From 6865c4f4be3c5d9261e7010e478eb081d6ffe761 Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Fri, 13 Dec 2019 09:13:02 +0000 Subject: [PATCH] Bug 1566850 - Remove target.activeConsole usage in Debugger. r=jlast. Differential Revision: https://phabricator.services.mozilla.com/D56690 --HG-- extra : moz-landing-system : lando --- .../debugger/src/client/firefox/commands.js | 31 +++++++++-------- .../debugger/src/client/firefox/types.js | 33 +++++++++---------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/devtools/client/debugger/src/client/firefox/commands.js b/devtools/client/debugger/src/client/firefox/commands.js index 55be332a10c3..949a937a4df3 100644 --- a/devtools/client/debugger/src/client/firefox/commands.js +++ b/devtools/client/debugger/src/client/firefox/commands.js @@ -230,13 +230,11 @@ function maybeGenerateLogGroupId(options) { return options; } -function maybeClearLogpoint(location: BreakpointLocation) { +async function maybeClearLogpoint(location: BreakpointLocation) { const bp = breakpoints[locationKey(location)]; - if (bp && bp.options.logGroupId && currentTarget.activeConsole) { - currentTarget.activeConsole.emit( - "clearLogpointMessages", - bp.options.logGroupId - ); + if (bp && bp.options.logGroupId && currentTarget) { + const consoleFront = await currentTarget.getFront("console"); + consoleFront.emit("clearLogpointMessages", bp.options.logGroupId); } } @@ -275,34 +273,39 @@ async function evaluateExpressions(scripts: Script[], options: EvaluateParam) { type EvaluateParam = { thread: string, frameId: ?FrameId }; -function evaluate( +async function evaluate( script: ?Script, { thread, frameId }: EvaluateParam = {} ): Promise<{ result: ExpressionResult }> { const params = { thread, frameActor: frameId }; if (!currentTarget || !script) { - return Promise.resolve({ result: null }); + return { result: null }; } const target = thread ? lookupTarget(thread) : currentTarget; - const consoleFront = target.activeConsole; + const consoleFront = await target.getFront("console"); if (!consoleFront) { - return Promise.resolve({ result: null }); + return { result: null }; } return consoleFront.evaluateJSAsync(script, params); } -function autocomplete( +async function autocomplete( input: string, cursor: number, frameId: ?string ): Promise { - if (!currentTarget || !currentTarget.activeConsole || !input) { - return Promise.resolve({}); + if (!currentTarget || !input) { + return {}; } + const consoleFront = await currentTarget.getFront("console"); + if (!consoleFront) { + return {}; + } + return new Promise(resolve => { - currentTarget.activeConsole.autocomplete( + consoleFront.autocomplete( input, cursor, result => resolve(result), diff --git a/devtools/client/debugger/src/client/firefox/types.js b/devtools/client/debugger/src/client/firefox/types.js index a5ef7ae9a85e..4dc8169028b2 100644 --- a/devtools/client/debugger/src/client/firefox/types.js +++ b/devtools/client/debugger/src/client/firefox/types.js @@ -178,21 +178,6 @@ export type TabPayload = { webExtensionInspectedWindowActor: ActorId, }; -type ConsoleClient = { - evaluateJSAsync: ( - script: Script, - func: Function, - params?: { frameActor: ?FrameId } - ) => Promise<{ result: ExpressionResult }>, - autocomplete: ( - input: string, - cursor: number, - func: Function, - frameId: ?string - ) => void, - emit: (string, any) => void, -}; - /** * Tab Target gives access to the browser tabs * @memberof firefox @@ -201,6 +186,7 @@ type ConsoleClient = { export type Target = { on: (string, Function) => void, emit: (string, any) => void, + getFront: string => Promise, form: { consoleActor: any }, root: any, navigateTo: ({ url: string }) => Promise<*>, @@ -208,8 +194,6 @@ export type Target = { reload: () => Promise<*>, destroy: () => void, threadFront: ThreadFront, - activeConsole: ConsoleClient, - name: string, isBrowsingContext: boolean, isContentProcess: boolean, @@ -224,6 +208,21 @@ export type Target = { debuggerServiceWorkerStatus: string, }; +type ConsoleFront = { + evaluateJSAsync: ( + script: Script, + func: Function, + params?: { frameActor: ?FrameId } + ) => Promise<{ result: ExpressionResult }>, + autocomplete: ( + input: string, + cursor: number, + func: Function, + frameId: ?string + ) => void, + emit: (string, any) => void, +}; + /** * Clients for accessing the Firefox debug server and browser * @memberof firefox/clients