Bug 1570242 - Fetch target from toolbox instead of memoizing it on console classes. r=nchevobbe
☠☠ backed out by beeb07bef59c ☠ ☠
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 21 Aug 2019 09:47:44 +0000
changeset 489153 a213b28dd40fe20af80a2bafcc6ae7c075da157a
parent 489152 63dc43dba90a00922b7fa994193fa8729e2e3ea4
child 489154 304366165980bc36f3e4a1fa7d1b1b04b89b9249
push id36465
push userdvarga@mozilla.com
push dateWed, 21 Aug 2019 16:47:43 +0000
treeherdermozilla-central@4ab60925635c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1570242
milestone70.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 1570242 - Fetch target from toolbox instead of memoizing it on console classes. r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D40017
devtools/client/webconsole/browser-console.js
devtools/client/webconsole/panel.js
devtools/client/webconsole/webconsole-connection-proxy.js
devtools/client/webconsole/webconsole-ui.js
devtools/client/webconsole/webconsole.js
--- a/devtools/client/webconsole/browser-console.js
+++ b/devtools/client/webconsole/browser-console.js
@@ -33,23 +33,28 @@ class BrowserConsole extends WebConsole 
    *        The target that the browser console will connect to.
    * @param nsIDOMWindow iframeWindow
    *        The window where the browser console UI is already loaded.
    * @param nsIDOMWindow chromeWindow
    *        The window of the browser console owner.
    * @param Boolean fissionSupport
    */
   constructor(target, iframeWindow, chromeWindow, fissionSupport = false) {
-    super(target, iframeWindow, chromeWindow, true, fissionSupport);
+    super(null, iframeWindow, chromeWindow, true, fissionSupport);
 
+    this._browserConsoleTarget = target;
     this._telemetry = new Telemetry();
     this._bcInitializer = null;
     this._bcDestroyer = null;
   }
 
+  get target() {
+    return this._browserConsoleTarget;
+  }
+
   /**
    * Initialize the Browser Console instance.
    *
    * @return object
    *         A promise for the initialization.
    */
   init() {
     if (this._bcInitializer) {
--- a/devtools/client/webconsole/panel.js
+++ b/devtools/client/webconsole/panel.js
@@ -60,17 +60,21 @@ WebConsolePanel.prototype = {
           });
         });
       }
 
       const webConsoleUIWindow = iframe.contentWindow.wrappedJSObject;
       const chromeWindow = iframe.ownerDocument.defaultView;
 
       // Open the Web Console.
-      this.hud = new WebConsole(this.target, webConsoleUIWindow, chromeWindow);
+      this.hud = new WebConsole(
+        this._toolbox,
+        webConsoleUIWindow,
+        chromeWindow
+      );
       await this.hud.init();
 
       // Pipe 'reloaded' event from WebConsoleUI to WebConsolePanel.
       // These events are listened by the Toolbox.
       this.hud.ui.on("reloaded", () => {
         this.emit("reloaded");
       });
 
--- a/devtools/client/webconsole/webconsole-connection-proxy.js
+++ b/devtools/client/webconsole/webconsole-connection-proxy.js
@@ -18,29 +18,20 @@ const PREF_CONNECTION_TIMEOUT = "devtool
 class WebConsoleConnectionProxy {
   /**
    * @constructor
    * @param {WebConsoleUI} webConsoleUI
    *        A WebConsoleUI instance that owns this connection proxy.
    * @param RemoteTarget target
    *        The target that the console will connect to.
    */
-  constructor(webConsoleUI, target, isBrowserConsole, fissionSupport) {
+  constructor(webConsoleUI, target) {
     this.webConsoleUI = webConsoleUI;
     this.target = target;
-    this.isBrowserConsole = isBrowserConsole;
-    this.fissionSupport = fissionSupport;
-
-    /**
-     * The DebuggerClient object.
-     *
-     * @see DebuggerClient
-     * @type object
-     */
-    this.client = target.client;
+    this.fissionSupport = this.webConsoleUI.fissionSupport;
 
     this._connecter = null;
 
     this._onPageError = this._onPageError.bind(this);
     this._onLogMessage = this._onLogMessage.bind(this);
     this._onConsoleAPICall = this._onConsoleAPICall.bind(this);
     this._onNetworkEvent = this._onNetworkEvent.bind(this);
     this._onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this);
@@ -63,16 +54,17 @@ class WebConsoleConnectionProxy {
     if (this._connecter) {
       return this._connecter;
     }
 
     this.target.on("will-navigate", this._onTabWillNavigate);
     this.target.on("navigate", this._onTabNavigated);
 
     const connection = (async () => {
+      this.client = this.target.client;
       this.webConsoleClient = await this.target.getFront("console");
       this._addWebConsoleClientEventListeners();
       await this._attachConsole();
 
       // There is no way to view response bodies from the Browser Console, so do
       // not waste the memory.
       const saveBodies =
         !this.webConsoleUI.isBrowserConsole &&
@@ -379,14 +371,13 @@ class WebConsoleConnectionProxy {
     }
 
     this._removeWebConsoleClientEventListeners();
     this.target.off("will-navigate", this._onTabWillNavigate);
     this.target.off("navigate", this._onTabNavigated);
 
     this.client = null;
     this.webConsoleClient = null;
-    this.target = null;
     this.webConsoleUI = null;
   }
 }
 
 exports.WebConsoleConnectionProxy = WebConsoleConnectionProxy;
--- a/devtools/client/webconsole/webconsole-ui.js
+++ b/devtools/client/webconsole/webconsole-ui.js
@@ -145,23 +145,24 @@ class WebConsoleUI {
 
     const toolbox = gDevTools.getToolbox(this.hud.target);
     if (toolbox) {
       toolbox.off("webconsole-selected", this._onPanelSelected);
       toolbox.off("split-console", this._onChangeSplitConsoleState);
       toolbox.off("select", this._onChangeSplitConsoleState);
     }
 
-    this.window = this.hud = this.wrapper = null;
-
     for (const proxy of this.getAllProxies()) {
       proxy.disconnect();
     }
     this.proxy = null;
     this.additionalProxies = null;
+
+    // Nullify `hud` last as it nullify also target which is used on destroy
+    this.window = this.hud = this.wrapper = null;
   }
 
   /**
    * Clear the Web Console output.
    *
    * This method emits the "messages-cleared" notification.
    *
    * @param boolean clearStorage
@@ -252,22 +253,17 @@ class WebConsoleUI {
   /**
    * Connect to the server using the remote debugging protocol.
    *
    * @private
    * @return object
    *         A promise object that is resolved/reject based on the proxies connections.
    */
   async _initConnection() {
-    this.proxy = new WebConsoleConnectionProxy(
-      this,
-      this.hud.target,
-      this.isBrowserConsole,
-      this.fissionSupport
-    );
+    this.proxy = new WebConsoleConnectionProxy(this, this.hud.target);
 
     if (
       this.fissionSupport &&
       this.hud.target.chrome &&
       !this.hud.target.isAddon
     ) {
       const { mainRoot } = this.hud.target.client;
       const { processes } = await mainRoot.listProcesses();
@@ -286,22 +282,17 @@ class WebConsoleUI {
           console.warn(
             "Can't retrieve the target front for process",
             processDescriptor
           );
           continue;
         }
 
         this.additionalProxies.push(
-          new WebConsoleConnectionProxy(
-            this,
-            targetFront,
-            this.isBrowserConsole,
-            this.fissionSupport
-          )
+          new WebConsoleConnectionProxy(this, targetFront)
         );
       }
     }
 
     return Promise.all(this.getAllProxies().map(proxy => proxy.connect()));
   }
 
   _initUI() {
--- a/devtools/client/webconsole/webconsole.js
+++ b/devtools/client/webconsole/webconsole.js
@@ -46,51 +46,55 @@ const isMacOS = Services.appinfo.OS === 
  *
  * This object only wraps the iframe that holds the Web Console UI. This is
  * meant to be an integration point between the Firefox UI and the Web Console
  * UI and features.
  */
 class WebConsole {
   /*
    * @constructor
-   * @param object target
-   *        The target that the web console will connect to.
+   * @param object toolbox
+   *        The toolbox where the web console is displayed.
    * @param nsIDOMWindow iframeWindow
    *        The window where the web console UI is already loaded.
    * @param nsIDOMWindow chromeWindow
    *        The window of the web console owner.
    * @param bool isBrowserConsole
    */
   constructor(
-    target,
+    toolbox,
     iframeWindow,
     chromeWindow,
     isBrowserConsole = false,
     fissionSupport = false
   ) {
+    this.toolbox = toolbox;
     this.iframeWindow = iframeWindow;
     this.chromeWindow = chromeWindow;
     this.hudId = "hud_" + ++gHudId;
-    this.target = target;
     this.browserWindow = this.chromeWindow.top;
     this.isBrowserConsole = isBrowserConsole;
     this.fissionSupport = fissionSupport;
 
     const element = this.browserWindow.document.documentElement;
     if (element.getAttribute("windowtype") != gDevTools.chromeWindowType) {
       this.browserWindow = Services.wm.getMostRecentWindow(
         gDevTools.chromeWindowType
       );
     }
     this.ui = new WebConsoleUI(this);
     this._destroyer = null;
 
     EventEmitter.decorate(this);
   }
 
+  get target() {
+    return this.toolbox.target;
+  }
+
   /**
    * Getter for the window that can provide various utilities that the web
    * console makes use of, like opening links, managing popups, etc.  In
    * most cases, this will be |this.browserWindow|, but in some uses (such as
    * the Browser Toolbox), there is no browser window, so an alternative window
    * hosts the utilities there.
    * @type nsIDOMWindow
    */