Bug 1094208 - Part 3 of 3 - Use DOM Promise scheduling in Promise.jsm. r=Yoric
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Thu, 13 Nov 2014 11:19:08 +0000
changeset 215609 fd4bd4b3fbf83159aae9c368826a0598df820750
parent 215608 d187d7f83b90d30e614fd1b1191475882fe6af1b
child 215610 5e58c0e599649cb6134e59219533d5ada3464af4
push id51796
push userryanvm@gmail.com
push dateThu, 13 Nov 2014 20:47:14 +0000
treeherdermozilla-inbound@a05b5362429f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1094208
milestone36.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 1094208 - Part 3 of 3 - Use DOM Promise scheduling in Promise.jsm. r=Yoric
toolkit/modules/Promise-backend.js
--- a/toolkit/modules/Promise-backend.js
+++ b/toolkit/modules/Promise-backend.js
@@ -35,16 +35,19 @@ const STATUS_REJECTED = 2;
 // properties are inaccessible by other code, but provide enough protection to
 // avoid using them by mistake.
 const salt = Math.floor(Math.random() * 100);
 const N_INTERNALS = "{private:internals:" + salt + "}";
 
 const JS_HAS_SYMBOLS = typeof Symbol === "function";
 const ITERATOR_SYMBOL = JS_HAS_SYMBOLS ? Symbol.iterator : "@@iterator";
 
+// We use DOM Promise for scheduling the walker loop.
+const DOMPromise = Promise;
+
 /////// Warn-upon-finalization mechanism
 //
 // One of the difficult problems with promises is locating uncaught
 // rejections. We adopt the following strategy: if a promise is rejected
 // at the time of its garbage-collection *and* if the promise is at the
 // end of a promise chain (i.e. |thatPromise.then| has never been
 // called), then we print a warning.
 //
@@ -680,18 +683,17 @@ this.PromiseWalker = {
   },
 
   /**
    * Sets up the PromiseWalker loop to start on the next tick of the event loop
    */
   scheduleWalkerLoop: function()
   {
     this.walkerLoopScheduled = true;
-    Services.tm.currentThread.dispatch(this.walkerLoop,
-                                       Ci.nsIThread.DISPATCH_NORMAL);
+    DOMPromise.resolve().then(() => this.walkerLoop());
   },
 
   /**
    * Schedules the resolution or rejection handlers registered on the provided
    * promise for processing.
    *
    * @param aPromise
    *        Resolved or rejected promise whose handlers should be processed.  It