Bug 1510598 - Handle uncatchable errors in RejectPromiseWithPendingError. r=jonco
authorJason Orendorff <jorendorff@mozilla.com>
Tue, 04 Dec 2018 19:54:05 +0000
changeset 449320 0b3de1c4a2ae2fcdf37817366c8557ad1861437a
parent 449319 5555defbbd01b3629496097dc8f403c9c4de60f8
child 449321 da4789ed7ec046470b3662ec5c26973398f042cd
push id74229
push userjorendorff@mozilla.com
push dateTue, 04 Dec 2018 20:56:36 +0000
treeherderautoland@0b3de1c4a2ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1510598
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 1510598 - Handle uncatchable errors in RejectPromiseWithPendingError. r=jonco Differential Revision: https://phabricator.services.mozilla.com/D13434
js/src/builtin/Promise.cpp
js/src/jit-test/tests/modules/bug-1510598.js
--- a/js/src/builtin/Promise.cpp
+++ b/js/src/builtin/Promise.cpp
@@ -3425,19 +3425,26 @@ static bool OriginalPromiseThenBuiltin(J
   } else {
     rval.setUndefined();
   }
   return true;
 }
 
 MOZ_MUST_USE bool js::RejectPromiseWithPendingError(
     JSContext* cx, Handle<PromiseObject*> promise) {
-  // Not much we can do about uncatchable exceptions, just bail.
+  if (!cx->isExceptionPending()) {
+    // Reject the promise, but also propagate this uncatchable error.
+    mozilla::Unused << PromiseObject::reject(cx, promise, UndefinedHandleValue);
+    return false;
+  }
+
   RootedValue exn(cx);
-  if (!GetAndClearException(cx, &exn)) return false;
+  if (!GetAndClearException(cx, &exn)) {
+    return false;
+  }
   return PromiseObject::reject(cx, promise, exn);
 }
 
 static MOZ_MUST_USE bool PerformPromiseThenWithReaction(
     JSContext* cx, Handle<PromiseObject*> promise,
     Handle<PromiseReactionRecord*> reaction);
 
 // Some async/await functions are implemented here instead of
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/modules/bug-1510598.js
@@ -0,0 +1,12 @@
+setModuleResolveHook(function(module, specifier) {
+    throw "Module '" + specifier + "' not found";
+});
+g = newGlobal();
+g.parent = this;
+g.eval("new Debugger(parent).onExceptionUnwind = () => null;");
+
+let exc = "fail";
+// This import fails because no such file exists, so we fire the onExceptionUnwind hook.
+import("javascript: ").catch(e => { exc = e; });
+drainJobQueue();
+assertEq(exc, undefined);