Bug 1464461 - resolve mochitest failures; r=ochameau
MozReview-Commit-ID: EyjdAt62Aaq
--- 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