Bug 1527768 - Report dead object in unhandled rejections set properly. r=jandem
authorTooru Fujisawa <arai_a@mac.com>
Fri, 15 Feb 2019 15:06:00 +0000
changeset 459466 dc7e72c71d3a8ec6ec1e6410ad3177f26b1d2ca7
parent 459465 cd3c6c72d196abccc70291624de8f19d764e963c
child 459467 0934e6142eb942c5f3ba28bb426c85eb47dbd897
push id78290
push userarai_a@mac.com
push dateFri, 15 Feb 2019 16:14:31 +0000
treeherderautoland@dc7e72c71d3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1527768
milestone67.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 1527768 - Report dead object in unhandled rejections set properly. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D19879
js/src/jit-test/tests/promise/unhandled-rejections-dead.js
js/src/shell/js.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/promise/unhandled-rejections-dead.js
@@ -0,0 +1,17 @@
+// |jit-test| error:Unhandled rejection
+
+// Create the set object for unhandled rejection in this global.
+async function fn() { e }
+let p = fn();
+
+var g = newGlobal();
+g.evaluate(`
+async function fn() { e }
+fn()
+// Create unhandled rejection in another compartment.
+// The promise is tracked by the unhandled rejection set with CCW.
+P = newGlobal().eval("(class extends Promise { function(){} })")
+
+// Nuke the CCW to make the entry in unhandled rejection set a dead proxy.
+Promise.all.call(P, [{ then() { nukeAllCCWs() } }])
+`);
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -10304,19 +10304,24 @@ static MOZ_MUST_USE bool ReportUnhandled
 
   while (true) {
     bool done = SetIteratorObject::next(iterObj, resultObj, cx);
     if (done) {
       break;
     }
 
     RootedObject obj(cx, &resultObj->getDenseElement(0).toObject());
-    Rooted<PromiseObject*> promise(cx, obj->maybeUnwrapAs<PromiseObject>());
+    Rooted<PromiseObject*> promise(cx, obj->maybeUnwrapIf<PromiseObject>());
     if (!promise) {
-      return false;
+      FILE* fp = ErrorFilePointer();
+      fputs(
+          "Unhandled rejection: dead proxy found in unhandled "
+          "rejections set\n",
+          fp);
+      continue;
     }
 
     AutoRealm ar2(cx, promise);
 
     if (!PrintUnhandledRejection(cx, promise)) {
       return false;
     }
   }