Bug 1388082 - Switch to async/await in action module. r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 07 Aug 2017 18:56:08 +0100
changeset 645933 1c195a22b4304c819a9fef747706e177e3a195cf
parent 645932 ac8d5d3c73ad4808401d4585c2ee30d783f16e95
child 645934 2f121a4e009352c15f558ef39b349fb9bcf06eed
push id73947
push userbmo:ato@sny.no
push dateMon, 14 Aug 2017 16:03:22 +0000
reviewersautomatedtester
bugs1388082
milestone57.0a1
Bug 1388082 - Switch to async/await in action module. r?automatedtester MozReview-Commit-ID: EREW0Hmmtb6
testing/marionette/action.js
--- a/testing/marionette/action.js
+++ b/testing/marionette/action.js
@@ -3,18 +3,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* eslint no-dupe-keys:off */
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
-Cu.import("resource://gre/modules/Task.jsm");
-
 Cu.import("chrome://marionette/content/assert.js");
 Cu.import("chrome://marionette/content/element.js");
 const {
   error,
   InvalidArgumentError,
   MoveTargetOutOfBoundsError,
   UnsupportedOperationError,
 } = Cu.import("chrome://marionette/content/error.js", {});
@@ -966,25 +964,25 @@ action.Mouse = class {
  * @param {Object.<string, nsIDOMWindow>} container
  *     Object with <code>frame</code> property of type
  *     <code>nsIDOMWindow</code>.
  *
  * @return {Promise}
  *     Promise for dispatching all actions in |chain|.
  */
 action.dispatch = function(chain, seenEls, container) {
-  let chainEvents = Task.spawn(function*() {
+  let chainEvents = (async () => {
     for (let tickActions of chain) {
-      yield action.dispatchTickActions(
+      await action.dispatchTickActions(
           tickActions,
           action.computeTickDuration(tickActions),
           seenEls,
           container);
     }
-  });
+  })();
   return chainEvents;
 };
 
 /**
  * Dispatch sequence of actions for one tick.
  *
  * This creates a Promise for one tick that resolves once the Promise
  * for each tick-action is resolved, which takes at least |tickDuration|
@@ -1321,33 +1319,32 @@ function dispatchPointerMove(
       performOnePointerMove(inputState, targetX, targetY, container.frame);
       resolve();
       return;
     }
 
     const distanceX = targetX - startX;
     const distanceY = targetY - startY;
     const ONE_SHOT = Ci.nsITimer.TYPE_ONE_SHOT;
-    let intermediatePointerEvents = Task.spawn(function* () {
+    let intermediatePointerEvents = (async () => {
       // wait |fps60| ms before performing first incremental pointer move
-      yield new Promise(resolveTimer =>
-          timer.initWithCallback(resolveTimer, fps60, ONE_SHOT)
-      );
+      await new Promise(resolveTimer =>
+          timer.initWithCallback(resolveTimer, fps60, ONE_SHOT));
       let durationRatio = Math.floor(Date.now() - start) / duration;
       const epsilon = fps60 / duration / 10;
       while ((1 - durationRatio) > epsilon) {
         let x = Math.floor(durationRatio * distanceX + startX);
         let y = Math.floor(durationRatio * distanceY + startY);
         performOnePointerMove(inputState, x, y, container.frame);
         // wait |fps60| ms before performing next pointer move
-        yield new Promise(resolveTimer =>
+        await new Promise(resolveTimer =>
             timer.initWithCallback(resolveTimer, fps60, ONE_SHOT));
         durationRatio = Math.floor(Date.now() - start) / duration;
       }
-    });
+    })();
     // perform last pointer move after all incremental moves are resolved and
     // durationRatio is close enough to 1
     intermediatePointerEvents.then(() => {
       performOnePointerMove(inputState, targetX, targetY, container.frame);
       resolve();
     });
 
   });