author | Nicolas Chevobbe <nchevobbe@mozilla.com> |
Wed, 27 Jun 2018 17:18:52 +0200 | |
changeset 424325 | 319854ead97929d37dba8011a991ae0d23aa385f |
parent 424324 | 97499b2f5612744210e16bd9e3525d18b2211da2 |
child 424326 | 8da7a4d1fcb5356ece01708fc0a9bf98bb823a2e |
push id | 104778 |
push user | shindli@mozilla.com |
push date | Thu, 28 Jun 2018 23:25:48 +0000 |
treeherder | mozilla-inbound@226fffcc9736 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ochameau |
bugs | 1471812 |
milestone | 63.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
|
--- 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() {