Bug 1569690 - Use target instead of thread as greatest common divisor. r=loganfsmyth,nchevobbe
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 05 Aug 2019 10:53:52 +0000
changeset 486168 020e8aad58a88199e189ab3938b6368d6e49fb8a
parent 486167 48ffed44db64bf22d6358f976aeddf0de2984107
child 486169 8247f9a13f56cd11a11a8047905186cb2c36b97f
push id36391
push usermalexandru@mozilla.com
push dateMon, 05 Aug 2019 15:55:27 +0000
treeherdermozilla-central@9c91b33629b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersloganfsmyth, nchevobbe
bugs1569690
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 1569690 - Use target instead of thread as greatest common divisor. r=loganfsmyth,nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D39720
devtools/client/debugger/panel.js
devtools/client/debugger/src/client/firefox/commands.js
devtools/client/debugger/src/client/firefox/types.js
devtools/client/debugger/src/client/firefox/workers.js
devtools/client/webconsole/webconsole-wrapper.js
devtools/client/webconsole/webconsole.js
--- a/devtools/client/debugger/panel.js
+++ b/devtools/client/debugger/panel.js
@@ -132,22 +132,19 @@ DebuggerPanel.prototype = {
       this._getState(),
       thread
     );
     const selected = frames.findIndex(frame => frame.id == selectedFrame.id);
 
     frames.forEach(frame => {
       frame.actor = frame.id;
     });
+    const target = this._client.lookupTarget(thread);
 
-    return { frames, selected };
-  },
-
-  lookupConsoleClient: function(thread) {
-    return this._client.lookupConsoleClient(thread);
+    return { frames, selected, target };
   },
 
   getMappedExpression(expression) {
     return this._actions.getMappedExpression(expression);
   },
 
   isPaused() {
     const thread = this._selectors.getCurrentThread(this._getState());
--- a/devtools/client/debugger/src/client/firefox/commands.js
+++ b/devtools/client/debugger/src/client/firefox/commands.js
@@ -1,16 +1,16 @@
 /* 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/>. */
 
 // @flow
 
 import { prepareSourcePayload, createWorker } from "./create";
-import { supportsWorkers, updateWorkerClients } from "./workers";
+import { supportsWorkers, updateWorkerTargets } from "./workers";
 import { features } from "../../utils/prefs";
 
 import Reps from "devtools-reps";
 import type { Node } from "devtools-reps";
 
 import type {
   ActorId,
   BreakpointLocation,
@@ -35,17 +35,17 @@ import type {
   SourcesPacket,
 } from "./types";
 
 import type {
   EventListenerCategoryList,
   EventListenerActiveList,
 } from "../../actions/types";
 
-let workerClients: Object;
+let workerTargets: Object;
 let threadFront: ThreadFront;
 let tabTarget: TabTarget;
 let debuggerClient: DebuggerClient;
 let sourceActors: { [ActorId]: SourceId };
 let breakpoints: { [string]: Object };
 let eventBreakpoints: ?EventListenerActiveList;
 let supportsWasm: boolean;
 
@@ -56,17 +56,17 @@ type Dependencies = {
   supportsWasm: boolean,
 };
 
 function setupCommands(dependencies: Dependencies) {
   threadFront = dependencies.threadFront;
   tabTarget = dependencies.tabTarget;
   debuggerClient = dependencies.debuggerClient;
   supportsWasm = dependencies.supportsWasm;
-  workerClients = {};
+  workerTargets = {};
   sourceActors = {};
   breakpoints = {};
 }
 
 function hasWasmSupport() {
   return supportsWasm;
 }
 
@@ -93,35 +93,33 @@ function releaseActor(actor: String) {
 
   return debuggerClient.release(actor);
 }
 
 function sendPacket(packet: Object) {
   return debuggerClient.request(packet);
 }
 
-function lookupThreadFront(thread: string) {
+function lookupTarget(thread: string) {
   if (thread == threadFront.actor) {
-    return threadFront;
+    return tabTarget;
   }
-  if (!workerClients[thread]) {
-    throw new Error(`Unknown thread client: ${thread}`);
+  if (!workerTargets[thread]) {
+    throw new Error(`Unknown thread front: ${thread}`);
   }
-  return workerClients[thread].thread;
+  return workerTargets[thread];
 }
 
-function lookupConsoleClient(thread: string) {
-  if (thread == threadFront.actor) {
-    return tabTarget.activeConsole;
-  }
-  return workerClients[thread].console;
+function lookupThreadFront(thread: string) {
+  const target = lookupTarget(thread);
+  return target.threadFront;
 }
 
 function listWorkerThreadFronts() {
-  return (Object.values(workerClients): any).map(({ thread }) => thread);
+  return (Object.values(workerTargets): any).map(target => target.threadFront);
 }
 
 function forEachThread(iteratee) {
   // We have to be careful here to atomically initiate the operation on every
   // thread, with no intervening await. Otherwise, other code could run and
   // trigger additional thread operations. Requests on server threads will
   // resolve in FIFO order, and this could result in client and server state
   // going out of sync.
@@ -248,19 +246,18 @@ function evaluate(
   script: ?Script,
   { thread, frameId }: EvaluateParam = {}
 ): Promise<{ result: Grip | null }> {
   const params = { thread, frameActor: frameId };
   if (!tabTarget || !script) {
     return Promise.resolve({ result: null });
   }
 
-  const console = thread
-    ? lookupConsoleClient(thread)
-    : tabTarget.activeConsole;
+  const target = thread ? lookupTarget(thread) : tabTarget;
+  const console = target.activeConsole;
   if (!console) {
     return Promise.resolve({ result: null });
   }
 
   return console.evaluateJSAsync(script, params);
 }
 
 function autocomplete(
@@ -405,42 +402,42 @@ function getSourceForActor(actor: ActorI
 async function fetchWorkers(): Promise<Worker[]> {
   if (features.windowlessWorkers) {
     const options = {
       breakpoints,
       eventBreakpoints,
       observeAsmJS: true,
     };
 
-    const newWorkerClients = await updateWorkerClients({
+    const newWorkerTargets = await updateWorkerTargets({
       tabTarget,
       debuggerClient,
       threadFront,
-      workerClients,
+      workerTargets,
       options,
     });
 
     // Fetch the sources and install breakpoints on any new workers.
-    const workerNames = Object.getOwnPropertyNames(newWorkerClients);
+    const workerNames = Object.getOwnPropertyNames(newWorkerTargets);
     for (const actor of workerNames) {
-      if (!workerClients[actor]) {
-        const client = newWorkerClients[actor].thread;
+      if (!workerTargets[actor]) {
+        const front = newWorkerTargets[actor].threadFront;
 
         // This runs in the background and populates some data, but we also
         // want to allow it to fail quietly. For instance, it is pretty easy
         // for source clients to throw during the fetch if their thread
         // shuts down, and this would otherwise cause test failures.
-        getSources(client).catch(e => console.error(e));
+        getSources(front).catch(e => console.error(e));
       }
     }
 
-    workerClients = newWorkerClients;
+    workerTargets = newWorkerTargets;
 
     return workerNames.map(actor =>
-      createWorker(actor, workerClients[actor].url)
+      createWorker(actor, workerTargets[actor].url)
     );
   }
 
   if (!supportsWorkers(tabTarget)) {
     return Promise.resolve([]);
   }
 
   const { workers } = await tabTarget.listWorkers();
@@ -539,12 +536,12 @@ const clientCommands = {
   fetchWorkers,
   getMainThread,
   sendPacket,
   setSkipPausing,
   setEventListenerBreakpoints,
   getEventListenerBreakpointTypes,
   detachWorkers,
   hasWasmSupport,
-  lookupConsoleClient,
+  lookupTarget,
 };
 
 export { setupCommands, clientCommands };
--- a/devtools/client/debugger/src/client/firefox/types.js
+++ b/devtools/client/debugger/src/client/firefox/types.js
@@ -192,16 +192,17 @@ export type Actions = {
 /**
  * Tab Target gives access to the browser tabs
  * @memberof firefox
  * @static
  */
 export type TabTarget = {
   on: (string, Function) => void,
   emit: (string, any) => void,
+  threadFront: ThreadFront,
   activeConsole: {
     evaluateJS: (
       script: Script,
       func: Function,
       params?: { frameActor: ?FrameId }
     ) => void,
     evaluateJSAsync: (
       script: Script,
--- a/devtools/client/debugger/src/client/firefox/workers.js
+++ b/devtools/client/debugger/src/client/firefox/workers.js
@@ -6,51 +6,47 @@
 
 import { addThreadEventListeners } from "./events";
 import type { TabTarget } from "./types";
 
 export function supportsWorkers(tabTarget: TabTarget) {
   return tabTarget.isBrowsingContext || tabTarget.isContentProcess;
 }
 
-export async function updateWorkerClients({
+export async function updateWorkerTargets({
   tabTarget,
   debuggerClient,
   threadFront,
-  workerClients,
+  workerTargets,
   options,
 }: Object) {
   if (!supportsWorkers(tabTarget)) {
     return {};
   }
 
-  const newWorkerClients = {};
+  const newWorkerTargets = {};
 
   const { workers } = await tabTarget.listWorkers();
   for (const workerTargetFront of workers) {
     try {
       await workerTargetFront.attach();
       const threadActorID = workerTargetFront._threadActor;
-      if (workerClients[threadActorID]) {
-        newWorkerClients[threadActorID] = workerClients[threadActorID];
+      if (workerTargets[threadActorID]) {
+        newWorkerTargets[threadActorID] = workerTargets[threadActorID];
       } else {
         const [, workerThread] = await workerTargetFront.attachThread(options);
         workerThread.resume();
 
         addThreadEventListeners(workerThread);
 
         const consoleFront = await workerTargetFront.getFront("console");
         await consoleFront.startListeners([]);
 
-        newWorkerClients[workerThread.actor] = {
-          url: workerTargetFront.url,
-          thread: workerThread,
-          console: consoleFront,
-        };
+        newWorkerTargets[workerThread.actor] = workerTargetFront;
       }
     } catch (e) {
       // If any of the workers have terminated since the list command initiated
       // then we will get errors. Ignore these.
     }
   }
 
-  return newWorkerClients;
+  return newWorkerTargets;
 }
--- a/devtools/client/webconsole/webconsole-wrapper.js
+++ b/devtools/client/webconsole/webconsole-wrapper.js
@@ -172,17 +172,17 @@ class WebConsoleWrapper {
           const grip = state.frames[state.selected];
 
           if (!grip) {
             return { frameActor: null, client: webConsoleUI.webConsoleClient };
           }
 
           return {
             frameActor: grip.actor,
-            client: this.hud.lookupConsoleClient(grip.thread),
+            client: state.target.activeConsole,
           };
         },
 
         inputHasSelection: () => {
           const { editor } = webConsoleUI.jsterm || {};
           return editor && !!editor.getSelection();
         },
 
--- a/devtools/client/webconsole/webconsole.js
+++ b/devtools/client/webconsole/webconsole.js
@@ -270,28 +270,16 @@ class WebConsole {
     if (!panel) {
       return null;
     }
 
     return panel.getFrames();
   }
 
   /**
-   * Return the console client to use when interacting with a thread.
-   *
-   * @param {String} thread: The ID of the target thread.
-   * @returns {Object} The console client associated with the thread.
-   */
-  lookupConsoleClient(thread) {
-    const toolbox = gDevTools.getToolbox(this.target);
-    const panel = toolbox.getPanel("jsdebugger");
-    return panel.lookupConsoleClient(thread);
-  }
-
-  /**
    * Given an expression, returns an object containing a new expression, mapped by the
    * parser worker to provide additional feature for the user (top-level await,
    * original languages mapping, …).
    *
    * @param {String} expression: The input to maybe map.
    * @returns {Object|null}
    *          Returns null if the input can't be mapped.
    *          If it can, returns an object containing the following: