Bug 1492830 - Move toolbox code from attach-thread.js to toolbox; r=jdescottes
authoryulia <ystartsev@mozilla.com>
Thu, 16 May 2019 08:13:00 +0000
changeset 474045 02a438fa11a8b1be6b0db28aa3f5c39b7ff6f8e8
parent 474044 91d4f30e0ddad63c153baee71e8bc496987204f4
child 474046 9faf24ffeaaf5f1e38fca1c6630716aeca7982bf
push id36022
push userncsoregi@mozilla.com
push dateThu, 16 May 2019 21:55:16 +0000
treeherdermozilla-central@96802be91766 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1492830
milestone68.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 1492830 - Move toolbox code from attach-thread.js to toolbox; r=jdescottes this code can be merged with the toolbox code Differential Revision: https://phabricator.services.mozilla.com/D29367
devtools/client/framework/attach-thread.js
devtools/client/framework/moz.build
devtools/client/framework/toolbox.js
deleted file mode 100644
--- a/devtools/client/framework/attach-thread.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/* -*- 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/. */
-
-const Services = require("Services");
-
-async function attachThread(target) {
-  const threadOptions = {
-    autoBlackBox: false,
-    ignoreFrameEnvironment: true,
-    pauseOnExceptions:
-      Services.prefs.getBoolPref("devtools.debugger.pause-on-exceptions"),
-    ignoreCaughtExceptions:
-      Services.prefs.getBoolPref("devtools.debugger.ignore-caught-exceptions"),
-  };
-
-  const [, threadClient] = await target.attachThread(threadOptions);
-  if (!threadClient.paused) {
-    throw new Error("Thread in wrong state when starting up, should be paused.");
-  }
-  return threadClient;
-}
-
-module.exports = { attachThread };
--- a/devtools/client/framework/moz.build
+++ b/devtools/client/framework/moz.build
@@ -15,17 +15,16 @@ BROWSER_CHROME_MANIFESTS += [
 ]
 XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
 
 DIRS += [
     'components',
 ]
 
 DevToolsModules(
-    'attach-thread.js',
     'browser-menus.js',
     'devtools-browser.js',
     'devtools.js',
     'gDevTools.jsm',
     'menu-item.js',
     'menu.js',
     'selection.js',
     'sidebar.js',
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -19,17 +19,16 @@ var {Ci, Cc} = require("chrome");
 var promise = require("promise");
 const { debounce } = require("devtools/shared/debounce");
 var Services = require("Services");
 var ChromeUtils = require("ChromeUtils");
 var {gDevTools} = require("devtools/client/framework/devtools");
 var EventEmitter = require("devtools/shared/event-emitter");
 var Telemetry = require("devtools/client/shared/telemetry");
 const { getUnicodeUrl } = require("devtools/client/shared/unicode-url");
-var { attachThread } = require("./attach-thread");
 var { DOMHelpers } = require("resource://devtools/client/shared/DOMHelpers.jsm");
 const { KeyCodes } = require("devtools/client/shared/keycodes");
 var Startup = Cc["@mozilla.org/devtools/startup-clh;1"].getService(Ci.nsISupports)
   .wrappedJSObject;
 
 const { BrowserLoader } =
   ChromeUtils.import("resource://devtools/client/shared/browser-loader.js");
 
@@ -481,16 +480,47 @@ Toolbox.prototype = {
     this.threadClient.addListener("resumed", this._onResumedState);
   },
 
   _stopThreadClientListeners: function() {
     this.threadClient.removeListener("paused", this._onPausedState);
     this.threadClient.removeListener("resumed", this._onResumedState);
   },
 
+  _attachAndResumeThread: async function() {
+    const threadOptions = {
+      autoBlackBox: false,
+      ignoreFrameEnvironment: true,
+      pauseOnExceptions:
+        Services.prefs.getBoolPref("devtools.debugger.pause-on-exceptions"),
+      ignoreCaughtExceptions:
+        Services.prefs.getBoolPref("devtools.debugger.ignore-caught-exceptions"),
+    };
+    const [, threadClient] = await this._target.attachThread(threadOptions);
+
+    try {
+      await threadClient.resume();
+    } catch (ex) {
+      // Interpret a possible error thrown by ThreadActor.resume
+      if (ex.error === "wrongOrder") {
+        const box = this.getNotificationBox();
+        box.appendNotification(
+          L10N.getStr("toolbox.resumeOrderWarning"),
+          "wrong-resume-order",
+          "",
+          box.PRIORITY_WARNING_HIGH
+        );
+      } else {
+        throw ex;
+      }
+    }
+
+    return threadClient;
+  },
+
   /**
    * Open the toolbox
    */
   open: function() {
     return (async function() {
       const isToolboxURL = this.win.location.href.startsWith(this._URL);
       if (isToolboxURL) {
         // Update the URL so that onceDOMReady watch for the right url.
@@ -520,36 +550,17 @@ Toolbox.prototype = {
       // Start tracking network activity on toolbox open for targets such as tabs.
       // (Workers and potentially others don't manage the console client in the target.)
       if (this._target.activeConsole) {
         await this._target.activeConsole.startListeners([
           "NetworkActivity",
         ]);
       }
 
-      // Attach the thread
-      this._threadClient = await attachThread(this._target);
-
-      try {
-        await this._threadClient.resume();
-      } catch (ex) {
-        // Interpret a possible error thrown by ThreadActor.resume
-        if (ex.error === "wrongOrder") {
-          const box = this.getNotificationBox();
-          box.appendNotification(
-            L10N.getStr("toolbox.resumeOrderWarning"),
-            "wrong-resume-order",
-            "",
-            box.PRIORITY_WARNING_HIGH
-          );
-        } else {
-          throw ex;
-        }
-      }
-
+      this._threadClient = await this._attachAndResumeThread();
       this._startThreadClientListeners();
 
       await domReady;
 
       this.browserRequire = BrowserLoader({
         window: this.win,
         useOnlyShared: true,
       }).require;