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
This commit is contained in:
Alexandre Poirot 2023-04-26 12:55:40 +00:00
parent 851dc88347
commit e4ee099d1d
7 changed files with 49 additions and 17 deletions

View File

@ -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);
}

View File

@ -34,7 +34,7 @@ export function highlightCalls(cx) {
getCurrentThread(getState())
);
if (!frame) {
if (!frame || !parserWorker.isLocationSupported(frame.location)) {
return null;
}

View File

@ -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) {

View File

@ -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
)
);
}
}

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}
}