Bug 1426219 - Extend PromiseTestUtils to uncaught JavaScript Developer Errors;r?florian draft
authorDavid Teller <dteller@mozilla.com>
Tue, 19 Dec 2017 21:00:32 +0100
changeset 713222 b204100c3f927e937db0fbdd2f837f39ae957188
parent 706650 de1f7a92e8726bdd365d4bbc5e65eaa369fbc20a
child 713223 f66a3ca0cdecc229aa25f540ff776b2c115f283b
push id93582
push userdteller@mozilla.com
push dateTue, 19 Dec 2017 21:18:14 +0000
reviewersflorian
bugs1426219
milestone59.0a1
Bug 1426219 - Extend PromiseTestUtils to uncaught JavaScript Developer Errors;r?florian This patch uses (and somewhat abuses) the existing PromiseTestUtils mechanism to also be able to whitelist uncaught errors that are not actual Promise rejections. This uses `ChromeUtils.recentJSDevError`, which lets us find out whether there is a recent ReferenceError/SyntaxError/TypeError in chrome code, even if that error was caught. MozReview-Commit-ID: 5z1pffURNYm
toolkit/modules/tests/modules/PromiseTestUtils.jsm
--- a/toolkit/modules/tests/modules/PromiseTestUtils.jsm
+++ b/toolkit/modules/tests/modules/PromiseTestUtils.jsm
@@ -87,16 +87,34 @@ this.PromiseTestUtils = {
 
     PromiseDebugging.removeUncaughtRejectionObserver(this);
     JSMPromise.Debugging.clearUncaughtErrorObservers();
 
     this._initialized = false;
   },
 
   /**
+   * Called only by the test infrastructure, collect all the
+   * JavaScript Developer Errors that have been thrown and
+   * treat them as uncaught promise rejections.
+   */
+  collectJSDevErrors() {
+    if (!("recentJSDevError" in ChromeUtils)) {
+      // For the time being, recentJSDevError/clearRecentJSDevError is only available on Nightly builds.
+      return;
+    }
+    let recentJSDevError = ChromeUtils.recentJSDevError;
+    if (recentJSDevError) {
+      ChromeUtils.clearRecentJSDevError();
+      let message = recentJSDevError.message + "\n" + recentJSDevError.stack + "\n----\n Detected at\n";
+      Promise.reject(message);
+    }
+  },
+
+  /**
    * Called only by the test infrastructure, spins the event loop until the
    * messages for pending DOM Promise rejections have been processed.
    */
   ensureDOMPromiseRejectionsProcessed() {
     let observed = false;
     let observer = {
       onLeftUncaught: promise => {
         if (PromiseDebugging.getState(promise).reason ===