Bug 1388082 - Convert execute script methods to async. r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 07 Aug 2017 16:53:02 +0100
changeset 645932 ac8d5d3c73ad4808401d4585c2ee30d783f16e95
parent 645931 23c9f135e2bf2948d164fea9179675c89e9bdf1d
child 645933 1c195a22b4304c819a9fef747706e177e3a195cf
push id73947
push userbmo:ato@sny.no
push dateMon, 14 Aug 2017 16:03:22 +0000
reviewersautomatedtester
bugs1388082
milestone57.0a1
Bug 1388082 - Convert execute script methods to async. r?automatedtester MozReview-Commit-ID: 6oUZ4v8snh0
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -939,32 +939,32 @@ GeckoDriver.prototype.getContext = funct
  *     JavaScript notion of null or undefined.
  *
  * @throws {ScriptTimeoutError}
  *     If the script was interrupted due to reaching the
  *     <var>scriptTimeout</var> or default timeout.
  * @throws {JavaScriptError}
  *     If an {@link Error} was thrown whilst evaluating the script.
  */
-GeckoDriver.prototype.executeScript = function*(cmd, resp) {
+GeckoDriver.prototype.executeScript = async function(cmd, resp) {
   assert.window(this.getCurrentWindow());
 
   let {script, args, scriptTimeout} = cmd.parameters;
   scriptTimeout = scriptTimeout || this.timeouts.script;
 
   let opts = {
     sandboxName: cmd.parameters.sandbox,
     newSandbox: !!(typeof cmd.parameters.newSandbox == "undefined") ||
         cmd.parameters.newSandbox,
     file: cmd.parameters.filename,
     line: cmd.parameters.line,
     debug: cmd.parameters.debug_script,
   };
 
-  resp.body.value = yield this.execute_(script, args, scriptTimeout, opts);
+  resp.body.value = await this.execute_(script, args, scriptTimeout, opts);
 };
 
 /**
  * Executes a JavaScript function in the context of the current browsing
  * context, if in content space, or in chrome space otherwise, and returns
  * the object passed to the callback.
  *
  * The callback is always the last argument to the <var>arguments</var>
@@ -1016,58 +1016,66 @@ GeckoDriver.prototype.executeScript = fu
  *     JavaScript notion of null or undefined.
  *
  * @throws {ScriptTimeoutError}
  *     If the script was interrupted due to reaching the
  *     <var>scriptTimeout</var> or default timeout.
  * @throws {JavaScriptError}
  *     If an Error was thrown whilst evaluating the script.
  */
-GeckoDriver.prototype.executeAsyncScript = function* (cmd, resp) {
+GeckoDriver.prototype.executeAsyncScript = async function(cmd, resp) {
   assert.window(this.getCurrentWindow());
 
   let {script, args, scriptTimeout} = cmd.parameters;
   scriptTimeout = scriptTimeout || this.timeouts.script;
 
   let opts = {
     sandboxName: cmd.parameters.sandbox,
     newSandbox: !!(typeof cmd.parameters.newSandbox == "undefined") ||
         cmd.parameters.newSandbox,
     file: cmd.parameters.filename,
     line: cmd.parameters.line,
     debug: cmd.parameters.debug_script,
     async: true,
   };
 
-  resp.body.value = yield this.execute_(script, args, scriptTimeout, opts);
+  resp.body.value = await this.execute_(script, args, scriptTimeout, opts);
 };
 
-GeckoDriver.prototype.execute_ = function(script, args, timeout, opts = {}) {
+GeckoDriver.prototype.execute_ = async function(
+    script, args, timeout, opts = {}) {
+  let res, els;
+
   switch (this.context) {
     case Context.CONTENT:
       // evaluate in content with lasting side-effects
       if (!opts.sandboxName) {
-        return this.listener.execute(script, args, timeout, opts)
-            .then(evaluate.toJSON);
-      }
+        res = await this.listener.execute(script, args, timeout, opts);
 
       // evaluate in content with sandbox
-      return this.listener.executeInSandbox(script, args, timeout, opts)
-          .then(evaluate.toJSON);
+      } else {
+        res = await this.listener.executeInSandbox(
+            script, args, timeout, opts);
+      }
+
+      break;
 
     case Context.CHROME:
       let sb = this.sandboxes.get(opts.sandboxName, opts.newSandbox);
       opts.timeout = timeout;
       let wargs = evaluate.fromJSON(args, this.curBrowser.seenEls, sb.window);
-      return evaluate.sandbox(sb, script, wargs, opts)
-          .then(res => evaluate.toJSON(res, this.curBrowser.seenEls));
+      res = await evaluate.sandbox(sb, script, wargs, opts);
+      els = this.curBrowser.seenEls;
+      break;
 
     default:
       throw new TypeError(`Unknown context: ${this.context}`);
   }
+
+  return evaluate.toJSON(res, els);
 };
 
 /**
  * Navigate to given URL.
  *
  * Navigates the current browsing context to the given URL and waits for
  * the document to load or the session's page timeout duration to elapse
  * before returning.