Bug 1527768 - Report dead object in unhandled rejections set properly. r=jandem a=lizzard
authorTooru Fujisawa <arai_a@mac.com>
Fri, 15 Feb 2019 15:06:00 +0000
changeset 516194 d2578f23e2f53775c1091ef4cfbe54c685bad32f
parent 516193 fb8a1b398f229ff4f7ce8b5d1234a08002ac8353
child 516195 674dfdbb55e1db81c730b883bd89d409d567f844
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem, lizzard
bugs1527768
milestone66.0
Bug 1527768 - Report dead object in unhandled rejections set properly. r=jandem a=lizzard 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
@@ -10538,16 +10538,25 @@ static MOZ_MUST_USE bool ReportUnhandled
     }
 
     RootedObject obj(cx, &resultObj->getDenseElement(0).toObject());
     obj = CheckedUnwrap(obj);
     if (!obj) {
       return false;
     }
 
+    if (!obj->is<PromiseObject>()) {
+      FILE* fp = ErrorFilePointer();
+      fputs(
+          "Unhandled rejection: dead proxy found in unhandled "
+          "rejections set\n",
+          fp);
+      continue;
+    }
+
     Handle<PromiseObject*> promise = obj.as<PromiseObject>();
 
     AutoRealm ar2(cx, promise);
 
     if (!PrintUnhandledRejection(cx, promise)) {
       return false;
     }
   }