From 93504129e18a59c55b3a01c02da090d885de656f Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 28 Dec 2011 11:55:11 -0500 Subject: [PATCH] Bug 463122 - Propagate mozJSComponentLoader exceptions that occur while executing the script. r=mrbkap --- js/xpconnect/loader/mozJSComponentLoader.cpp | 12 +++++++++++- js/xpconnect/tests/unit/importer.jsm | 1 + js/xpconnect/tests/unit/test_import_fail.js | 10 ++++++++++ js/xpconnect/tests/unit/xpcshell.ini | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 js/xpconnect/tests/unit/importer.jsm create mode 100644 js/xpconnect/tests/unit/test_import_fail.js diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index eb1ab67ab94..5b0525e876f 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -964,10 +964,20 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile, // See bug 384168. *aGlobal = global; - if (!JS_ExecuteScriptVersion(cx, global, script, NULL, JSVERSION_LATEST)) { + uint32 oldopts = JS_GetOptions(cx); + JS_SetOptions(cx, oldopts | + (exception ? JSOPTION_DONT_REPORT_UNCAUGHT : 0)); + bool ok = JS_ExecuteScriptVersion(cx, global, script, NULL, JSVERSION_LATEST); + JS_SetOptions(cx, oldopts); + + if (!ok) { #ifdef DEBUG_shaver_off fprintf(stderr, "mJCL: failed to execute %s\n", nativePath.get()); #endif + if (exception) { + JS_GetPendingException(cx, exception); + JS_ClearPendingException(cx); + } *aGlobal = nsnull; return NS_ERROR_FAILURE; } diff --git a/js/xpconnect/tests/unit/importer.jsm b/js/xpconnect/tests/unit/importer.jsm new file mode 100644 index 00000000000..f5f40d30b97 --- /dev/null +++ b/js/xpconnect/tests/unit/importer.jsm @@ -0,0 +1 @@ +Components.utils.import("resource://test/syntax_error.jsm"); \ No newline at end of file diff --git a/js/xpconnect/tests/unit/test_import_fail.js b/js/xpconnect/tests/unit/test_import_fail.js new file mode 100644 index 00000000000..d297fa01daa --- /dev/null +++ b/js/xpconnect/tests/unit/test_import_fail.js @@ -0,0 +1,10 @@ +function run_test() +{ + try { + Components.utils.import("resource://test/importer.jsm"); + do_check_true(false, "import should not succeed."); + } catch (x) { + do_check_neq(x.fileName.indexOf("syntax_error.jsm"), -1); + do_check_eq(x.lineNumber, 1); + } +} \ No newline at end of file diff --git a/js/xpconnect/tests/unit/xpcshell.ini b/js/xpconnect/tests/unit/xpcshell.ini index b0d2a2cc4aa..b2c08672164 100644 --- a/js/xpconnect/tests/unit/xpcshell.ini +++ b/js/xpconnect/tests/unit/xpcshell.ini @@ -14,6 +14,7 @@ tail = [test_bug_442086.js] [test_file.js] [test_import.js] +[test_import_fail.js] [test_js_weak_references.js] [test_reflect_parse.js] [test_localeCompare.js]