Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit fcce56c

Browse files
committed
Fix previewing generated locations (#5701)
* [Preview] support generated locations * test
1 parent 5b13c51 commit fcce56c

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

src/reducers/ast.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ export function getSourceMetaData(state: OuterState, sourceId: string) {
212212
return state.ast.getIn(["sourceMetaData", sourceId]) || emptySourceMetaData;
213213
}
214214

215+
export function hasSourceMetaData(state: OuterState, sourceId: string) {
216+
return state.ast.hasIn(["sourceMetaData", sourceId]);
217+
}
218+
215219
export function getInScopeLines(state: OuterState) {
216220
return state.ast.get("inScopeLines");
217221
}

src/selectors/isSelectedFrameVisible.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
44

5+
import { originalToGeneratedId, isOriginalId } from "devtools-source-map";
56
import { getSelectedFrame } from "../reducers/pause";
67
import { getSelectedLocation } from "../reducers/sources";
78

9+
function visibleSourceId(location) {
10+
return isOriginalId(location.sourceId)
11+
? originalToGeneratedId(location.sourceId)
12+
: location.sourceId;
13+
}
14+
815
/*
916
* Checks to if the selected frame's source is currently
1017
* selected.
@@ -13,9 +20,12 @@ export function isSelectedFrameVisible(state) {
1320
const selectedLocation = getSelectedLocation(state);
1421
const selectedFrame = getSelectedFrame(state);
1522

23+
if (!selectedFrame || !selectedLocation) {
24+
return false;
25+
}
26+
1627
return (
17-
selectedFrame &&
18-
selectedLocation &&
19-
selectedFrame.location.sourceId == selectedLocation.sourceId
28+
visibleSourceId(selectedLocation) ===
29+
visibleSourceId(selectedFrame.location)
2030
);
2131
}

src/test/mochitest/browser_dbg-preview-source-maps.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ function getCoordsFromPosition(cm, { line, ch }) {
66
}
77

88
function hoverAtPos(dbg, { line, ch }) {
9+
info(`Hovering at (${line}, ${ch})\n`);
910
const cm = getCM(dbg);
1011
const coords = getCoordsFromPosition(cm, { line: line - 1, ch });
1112
const tokenEl = dbg.win.document.elementFromPoint(coords.left, coords.top);
13+
const previewed = waitForDispatch(dbg, "SET_PREVIEW");
1214
tokenEl.dispatchEvent(
1315
new MouseEvent("mouseover", {
1416
bubbles: true,
1517
cancelable: true,
1618
view: dbg.win
1719
})
1820
);
21+
return previewed;
1922
}
2023

2124
function assertTooltip(dbg, { result, expression }) {
@@ -55,9 +58,12 @@ add_task(async function() {
5558
await waitForPaused(dbg);
5659
await waitForSelectedSource(dbg, "times2");
5760

58-
const tooltipPreviewed = waitForDispatch(dbg, "SET_PREVIEW");
59-
hoverAtPos(dbg, { line: 2, ch: 9 });
61+
await hoverAtPos(dbg, { line: 2, ch: 9 });
62+
assertPreviewTooltip(dbg, { result: 4, expression: "x" });
6063

61-
await tooltipPreviewed;
62-
assertTooltip(dbg, { result: 4, expression: "x" });
64+
await dbg.actions.jumpToMappedSelectedLocation();
65+
await waitForSelectedSource(dbg, "bundle.js");
66+
67+
await hoverAtPos(dbg, { line: 70, ch: 10 });
68+
assertPreviewTooltip(dbg, { result: 4, expression: "x" });
6369
});

src/test/mochitest/head.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ function waitForSelectedSource(dbg, url) {
264264
}
265265

266266
// wait for async work to be done
267-
return dbg.selectors.hasSymbols(state, source.toJS());
267+
const hasSymbols = dbg.selectors.hasSymbols(state, source);
268+
const hasSourceMetaData = dbg.selectors.hasSourceMetaData(state, source.id);
269+
return hasSymbols && hasSourceMetaData;
268270
},
269271
"selected source"
270272
);

src/utils/makeRecord.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type Record<T: Object> = {
2222
equals<A>(other: A): boolean,
2323
get<A>(key: $Keys<T>, notSetValue?: any): A,
2424
getIn<A>(keyPath: Array<any>, notSetValue?: any): A,
25+
hasIn<A>(keyPath: Array<any>): boolean,
2526
set<A>(key: $Keys<T>, value: A): Record<T>,
2627
setIn(keyPath: Array<any>, ...iterables: Array<any>): Record<T>,
2728
merge(values: $Shape<T>): Record<T>,

0 commit comments

Comments
 (0)