Bug 840887 - DirectoryIterator.prototype.exists - asynchronous version. r=froydnj

This commit is contained in:
David Rajchenbach-Teller 2013-02-26 12:08:28 -05:00
parent f28096d843
commit 15b21c14a2
2 changed files with 18 additions and 1 deletions

View File

@ -627,6 +627,18 @@ let DirectoryIterator = function DirectoryIterator(path, options) {
this._isClosed = false; this._isClosed = false;
}; };
DirectoryIterator.prototype = { DirectoryIterator.prototype = {
/**
* Determine whether the directory exists.
*
* @resolves {boolean}
*/
exists: function exists() {
return this._itmsg.then(
function onSuccess(iterator) {
return Scheduler.post("DirectoryIterator_prototype_exists", [iterator]);
}
);
},
/** /**
* Get the next entry in the directory. * Get the next entry in the directory.
* *
@ -728,7 +740,6 @@ DirectoryIterator.prototype = {
*/ */
_next: function _next(iterator) { _next: function _next(iterator) {
if (this._isClosed) { if (this._isClosed) {
LOG("DirectoryIterator._next", "closed");
return this._itmsg; return this._itmsg;
} }
let self = this; let self = this;

View File

@ -356,6 +356,12 @@ if (this.Components) {
this.close(); this.close();
OpenedDirectoryIterators.remove(dir); OpenedDirectoryIterators.remove(dir);
}, true);// ignore error to support double-closing |DirectoryIterator| }, true);// ignore error to support double-closing |DirectoryIterator|
},
DirectoryIterator_prototype_exists: function exists(dir) {
return withDir(dir,
function do_exists() {
return this.exists();
});
} }
}; };
} catch(ex) { } catch(ex) {