From e4ee099d1d467652fd26edd7a0bad421196d4c4f Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Wed, 26 Apr 2023 12:55:40 +0000 Subject: [PATCH] Bug 1829688 - [devtools] Avoid querying the parser worker for unsupported sources. r=nchevobbe,devtools-reviewers The worker itself ignores already the WASM sources, but we could save some cycle to avoid calling the parserWorker entirely when we know the source won't be supported by it. Differential Revision: https://phabricator.services.mozilla.com/D176414 --- .../src/actions/ast/setInScopeLines.js | 2 +- .../src/actions/pause/highlightCalls.js | 2 +- .../src/actions/pause/inlinePreview.js | 4 +++ .../src/actions/sources/loadSourceText.js | 34 ++++++++++++------- .../debugger/src/actions/sources/symbols.js | 4 +-- .../src/utils/pause/mapScopes/index.js | 3 ++ .../debugger/src/workers/parser/index.js | 17 ++++++++++ 7 files changed, 49 insertions(+), 17 deletions(-) diff --git a/devtools/client/debugger/src/actions/ast/setInScopeLines.js b/devtools/client/debugger/src/actions/ast/setInScopeLines.js index 4a9f17817908..a17510a5073a 100644 --- a/devtools/client/debugger/src/actions/ast/setInScopeLines.js +++ b/devtools/client/debugger/src/actions/ast/setInScopeLines.js @@ -35,7 +35,7 @@ async function getInScopeLines( const sourceTextContent = getSourceTextContent(getState(), location); let locations = null; - if (location.line && location.source && !location.source.isWasm) { + if (location.line && parserWorker.isLocationSupported(location)) { locations = await parserWorker.findOutOfScopeLocations(location); } diff --git a/devtools/client/debugger/src/actions/pause/highlightCalls.js b/devtools/client/debugger/src/actions/pause/highlightCalls.js index 874f0a1648e2..aaa41ae40ad5 100644 --- a/devtools/client/debugger/src/actions/pause/highlightCalls.js +++ b/devtools/client/debugger/src/actions/pause/highlightCalls.js @@ -34,7 +34,7 @@ export function highlightCalls(cx) { getCurrentThread(getState()) ); - if (!frame) { + if (!frame || !parserWorker.isLocationSupported(frame.location)) { return null; } diff --git a/devtools/client/debugger/src/actions/pause/inlinePreview.js b/devtools/client/debugger/src/actions/pause/inlinePreview.js index 70559fe035eb..83d0fd6697f5 100644 --- a/devtools/client/debugger/src/actions/pause/inlinePreview.js +++ b/devtools/client/debugger/src/actions/pause/inlinePreview.js @@ -63,6 +63,10 @@ export function generateInlinePreview(cx, frame) { return null; } + if (!parserWorker.isLocationSupported(selectedLocation)) { + return null; + } + const originalAstScopes = await parserWorker.getScopes(selectedLocation); validateThreadContext(getState(), cx); if (!originalAstScopes) { diff --git a/devtools/client/debugger/src/actions/sources/loadSourceText.js b/devtools/client/debugger/src/actions/sources/loadSourceText.js index 83a5ba4b91e7..1a3890b112fb 100644 --- a/devtools/client/debugger/src/actions/sources/loadSourceText.js +++ b/devtools/client/debugger/src/actions/sources/loadSourceText.js @@ -126,27 +126,35 @@ async function onSourceTextContentAvailable( sourceActor, { dispatch, getState, parserWorker } ) { - const content = getSettledSourceTextContent( - getState(), - createLocation({ - source, - sourceActor, - }) - ); + const location = createLocation({ + source, + sourceActor, + }); + const content = getSettledSourceTextContent(getState(), location); + if (!content) { + return; + } - if (!source.isWasm && content) { + if (parserWorker.isLocationSupported(location)) { parserWorker.setSource( source.id, isFulfilled(content) ? content.value : { type: "text", value: "", contentType: undefined } ); + } - // Update the text in any breakpoints for this source by re-adding them. - const breakpoints = getBreakpointsForSource(getState(), source.id); - for (const { location, options, disabled } of breakpoints) { - await dispatch(addBreakpoint(cx, location, options, disabled)); - } + // Update the text in any breakpoints for this source by re-adding them. + const breakpoints = getBreakpointsForSource(getState(), source.id); + for (const breakpoint of breakpoints) { + await dispatch( + addBreakpoint( + cx, + breakpoint.location, + breakpoint.options, + breakpoint.disabled + ) + ); } } diff --git a/devtools/client/debugger/src/actions/sources/symbols.js b/devtools/client/debugger/src/actions/sources/symbols.js index cd2f65f90fda..5a1fb1f967df 100644 --- a/devtools/client/debugger/src/actions/sources/symbols.js +++ b/devtools/client/debugger/src/actions/sources/symbols.js @@ -26,8 +26,8 @@ async function doSetSymbols( } export const setSymbols = memoizeableAction("setSymbols", { - getValue: ({ location }, { getState }) => { - if (location.source.isWasm) { + getValue: ({ location }, { getState, parserWorker }) => { + if (!parserWorker.isLocationSupported(location)) { return fulfilled(null); } diff --git a/devtools/client/debugger/src/utils/pause/mapScopes/index.js b/devtools/client/debugger/src/utils/pause/mapScopes/index.js index 8bbc0bbad314..3ca12ec0f248 100644 --- a/devtools/client/debugger/src/utils/pause/mapScopes/index.js +++ b/devtools/client/debugger/src/utils/pause/mapScopes/index.js @@ -32,6 +32,9 @@ export async function buildMappedScopes( thunkArgs ) { const { parserWorker } = thunkArgs; + if (!parserWorker.isLocationSupported(frame.location)) { + return null; + } const originalAstScopes = await parserWorker.getScopes(frame.location); const generatedAstScopes = await parserWorker.getScopes( frame.generatedLocation diff --git a/devtools/client/debugger/src/workers/parser/index.js b/devtools/client/debugger/src/workers/parser/index.js index f5028101ca7e..5f038179d3d7 100644 --- a/devtools/client/debugger/src/workers/parser/index.js +++ b/devtools/client/debugger/src/workers/parser/index.js @@ -33,4 +33,21 @@ export class ParserDispatcher extends WorkerDispatcher { mapExpression = this.task("mapExpression"); clear = this.task("clearState"); + + /** + * Reports if the location's source can be parsed by this worker. + * + * @param {Object} location + * A debugger frontend location object. See createLocation(). + * @return {Boolean} + * True, if the worker may be able to parse this source. + */ + isLocationSupported(location) { + // There might be more sources that the worker doesn't support, + // like original sources which aren't JavaScript. + // But we can only know with the source's content type, + // which isn't available right away. + // These source will be ignored from within the worker. + return !location.source.isWasm; + } }