Bug 1746368 - [devtools] Add blackbox checks for specfic paused frame location lines r=ochameau

Differential Revision: https://phabricator.services.mozilla.com/D135393
This commit is contained in:
Hubert Boma Manilla 2022-01-12 23:44:19 +00:00
Родитель ece708abfa
Коммит c150b0a2c0
10 изменённых файлов: 107 добавлений и 268 удалений

Просмотреть файл

@ -2,24 +2,38 @@
* 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/>. */
import { getFrames, getSource, getSelectedFrame } from "../../selectors";
import {
getFrames,
getBlackBoxRanges,
getSource,
getSelectedFrame,
} from "../../selectors";
import { isFrameBlackBoxed } from "../../utils/source";
import assert from "../../utils/assert";
import { isGeneratedId } from "devtools-source-map";
function isFrameBlackboxed(state, frame) {
const source = getSource(state, frame.location.sourceId);
return !!source?.isBlackBoxed;
}
function getSelectedFrameId(state, thread, frames) {
let selectedFrame = getSelectedFrame(state, thread);
if (selectedFrame && !isFrameBlackboxed(state, selectedFrame)) {
const blackboxedRanges = getBlackBoxRanges(state);
if (
selectedFrame &&
!isFrameBlackBoxed(
selectedFrame,
getSource(state, selectedFrame.location.sourceId),
blackboxedRanges
)
) {
return selectedFrame.id;
}
selectedFrame = frames.find(frame => !isFrameBlackboxed(state, frame));
selectedFrame = frames.find(frame => {
const frameSource = getSource(state, frame.location.sourceId);
return !isFrameBlackBoxed(frame, frameSource, blackboxedRanges);
});
return selectedFrame?.id;
}

Просмотреть файл

@ -27,59 +27,3 @@ Object {
},
}
`;
exports[`sources - pretty print should create a source when first toggling pretty print 1`] = `
Object {
"extensionName": null,
"id": "base.js/originalSource-36c718d4bde9a75edb388ff7733efe7f",
"isBlackBoxed": false,
"isExtension": false,
"isOriginal": true,
"isPrettyPrinted": true,
"isWasm": false,
"relativeUrl": "/examples/base.js:formatted",
"url": "http://localhost:8000/examples/base.js:formatted",
}
`;
exports[`sources - pretty print should create a source when first toggling pretty print 2`] = `
Object {
"state": "fulfilled",
"value": Object {
"contentType": "text/javascript",
"type": "text",
"value": "function base() {
return base
}
",
},
}
`;
exports[`sources - pretty print should not make a second source when toggling pretty print 1`] = `
Object {
"extensionName": null,
"id": "base.js/originalSource-36c718d4bde9a75edb388ff7733efe7f",
"isBlackBoxed": false,
"isExtension": false,
"isOriginal": true,
"isPrettyPrinted": true,
"isWasm": false,
"relativeUrl": "/examples/base.js:formatted",
"url": "http://localhost:8000/examples/base.js:formatted",
}
`;
exports[`sources - pretty print should not make a second source when toggling pretty print 2`] = `
Object {
"state": "fulfilled",
"value": Object {
"contentType": "text/javascript",
"type": "text",
"value": "function base() {
return base
}
",
},
}
`;

Просмотреть файл

@ -1,169 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ast setSymbols frameworks should detect react components 1`] = `
Object {
"callExpressions": Array [],
"classes": Array [],
"comments": Array [],
"functions": Array [
Object {
"identifier": Object {
"end": 13,
"loc": Object {
"end": Object {
"column": 13,
"line": 1,
},
"identifierName": "base",
"start": Object {
"column": 9,
"line": 1,
},
},
"name": "base",
"start": 9,
"type": "Identifier",
},
"index": 0,
"klass": null,
"location": Object {
"end": Object {
"column": 21,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"name": "base",
"parameterNames": Array [
"boo",
],
},
],
"hasJsx": false,
"hasTypes": false,
"identifiers": Array [
Object {
"expression": "base",
"location": Object {
"end": Object {
"column": 13,
"line": 1,
},
"start": Object {
"column": 9,
"line": 1,
},
},
"name": "base",
},
Object {
"expression": "boo",
"location": Object {
"end": Object {
"column": 17,
"line": 1,
},
"start": Object {
"column": 14,
"line": 1,
},
},
"name": "boo",
},
],
"imports": Array [],
"literals": Array [],
"loading": false,
"memberExpressions": Array [],
"objectProperties": Array [],
}
`;
exports[`ast setSymbols frameworks should not give false positive on non react components 1`] = `
Object {
"callExpressions": Array [],
"classes": Array [],
"comments": Array [],
"functions": Array [
Object {
"identifier": Object {
"end": 13,
"loc": Object {
"end": Object {
"column": 13,
"line": 1,
},
"identifierName": "base",
"start": Object {
"column": 9,
"line": 1,
},
},
"name": "base",
"start": 9,
"type": "Identifier",
},
"index": 0,
"klass": null,
"location": Object {
"end": Object {
"column": 21,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"name": "base",
"parameterNames": Array [
"boo",
],
},
],
"hasJsx": false,
"hasTypes": false,
"identifiers": Array [
Object {
"expression": "base",
"location": Object {
"end": Object {
"column": 13,
"line": 1,
},
"start": Object {
"column": 9,
"line": 1,
},
},
"name": "base",
},
Object {
"expression": "boo",
"location": Object {
"end": Object {
"column": 17,
"line": 1,
},
"start": Object {
"column": 14,
"line": 1,
},
},
"name": "boo",
},
],
"imports": Array [],
"literals": Array [],
"loading": false,
"memberExpressions": Array [],
"objectProperties": Array [],
}
`;
exports[`ast setSymbols when the source is loaded should be able to set symbols 1`] = `
Object {
"callExpressions": Array [],

Просмотреть файл

@ -1,7 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`preview queued previews (w/ the 1st finishing first) 1`] = `null`;
exports[`preview queued previews (w/ the 2nd finishing first) 1`] = `null`;
exports[`preview should generate previews 1`] = `null`;

Просмотреть файл

@ -41,8 +41,6 @@ Array [
exports[`project text search should clear all the search results 2`] = `Array []`;
exports[`project text search should clear all the search results 3`] = `Array []`;
exports[`project text search should close project search 1`] = `
Array [
Object {

Просмотреть файл

@ -9,6 +9,7 @@ import {
getRawSourceURL,
getFilename,
shouldBlackbox,
findBlackBoxRange,
} from "../../../utils/source";
import { toSourceLine } from "../../../utils/editor";
import { downloadFile } from "../../../utils/utils";
@ -90,27 +91,6 @@ const blackBoxMenuItem = (cx, selectedSource, editorActions) => ({
disabled: !shouldBlackbox(selectedSource),
click: () => editorActions.toggleBlackBox(cx, selectedSource),
});
/**
* Checks if a blackbox range exist for the line range.
* That is if any start and end lines overlap any of the
* blackbox ranges
*
* @param {Object} source - The current selected source
* @param {Object} blackboxedRanges - the store of blackboxedRanges
* @param {Object} line - The start and end line range
*/
function findBlackBoxRange(source, blackboxedRanges, line) {
const ranges = blackboxedRanges[source.url];
if (!ranges || !ranges.length) {
return null;
}
return ranges.find(
range =>
(line.start >= range.start.line && line.start <= range.end.line) ||
(line.end >= range.start.line && line.end <= range.end.line)
);
}
export const blackBoxLineMenuItem = (
cx,

Просмотреть файл

@ -189,8 +189,8 @@ describe("Frames", () => {
describe("Blackboxed Frames", () => {
it("filters blackboxed frames", () => {
const source1 = makeMockSource(undefined, "1");
const source2 = makeMockSource(undefined, "2");
const source1 = makeMockSource("source1", "1");
const source2 = makeMockSource("source2", "2");
source2.isBlackBoxed = true;
const frames = [
@ -200,12 +200,21 @@ describe("Frames", () => {
makeMockFrame("8", source2),
];
const blackboxedRanges = {
source2: [],
};
const sources = insertResources(createInitial(), [
{ ...source1, content: null },
{ ...source2, content: null },
]);
const processedFrames = formatCallStackFrames(frames, sources, source1);
const processedFrames = formatCallStackFrames(
frames,
sources,
source1,
blackboxedRanges
);
const selectedFrame = frames[0];
const component = render({

Просмотреть файл

@ -44,8 +44,8 @@ exports[`Frames Blackboxed Frames filters blackboxed frames 1`] = `
"isOriginal": false,
"isPrettyPrinted": false,
"isWasm": false,
"relativeUrl": "url",
"url": "url",
"relativeUrl": "source1",
"url": "source1",
},
"state": "on-stack",
"this": Object {},
@ -91,8 +91,8 @@ exports[`Frames Blackboxed Frames filters blackboxed frames 1`] = `
"isOriginal": false,
"isPrettyPrinted": false,
"isWasm": false,
"relativeUrl": "url",
"url": "url",
"relativeUrl": "source1",
"url": "source1",
},
"state": "on-stack",
"this": Object {},
@ -141,8 +141,8 @@ exports[`Frames Blackboxed Frames filters blackboxed frames 1`] = `
"isOriginal": false,
"isPrettyPrinted": false,
"isWasm": false,
"relativeUrl": "url",
"url": "url",
"relativeUrl": "source1",
"url": "source1",
},
"state": "on-stack",
"this": Object {},
@ -188,8 +188,8 @@ exports[`Frames Blackboxed Frames filters blackboxed frames 1`] = `
"isOriginal": false,
"isPrettyPrinted": false,
"isWasm": false,
"relativeUrl": "url",
"url": "url",
"relativeUrl": "source1",
"url": "source1",
},
"state": "on-stack",
"this": Object {},

Просмотреть файл

@ -6,9 +6,11 @@ import {
getSources,
getSelectedSource,
getSourceInSources,
getBlackBoxRanges,
} from "../reducers/sources";
import { getCurrentThreadFrames } from "../reducers/pause";
import { annotateFrames } from "../utils/pause/frames";
import { isFrameBlackBoxed } from "../utils/source";
import { createSelector } from "reselect";
function getLocation(frame, isGeneratedSource) {
@ -31,7 +33,12 @@ function appendSource(sources, frame, selectedSource) {
};
}
export function formatCallStackFrames(frames, sources, selectedSource) {
export function formatCallStackFrames(
frames,
sources,
selectedSource,
blackboxedRanges
) {
if (!frames) {
return null;
}
@ -39,7 +46,7 @@ export function formatCallStackFrames(frames, sources, selectedSource) {
const formattedFrames = frames
.filter(frame => getSourceForFrame(sources, frame))
.map(frame => appendSource(sources, frame, selectedSource))
.filter(frame => !frame?.source?.isBlackBoxed);
.filter(frame => !isFrameBlackBoxed(frame, frame.source, blackboxedRanges));
return annotateFrames(formattedFrames);
}
@ -49,5 +56,6 @@ export const getCallStackFrames = (createSelector)(
getCurrentThreadFrames,
getSources,
getSelectedSource,
getBlackBoxRanges,
formatCallStackFrames
);

Просмотреть файл

@ -60,6 +60,60 @@ export function shouldBlackbox(source) {
return true;
}
/**
* Checks if the frame is within a line ranges which are blackboxed
* in the source.
*
* @param {Object} frame
* The current frame
* @param {Object} source
* The source related to the frame
* @param {Object} blackboxedRanges
* The currently blackboxedRanges for all the sources.
* @param {Boolean} isFrameBlackBoxed
* If the frame is within the blackboxed range
* or not.
*/
export function isFrameBlackBoxed(frame, source, blackboxedRanges) {
return (
!!source?.isBlackBoxed &&
(!blackboxedRanges[source.url].length ||
!!findBlackBoxRange(source, blackboxedRanges, {
start: frame.location.line,
end: frame.location.line,
}))
);
}
/**
* Checks if a blackbox range exist for the line range.
* That is if any start and end lines overlap any of the
* blackbox ranges
*
* @param {Object} source
* The current selected source
* @param {Object} blackboxedRanges
* The store of blackboxedRanges
* @param {Object} lineRange
* The start/end line range `{ start: <Number>, end: <Number> }`
* @return {Object} blackboxRange
* The first matching blackbox range that all or part of the
* specified lineRange sits within.
*/
export function findBlackBoxRange(source, blackboxedRanges, lineRange) {
const ranges = blackboxedRanges[source.url];
if (!ranges || !ranges.length) {
return null;
}
return ranges.find(
range =>
(lineRange.start >= range.start.line &&
lineRange.start <= range.end.line) ||
(lineRange.end >= range.start.line && lineRange.end <= range.end.line)
);
}
/**
* Returns true if the specified url and/or content type are specific to
* javascript files.