Bug 1471812 - Remove defer usage in webconsole panel initialization; r=ochameau.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Wed, 27 Jun 2018 17:18:52 +0200
changeset 424168 319854ead97929d37dba8011a991ae0d23aa385f
parent 424167 97499b2f5612744210e16bd9e3525d18b2211da2
child 424169 8da7a4d1fcb5356ece01708fc0a9bf98bb823a2e
push id34200
push usershindli@mozilla.com
push dateThu, 28 Jun 2018 21:52:47 +0000
treeherdermozilla-central@96434ebf453f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1471812
milestone63.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 1471812 - Remove defer usage in webconsole panel initialization; r=ochameau. This patch removes the use of defer and switches the open function to an async one, which makes things easier to follow. MozReview-Commit-ID: Iezrfs3NNBz
devtools/client/webconsole/panel.js
--- a/devtools/client/webconsole/panel.js
+++ b/devtools/client/webconsole/panel.js
@@ -1,19 +1,16 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft= javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-const promise = require("promise");
-const defer = require("devtools/shared/defer");
-
 loader.lazyRequireGetter(this, "HUDService", "devtools/client/webconsole/hudservice", true);
 loader.lazyGetter(this, "EventEmitter", () => require("devtools/shared/event-emitter"));
 
 /**
  * A DevToolPanel that controls the Web Console.
  */
 function WebConsolePanel(iframeWindow, toolbox) {
   this._frameWindow = iframeWindow;
@@ -36,70 +33,57 @@ WebConsolePanel.prototype = {
   },
 
   /**
    * Open is effectively an asynchronous constructor.
    *
    * @return object
    *         A promise that is resolved when the Web Console completes opening.
    */
-  open: function() {
-    const parentDoc = this._toolbox.doc;
-    const iframe = parentDoc.getElementById("toolbox-panel-iframe-webconsole");
+  open: async function() {
+    try {
+      const parentDoc = this._toolbox.doc;
+      const iframe = parentDoc.getElementById("toolbox-panel-iframe-webconsole");
+
+      // Make sure the iframe content window is ready.
+      const win = iframe.contentWindow;
+      const doc = win && win.document;
+      if (!doc || doc.readyState !== "complete") {
+        await new Promise(resolve => {
+          iframe.addEventListener("load", resolve, {capture: true, once: true});
+        });
+      }
+
+      // Local debugging needs to make the target remote.
+      if (!this.target.isRemote) {
+        await this.target.makeRemote();
+      }
 
-    // Make sure the iframe content window is ready.
-    const deferredIframe = defer();
-    let win, doc;
-    if ((win = iframe.contentWindow) &&
-        (doc = win.document) &&
-        doc.readyState == "complete") {
-      deferredIframe.resolve(null);
-    } else {
-      iframe.addEventListener("load", function() {
-        deferredIframe.resolve(null);
-      }, {capture: true, once: true});
-    }
+      const webConsoleUIWindow = iframe.contentWindow.wrappedJSObject;
+      const chromeWindow = iframe.ownerDocument.defaultView;
+
+      // Open the Web Console.
+      this.hud = await HUDService.openWebConsole(
+        this.target, webConsoleUIWindow, chromeWindow);
 
-    // Local debugging needs to make the target remote.
-    let promiseTarget;
-    if (!this.target.isRemote) {
-      promiseTarget = this.target.makeRemote();
-    } else {
-      promiseTarget = promise.resolve(this.target);
+      // Pipe 'reloaded' event from WebConsoleFrame to WebConsolePanel.
+      // These events are listened by the Toolbox.
+      this.hud.ui.on("reloaded", () => {
+        this.emit("reloaded");
+      });
+
+      this._isReady = true;
+      this.emit("ready");
+    } catch (e) {
+      const msg = "WebConsolePanel open failed. " + e.error + ": " + e.message;
+      dump(msg + "\n");
+      console.error(msg, e);
     }
 
-    // 1. Wait for the iframe to load.
-    // 2. Wait for the remote target.
-    // 3. Open the Web Console.
-    return deferredIframe.promise
-      .then(() => promiseTarget)
-      .then((target) => {
-        this._frameWindow._remoteTarget = target;
-
-        const webConsoleUIWindow = iframe.contentWindow.wrappedJSObject;
-        const chromeWindow = iframe.ownerDocument.defaultView;
-        return HUDService.openWebConsole(this.target, webConsoleUIWindow,
-                                         chromeWindow);
-      })
-      .then((webConsole) => {
-        this.hud = webConsole;
-        // Pipe 'reloaded' event from WebConsoleFrame to WebConsolePanel.
-        // These events are listened by the Toolbox.
-        this.hud.ui.on("reloaded", () => {
-          this.emit("reloaded");
-        });
-        this._isReady = true;
-        this.emit("ready");
-        return this;
-      }, (reason) => {
-        const msg = "WebConsolePanel open failed. " +
-                  reason.error + ": " + reason.message;
-        dump(msg + "\n");
-        console.error(msg, reason);
-      });
+    return this;
   },
 
   get target() {
     return this._toolbox.target;
   },
 
   _isReady: false,
   get isReady() {