Skip to content

Commit

Permalink
Bug 1824705 - [devtools] Add support for sourcemaps ignore list r=dev…
Browse files Browse the repository at this point in the history
…tools-reviewers,nchevobbe

Also there is a patch to add support for ignoreList to the sourcemap library
mozilla/source-map#481

Differential Revision: https://phabricator.services.mozilla.com/D174357
  • Loading branch information
bomsy committed May 22, 2023
1 parent aa3d711 commit b735281
Show file tree
Hide file tree
Showing 28 changed files with 328 additions and 67 deletions.
13 changes: 10 additions & 3 deletions devtools/client/debugger/src/actions/breakpoints/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
getPendingBreakpointList,
isMapScopesEnabled,
getBlackBoxRanges,
isSourceMapIgnoreListEnabled,
isSourceOnSourceMapIgnoreList,
} from "../../selectors";

import { setBreakpointPositions } from "./breakpointPositions";
Expand Down Expand Up @@ -81,14 +83,19 @@ function clientRemoveBreakpoint(client, state, generatedLocation) {
export function enableBreakpoint(cx, initialBreakpoint) {
return thunkArgs => {
const { dispatch, getState, client } = thunkArgs;
const breakpoint = getBreakpoint(getState(), initialBreakpoint.location);
const blackboxedRanges = getBlackBoxRanges(getState());
const state = getState();
const breakpoint = getBreakpoint(state, initialBreakpoint.location);
const blackboxedRanges = getBlackBoxRanges(state);
const isSourceOnIgnoreList =
isSourceMapIgnoreListEnabled(state) &&
isSourceOnSourceMapIgnoreList(state, breakpoint.location.source);
if (
!breakpoint ||
!breakpoint.disabled ||
isLineBlackboxed(
blackboxedRanges[breakpoint.location.source.url],
breakpoint.location.line
breakpoint.location.line,
isSourceOnIgnoreList
)
) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions devtools/client/debugger/src/actions/sources/blackbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getBreakpointsForSource,
} from "../../selectors";

async function _blackboxSourceActorsForSource(
export async function blackboxSourceActorsForSource(
thunkArgs,
source,
shouldBlackBox,
Expand Down Expand Up @@ -82,7 +82,7 @@ export function toggleBlackBox(cx, source, shouldBlackBox, ranges = []) {
? shouldBlackBox
: !isSourceBlackBoxed(getState(), source);

await _blackboxSourceActorsForSource(
await blackboxSourceActorsForSource(
thunkArgs,
source,
shouldBlackBox,
Expand Down Expand Up @@ -200,7 +200,7 @@ export function blackBoxSources(cx, sourcesToBlackBox, shouldBlackBox) {
}

for (const source of sources) {
await _blackboxSourceActorsForSource(thunkArgs, source, shouldBlackBox);
await blackboxSourceActorsForSource(thunkArgs, source, shouldBlackBox);
}

if (shouldBlackBox) {
Expand Down
13 changes: 10 additions & 3 deletions devtools/client/debugger/src/actions/sources/newSources.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Redux actions for the sources state
* @module actions/sources
*/

import { PROMISE } from "../utils/middleware/promise";
import { insertSourceActors } from "../../actions/source-actors";
import {
makeSourceId,
Expand All @@ -18,6 +18,7 @@ import { toggleBlackBox } from "./blackbox";
import { syncBreakpoint } from "../breakpoints";
import { loadSourceText } from "./loadSourceText";
import { togglePrettyPrint } from "./prettyPrint";
import { toggleSourceMapIgnoreList } from "../ui";
import { selectLocation, setBreakableLines } from "../sources";

import { getRawSourceURL, isPrettyURL } from "../../utils/source";
Expand Down Expand Up @@ -54,14 +55,12 @@ function loadSourceMaps(cx, sources) {
);

await sourceQueue.flush();

return sourceList.flat();
} catch (error) {
if (!(error instanceof ContextError)) {
throw error;
}
}

return [];
};
}
Expand Down Expand Up @@ -91,6 +90,10 @@ function loadSourceMap(cx, sourceActor) {
sourceMapURL: sourceActor.sourceMapURL || "",
isWasm: sourceActor.introductionType === "wasm",
});
dispatch({
type: "ADD_SOURCEMAP_IGNORE_LIST_SOURCES",
[PROMISE]: sourceMapLoader.getSourceMapIgnoreList(source.id),
});
}
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -194,6 +197,10 @@ function restoreBlackBoxedSources(cx, sources) {
await dispatch(toggleBlackBox(cx, source, true, ranges));
}
}

if (prefs.sourceMapIgnoreListEnabled) {
await dispatch(toggleSourceMapIgnoreList(cx, true));
}
};
}

Expand Down
24 changes: 24 additions & 0 deletions devtools/client/debugger/src/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import {
getSource,
getSourceContent,
getMainThread,
getIgnoreListSourceUrls,
getSourceByURL,
getBreakpointsForSource,
} from "../selectors";
import { selectSource } from "../actions/sources/select";
import {
getEditor,
getLocationsInViewport,
updateDocuments,
} from "../utils/editor";
import { blackboxSourceActorsForSource } from "./sources/blackbox";
import { toggleBreakpoints } from "./breakpoints";
import { copyToTheClipboard } from "../utils/clipboard";
import { isFulfilled } from "../utils/async-value";

Expand Down Expand Up @@ -242,3 +247,22 @@ export function setHideOrShowIgnoredSources(shouldHide) {
dispatch({ type: "HIDE_IGNORED_SOURCES", shouldHide });
};
}

export function toggleSourceMapIgnoreList(cx, shouldEnable) {
return async thunkArgs => {
const { dispatch, getState } = thunkArgs;
const ignoreListSourceUrls = getIgnoreListSourceUrls(getState());
// Blackbox the source actors on the server
for (const url of ignoreListSourceUrls) {
const source = getSourceByURL(getState(), url);
await blackboxSourceActorsForSource(thunkArgs, source, shouldEnable);
// Disable breakpoints in sources on the ignore list
const breakpoints = getBreakpointsForSource(getState(), source.id);
await dispatch(toggleBreakpoints(cx, shouldEnable, breakpoints));
}
await dispatch({
type: "ENABLE_SOURCEMAP_IGNORELIST",
shouldEnable,
});
};
}
37 changes: 33 additions & 4 deletions devtools/client/debugger/src/components/Editor/BlackboxLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import PropTypes from "prop-types";
import { Component } from "react";
import { toEditorLine, fromEditorLine } from "../../utils/editor";
import { isLineBlackboxed } from "../../utils/source";
import { getBlackBoxRanges, getSelectedSource } from "../../selectors";
import {
getBlackBoxRanges,
getSelectedSource,
isSourceMapIgnoreListEnabled,
isSourceOnSourceMapIgnoreList,
} from "../../selectors";
import { isWasm } from "../../utils/wasm";

// This renders blackbox line highlighting in the editor
Expand All @@ -17,13 +22,19 @@ class BlackboxLines extends Component {
editor: PropTypes.object,
selectedSource: PropTypes.object,
blackboxedRangesForSelectedSource: PropTypes.object,
isSourceOnIgnoreList: PropTypes.bool,
};
}

componentDidMount() {
const { selectedSource, blackboxedRangesForSelectedSource, editor } =
this.props;

if (this.props.isSourceOnIgnoreList) {
this.setAllBlackboxLines(editor);
return;
}

// When `blackboxedRangesForSelectedSource` is undefined, the source isn't blackboxed
if (!blackboxedRangesForSelectedSource) {
return;
Expand All @@ -47,8 +58,17 @@ class BlackboxLines extends Component {
}

componentDidUpdate() {
const { selectedSource, blackboxedRangesForSelectedSource, editor } =
this.props;
const {
selectedSource,
blackboxedRangesForSelectedSource,
editor,
isSourceOnIgnoreList,
} = this.props;

if (this.props.isSourceOnIgnoreList) {
this.setAllBlackboxLines(editor);
return;
}

// when unblackboxed
if (!blackboxedRangesForSelectedSource) {
Expand All @@ -75,7 +95,13 @@ class BlackboxLines extends Component {
sourceIsWasm
);

if (isLineBlackboxed(blackboxedRangesForSelectedSource, line)) {
if (
isLineBlackboxed(
blackboxedRangesForSelectedSource,
line,
isSourceOnIgnoreList
)
) {
this.setBlackboxLine(editor, lineHandle);
} else {
this.clearBlackboxLine(editor, lineHandle);
Expand Down Expand Up @@ -128,6 +154,9 @@ const mapStateToProps = state => {
blackboxedRangesForSelectedSource: selectedSource
? getBlackBoxRanges(state)[selectedSource.url]
: undefined,
isSourceOnIgnoreList:
isSourceMapIgnoreListEnabled(state) &&
isSourceOnSourceMapIgnoreList(state, selectedSource),
};
};

Expand Down
5 changes: 4 additions & 1 deletion devtools/client/debugger/src/components/Editor/Breakpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Breakpoint extends PureComponent {
editorActions: PropTypes.object.isRequired,
selectedSource: PropTypes.object,
blackboxedRangesForSelectedSource: PropTypes.array,
isSelectedSourceOnIgnoreList: PropTypes.bool.isRequired,
};
}

Expand Down Expand Up @@ -97,6 +98,7 @@ class Breakpoint extends PureComponent {
selectedSource,
breakpointActions,
blackboxedRangesForSelectedSource,
isSelectedSourceOnIgnoreList,
} = this.props;
event.stopPropagation();
event.preventDefault();
Expand All @@ -109,7 +111,8 @@ class Breakpoint extends PureComponent {
breakpoint,
selectedLocation,
breakpointActions,
blackboxedRangesForSelectedSource
blackboxedRangesForSelectedSource,
isSelectedSourceOnIgnoreList
)
);
};
Expand Down
33 changes: 24 additions & 9 deletions devtools/client/debugger/src/components/Editor/Breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
getSelectedSource,
getFirstVisibleBreakpoints,
getBlackBoxRanges,
isSourceMapIgnoreListEnabled,
isSourceOnSourceMapIgnoreList,
} from "../../selectors";
import { makeBreakpointId } from "../../utils/breakpoint";
import { connect } from "../../utils/connect";
Expand All @@ -26,6 +28,8 @@ class Breakpoints extends Component {
editorActions: PropTypes.object,
selectedSource: PropTypes.object,
blackboxedRanges: PropTypes.object,
isSelectedSourceOnIgnoreList: PropTypes.bool,
blackboxedRangesForSelectedSource: PropTypes.array,
};
}
render() {
Expand All @@ -36,7 +40,8 @@ class Breakpoints extends Component {
editor,
breakpointActions,
editorActions,
blackboxedRanges,
blackboxedRangesForSelectedSource,
isSelectedSourceOnIgnoreList,
} = this.props;

if (!selectedSource || !breakpoints) {
Expand All @@ -53,8 +58,9 @@ class Breakpoints extends Component {
breakpoint={bp}
selectedSource={selectedSource}
blackboxedRangesForSelectedSource={
blackboxedRanges[selectedSource.url]
blackboxedRangesForSelectedSource
}
isSelectedSourceOnIgnoreList={isSelectedSourceOnIgnoreList}
editor={editor}
breakpointActions={breakpointActions}
editorActions={editorActions}
Expand All @@ -67,13 +73,22 @@ class Breakpoints extends Component {
}

export default connect(
state => ({
// Retrieves only the first breakpoint per line so that the
// breakpoint marker represents only the first breakpoint
breakpoints: getFirstVisibleBreakpoints(state),
selectedSource: getSelectedSource(state),
blackboxedRanges: getBlackBoxRanges(state),
}),
state => {
const selectedSource = getSelectedSource(state);
const blackboxedRanges = getBlackBoxRanges(state);
return {
// Retrieves only the first breakpoint per line so that the
// breakpoint marker represents only the first breakpoint
breakpoints: getFirstVisibleBreakpoints(state),
selectedSource,
blackboxedRangesForSelectedSource:
selectedSource && blackboxedRanges[selectedSource.url],
isSelectedSourceOnIgnoreList:
selectedSource &&
isSourceMapIgnoreListEnabled(state) &&
isSourceOnSourceMapIgnoreList(state, selectedSource),
};
},
dispatch => ({
breakpointActions: breakpointItemActions(dispatch),
editorActions: editorItemActions(dispatch),
Expand Down
8 changes: 8 additions & 0 deletions devtools/client/debugger/src/components/Editor/EditorMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
getThreadContext,
isSourceWithMap,
getBlackBoxRanges,
isSourceOnSourceMapIgnoreList,
isSourceMapIgnoreListEnabled,
} from "../../selectors";

import { editorMenuItems, editorItemActions } from "./menus/editor";
Expand All @@ -25,6 +27,7 @@ class EditorMenu extends Component {
return {
clearContextMenu: PropTypes.func.isRequired,
contextMenu: PropTypes.object,
isSourceOnIgnoreList: PropTypes.bool,
};
}

Expand All @@ -47,6 +50,7 @@ class EditorMenu extends Component {
isPaused,
editorWrappingEnabled,
contextMenu: event,
isSourceOnIgnoreList,
} = props;

const location = getSourceLocationFromMouseEvent(
Expand All @@ -70,6 +74,7 @@ class EditorMenu extends Component {
selectionText: editor.codeMirror.getSelection().trim(),
isTextSelected: editor.codeMirror.somethingSelected(),
editor,
isSourceOnIgnoreList,
})
);
}
Expand All @@ -93,6 +98,9 @@ const mapStateToProps = (state, props) => {
isSourceWithMap(state, props.selectedSource.id) ||
isPretty(props.selectedSource)) &&
!getPrettySource(state, props.selectedSource.id),
isSourceOnIgnoreList:
isSourceMapIgnoreListEnabled(state) &&
isSourceOnSourceMapIgnoreList(state, props.selectedSource),
};
};

Expand Down

0 comments on commit b735281

Please sign in to comment.