Backed out changeset 22e7144f857c (bug 1242505)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Sun, 28 May 2017 11:31:17 +0200
changeset 585753 79db5648dbd2a1397954bc08293082b50a037ebe
parent 585752 9dbe428fc209988be73d2a4bbc3c890811310d3d
child 585754 5f54472fcf58d462a31398d15cacbdde5bcad7e1
push id61188
push usermaglione.k@gmail.com
push dateSun, 28 May 2017 22:11:50 +0000
bugs1242505
milestone55.0a1
backs out22e7144f857ce6a49764375f1e5ddf3e1ead7a96
Backed out changeset 22e7144f857c (bug 1242505)
toolkit/modules/tests/modules/PromiseTestUtils.jsm
--- a/toolkit/modules/tests/modules/PromiseTestUtils.jsm
+++ b/toolkit/modules/tests/modules/PromiseTestUtils.jsm
@@ -48,23 +48,16 @@ this.PromiseTestUtils = {
    * When an uncaught rejection is detected, it is ignored if one of the
    * functions in this array returns true when called with the rejection details
    * as its only argument. When a function matches an expected rejection, it is
    * then removed from the array.
    */
   _rejectionIgnoreFns: [],
 
   /**
-   * If any of the functions in this array returns true when called with the
-   * rejection details as its only argument, the rejection is ignored. This
-   * happens after the "_rejectionIgnoreFns" array is processed.
-   */
-  _globalRejectionIgnoreFns: [],
-
-  /**
    * Called only by the test infrastructure, registers the rejection observers.
    *
    * This should be called only once, and a matching "uninit" call must be made
    * or the tests will crash on shutdown.
    */
   init() {
     if (this._initialized) {
       Cu.reportError("This object was already initialized.");
@@ -152,31 +145,23 @@ this.PromiseTestUtils = {
       let reason = PromiseDebugging.getState(promise).reason;
       if (reason === this._ensureDOMPromiseRejectionsProcessedReason) {
         // Ignore the special promise for ensureDOMPromiseRejectionsProcessed.
         return;
       }
       message = reason.message || ("" + reason);
     } catch (ex) {}
 
-    // We should convert the rejection stack to a string immediately. This is
-    // because the object might not be available when we report the rejection
-    // later, if the error occurred in a context that has been unloaded.
-    let stack = "(Unable to convert rejection stack to string.)";
-    try {
-      stack = "" + PromiseDebugging.getRejectionStack(promise);
-    } catch (ex) {}
-
     // It's important that we don't store any reference to the provided Promise
     // object or its value after this function returns in order to avoid leaks.
     this._rejections.push({
       id: PromiseDebugging.getPromiseID(promise),
       message,
       date: new Date(),
-      stack,
+      stack: PromiseDebugging.getRejectionStack(promise),
     });
   },
 
   // UncaughtRejectionObserver
   onConsumed(promise) {
     // We don't expect that many unhandled rejections will appear at the same
     // time, so the algorithm doesn't need to be optimized for that case.
     let id = PromiseDebugging.getPromiseID(promise);
@@ -205,29 +190,16 @@ this.PromiseTestUtils = {
    */
   expectUncaughtRejection(regExpOrCheckFn) {
     let checkFn = !("test" in regExpOrCheckFn) ? regExpOrCheckFn :
                   rejection => regExpOrCheckFn.test(rejection.message);
     this._rejectionIgnoreFns.push(checkFn);
   },
 
   /**
-   * Whitelists an entire class of Promise rejections. Usage of this function
-   * should be kept to a minimum because it has a broad scope and doesn't
-   * prevent new unhandled rejections of this class from being added.
-   *
-   * @param regExp
-   *        This should match the error message of the rejection.
-   */
-  whitelistRejectionsGlobally(regExp) {
-    this._globalRejectionIgnoreFns.push(
-      rejection => regExp.test(rejection.message));
-  },
-
-  /**
    * Fails the test if there are any uncaught rejections at this time that have
    * not been whitelisted using expectUncaughtRejection.
    *
    * Depending on the configuration of the test suite, this function might only
    * report the details of the first uncaught rejection that was generated.
    *
    * This is called by the test suite at the end of each test function.
    */
@@ -242,21 +214,16 @@ this.PromiseTestUtils = {
       // If one of the ignore functions matches, ignore the rejection, then
       // remove the function so that each function only matches one rejection.
       let index = this._rejectionIgnoreFns.findIndex(f => f(rejection));
       if (index != -1) {
         this._rejectionIgnoreFns.splice(index, 1);
         continue;
       }
 
-      // Check the global whitelisting functions.
-      if (this._globalRejectionIgnoreFns.some(fn => fn(rejection))) {
-        continue;
-      }
-
       // Report the error. This operation can throw an exception, depending on
       // the configuration of the test suite that handles the assertion.
       Assert.ok(false,
                 `A promise chain failed to handle a rejection:` +
                 ` ${rejection.message} - rejection date: ${rejection.date}` +
                 ` - stack: ${rejection.stack}`);
     }
   },
@@ -268,12 +235,10 @@ this.PromiseTestUtils = {
    * This is called by the test suite at the end of each test file.
    */
   assertNoMoreExpectedRejections() {
     // Only log this condition is there is a failure.
     if (this._rejectionIgnoreFns.length > 0) {
       Assert.equal(this._rejectionIgnoreFns.length, 0,
              "Unable to find a rejection expected by expectUncaughtRejection.");
     }
-    // Reset the list of expected rejections in case the test suite continues.
-    this._rejectionIgnoreFns = [];
   },
 };