Bug 1464461 - resolve mochitest failures; r=ochameau draft
authoryulia <ystartsev@mozilla.com>
Tue, 26 Jun 2018 16:11:55 +0200
changeset 810786 1398940c020c
parent 810782 a3a72d45cf25
child 810833 68f4b3610c94
push id114107
push userbmo:ystartsev@mozilla.com
push dateTue, 26 Jun 2018 14:15:18 +0000
reviewersochameau
bugs1464461
milestone62.0a1
Bug 1464461 - resolve mochitest failures; r=ochameau MozReview-Commit-ID: EyjdAt62Aaq
devtools/server/actors/webconsole.js
--- a/devtools/server/actors/webconsole.js
+++ b/devtools/server/actors/webconsole.js
@@ -879,32 +879,52 @@ WebConsoleActor.prototype =
    * that can be associated back to this request via the `resultID` field.
    *
    * @param object request
    *        The JSON request object received from the Web Console client.
    * @return object
    *         The response packet to send to with the unique id in the
    *         `resultID` field.
    */
-  evaluateJSAsync: async function(request) {
+  evaluateJSAsync: function(request) {
     // We want to be able to run console commands without waiting
     // for the first to return (see Bug 1088861).
 
     // First, send a response packet with the id only.
     const resultID = Date.now();
     this.conn.send({
       from: this.actorID,
       resultID: resultID
     });
 
     // Then, execute the script that may pause.
     const response = this.evaluateJS(request);
     response.resultID = resultID;
 
-    // Wait for asynchronous command completion before sending back the response
+    this._waitForHelperResultAndSend(response);
+  },
+
+  /**
+   * In order to have asynchornous commands such as screenshot, we have to be
+   * able to handle promises in the helper result. This method handles waiting
+   * for the promise, and then dispatching the result
+   *
+   *
+   * @private
+   * @param object response
+   *         The response packet to send to with the unique id in the
+   *         `resultID` field, and potentially a promise in the helperResult
+   *         field.
+   *
+   * @return object
+   *         The response packet to send to with the unique id in the
+   *         `resultID` field, with a sanitized helperResult field.
+   */
+  _waitForHelperResultAndSend: async function(response) {
+    // wait for asynchronous command completion before sending back the response
     if (
       response.helperResult &&
       typeof response.helperResult.then == "function"
     ) {
       response.helperResult = await response.helperResult;
     }
 
     // Finally, send an unsolicited evaluationResult packet with