From 15b21c14a21cd3bafe144346d20f03e1c9512e4c Mon Sep 17 00:00:00 2001 From: David Rajchenbach-Teller Date: Tue, 26 Feb 2013 12:08:28 -0500 Subject: [PATCH] Bug 840887 - DirectoryIterator.prototype.exists - asynchronous version. r=froydnj --- toolkit/components/osfile/osfile_async_front.jsm | 13 ++++++++++++- toolkit/components/osfile/osfile_async_worker.js | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/toolkit/components/osfile/osfile_async_front.jsm b/toolkit/components/osfile/osfile_async_front.jsm index 7329cc0caa88..40343af848ad 100644 --- a/toolkit/components/osfile/osfile_async_front.jsm +++ b/toolkit/components/osfile/osfile_async_front.jsm @@ -627,6 +627,18 @@ let DirectoryIterator = function DirectoryIterator(path, options) { this._isClosed = false; }; 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. * @@ -728,7 +740,6 @@ DirectoryIterator.prototype = { */ _next: function _next(iterator) { if (this._isClosed) { - LOG("DirectoryIterator._next", "closed"); return this._itmsg; } let self = this; diff --git a/toolkit/components/osfile/osfile_async_worker.js b/toolkit/components/osfile/osfile_async_worker.js index 94128f986788..2c82a52020b5 100644 --- a/toolkit/components/osfile/osfile_async_worker.js +++ b/toolkit/components/osfile/osfile_async_worker.js @@ -356,6 +356,12 @@ if (this.Components) { this.close(); OpenedDirectoryIterators.remove(dir); }, 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) {