Bug 1502669 - Check whether an exception is pending if dynamic module import hook fails r=jandem
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 30 Oct 2018 10:29:57 +0000
changeset 443472 0d19b902fd7cf57dd5c00862489f26ca1ae99af6
parent 443471 f09bd717691e8e913764e560377def8d5b7581f5
child 443473 131bc0e561970979dec138a2d65d5b7b4d3d995a
push id109383
push userjcoppeard@mozilla.com
push dateTue, 30 Oct 2018 10:42:32 +0000
treeherdermozilla-inbound@131bc0e56197 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1502669
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1502669 - Check whether an exception is pending if dynamic module import hook fails r=jandem
js/src/builtin/ModuleObject.cpp
js/src/jit-test/tests/modules/bug-1502669.js
js/src/shell/js.cpp
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -1857,17 +1857,19 @@ js::StartDynamicModuleImport(JSContext* 
     if (!specifier) {
         if (!RejectPromiseWithPendingError(cx, promise)) {
             return nullptr;
         }
         return promise;
     }
 
     if (!importHook(cx, referencingPrivate, specifier, promise)) {
-        if (!RejectPromiseWithPendingError(cx, promise)) {
+        // If there's no exception pending then the script is terminating
+        // anyway, so just return nullptr.
+        if (!cx->isExceptionPending() || !RejectPromiseWithPendingError(cx, promise)) {
             return nullptr;
         }
         return promise;
     }
 
     return promise;
 }
 
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/modules/bug-1502669.js
@@ -0,0 +1,5 @@
+// |jit-test| error: ReferenceError
+var g = newGlobal();
+g.parent = this;
+g.eval("new Debugger(parent).onExceptionUnwind = function () { hits++; };");
+import('')();
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -4981,21 +4981,17 @@ ShellModuleDynamicImportHook(JSContext* 
     MOZ_ASSERT(hookValue.toObject().is<JSFunction>());
 
     JS::AutoValueArray<3> args(cx);
     args[0].set(referencingPrivate);
     args[1].setString(specifier);
     args[2].setObject(*promise);
 
     RootedValue result(cx);
-    if (!JS_CallFunctionValue(cx, nullptr, hookValue, args, &result)) {
-        return false;
-    }
-
-    return true;
+    return JS_CallFunctionValue(cx, nullptr, hookValue, args, &result);
 }
 
 static bool
 GetModuleLoadPath(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     ShellContext* sc = GetShellContext(cx);