diff --git a/toolkit/components/osfile/modules/osfile_async_front.jsm b/toolkit/components/osfile/modules/osfile_async_front.jsm index a763cfba879..e7e5ea527c0 100644 --- a/toolkit/components/osfile/modules/osfile_async_front.jsm +++ b/toolkit/components/osfile/modules/osfile_async_front.jsm @@ -208,9 +208,16 @@ let Scheduler = { // Decode any serialized error if (error instanceof PromiseWorker.WorkerError) { throw OS.File.Error.fromMsg(error.data); - } else { - throw error; } + // Extract something meaningful from WorkerErrorEvent + if (typeof error == "object" && error && error.constructor.name == "WorkerErrorEvent") { + let message = error.message; + if (message == "uncaught exception: [object StopIteration]") { + throw StopIteration; + } + throw new Error(message, error.filename, error.lineno); + } + throw error; } ); } @@ -965,14 +972,11 @@ DirectoryIterator.prototype = { promise = promise.then( DirectoryIterator.Entry.fromMsg, function onReject(reason) { - // If the exception is |StopIteration| (which we may determine only - // from its message...) we need to stop the iteration. - if (!(reason instanceof WorkerErrorEvent && reason.message == "uncaught exception: [object StopIteration]")) { - // Any exception other than StopIteration should be propagated as such - throw reason; + if (reason == StopIteration) { + self.close(); + throw StopIteration; } - self.close(); - throw StopIteration; + throw reason; }); return promise; }, diff --git a/toolkit/components/osfile/tests/xpcshell/test_exception.js b/toolkit/components/osfile/tests/xpcshell/test_exception.js new file mode 100644 index 00000000000..e28950fb1d9 --- /dev/null +++ b/toolkit/components/osfile/tests/xpcshell/test_exception.js @@ -0,0 +1,29 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +Components.utils.import("resource://gre/modules/osfile.jsm"); + +function run_test() { + do_test_pending(); + run_next_test(); +} + +add_task(function test_typeerror() { + let exn; + try { + let fd = yield OS.File.open("/tmp", {no_such_key: 1}); + do_print("Fd: " + fd); + } catch (ex) { + exn = ex; + } + do_print("Exception: " + exn); + do_check_true(typeof exn == "object"); + do_check_true("name" in exn); + do_check_true(exn.message.indexOf("TypeError") != -1); +}); + +add_task(function() { + do_test_finished(); +}); diff --git a/toolkit/components/osfile/tests/xpcshell/xpcshell.ini b/toolkit/components/osfile/tests/xpcshell/xpcshell.ini index 97655c3cdd6..c9ac7cc8350 100644 --- a/toolkit/components/osfile/tests/xpcshell/xpcshell.ini +++ b/toolkit/components/osfile/tests/xpcshell/xpcshell.ini @@ -8,5 +8,6 @@ tail = [test_profiledir.js] [test_logging.js] [test_creationDate.js] +[test_exception.js] [test_path_constants.js] [test_removeDir.js]