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

Commit fa58a03

Browse files
committed
Revert "Revert "Improve Breakpoint Syncing (#5160)"" (#5230)
This reverts commit f253328.
1 parent 6d9bb9c commit fa58a03

22 files changed

+491
-15
lines changed

src/actions/breakpoints/syncBreakpoint.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import type {
2323
} from "debugger-html";
2424

2525
type BreakpointSyncData = {
26-
previousLocation: Location | null,
27-
breakpoint: Breakpoint
26+
previousLocation: Location,
27+
breakpoint: ?Breakpoint
2828
};
2929

3030
async function makeScopedLocation(
@@ -50,7 +50,7 @@ function createSyncData(
5050
pendingBreakpoint: PendingBreakpoint,
5151
location: Location,
5252
generatedLocation: Location,
53-
previousLocation: Location | null = null
53+
previousLocation: Location
5454
): BreakpointSyncData {
5555
const overrides = { ...pendingBreakpoint, generatedLocation, id };
5656
const breakpoint = createBreakpoint(location, overrides);
@@ -127,6 +127,11 @@ export async function syncClientBreakpoint(
127127
/** ******* Case 2: Add New Breakpoint ***********/
128128
// If we are not disabled, set the breakpoint on the server and get
129129
// that info so we can set it on our breakpoints.
130+
131+
if (!scopedGeneratedLocation.line) {
132+
return { previousLocation, breakpoint: null };
133+
}
134+
130135
const { id, actualLocation } = await client.setBreakpoint(
131136
scopedGeneratedLocation,
132137
pendingBreakpoint.condition,

src/reducers/breakpoints.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,16 @@ function addBreakpoint(state, action) {
9494

9595
function syncBreakpoint(state, data) {
9696
const { breakpoint, previousLocation } = data;
97-
const locationId = makeLocationId(breakpoint.location);
9897

9998
if (previousLocation) {
100-
return state
101-
.deleteIn(["breakpoints", makeLocationId(previousLocation)])
102-
.setIn(["breakpoints", locationId], breakpoint);
99+
state = state.deleteIn(["breakpoints", makeLocationId(previousLocation)]);
100+
}
101+
102+
if (!breakpoint) {
103+
return state;
103104
}
104105

106+
const locationId = makeLocationId(breakpoint.location);
105107
return state.setIn(["breakpoints", locationId], breakpoint);
106108
}
107109

src/reducers/pending-breakpoints.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,21 @@ function addBreakpoint(state, action) {
9090

9191
function syncBreakpoint(state, action) {
9292
const { breakpoint, previousLocation } = action;
93-
const locationId = makePendingLocationId(breakpoint.location);
94-
const pendingBreakpoint = createPendingBreakpoint(breakpoint);
9593

9694
if (previousLocation) {
97-
return state
98-
.deleteIn(["pendingBreakpoints", makePendingLocationId(previousLocation)])
99-
.setIn(["pendingBreakpoints", locationId], pendingBreakpoint);
95+
state = state.deleteIn([
96+
"pendingBreakpoints",
97+
makePendingLocationId(previousLocation)
98+
]);
99+
}
100+
101+
if (!breakpoint) {
102+
return state;
100103
}
101104

105+
const locationId = makePendingLocationId(breakpoint.location);
106+
const pendingBreakpoint = createPendingBreakpoint(breakpoint);
107+
102108
return state.setIn(["pendingBreakpoints", locationId], pendingBreakpoint);
103109
}
104110

src/test/mochitest/browser.ini

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ support-files =
1515
examples/sourcemaps3/bundle.js.map
1616
examples/sourcemaps3/sorted.js
1717
examples/sourcemaps3/test.js
18+
examples/sourcemaps-reload/v1.bundle.js
19+
examples/sourcemaps-reload/v1.bundle.js.map
20+
examples/sourcemaps-reload/v2.bundle.js
21+
examples/sourcemaps-reload/v2.bundle.js.map
22+
examples/sourcemaps-reload/v3.bundle.js
23+
examples/sourcemaps-reload/v3.bundle.js.map
24+
examples/sourcemaps-reload/doc-sourcemaps-reload.html
25+
examples/sourcemaps-reload/sjs_code_reload.sjs
1826
examples/wasm-sourcemaps/average.js
1927
examples/wasm-sourcemaps/average.wasm
2028
examples/wasm-sourcemaps/average.wasm.map
@@ -25,7 +33,8 @@ support-files =
2533
examples/sum/sum.min.js.map
2634
examples/reload/code_reload_1.js
2735
examples/reload/code_reload_2.js
28-
examples/reload/doc_reload.html
36+
examples/reload/doc-reload.html
37+
examples/reload/sjs_code_reload.sjs
2938
examples/doc-async.html
3039
examples/doc-asm.html
3140
examples/doc-content-script-sources.html
@@ -63,7 +72,6 @@ support-files =
6372
examples/script-switching-02.js
6473
examples/script-switching-01.js
6574
examples/times2.js
66-
examples/reload/sjs_code_reload.sjs
6775

6876
[browser_dbg-asm.js]
6977
[browser_dbg-async-stepping.js]
@@ -115,6 +123,7 @@ skip-if = os == "win" # Bug 1393121
115123
skip-if = true # regular failures during release in Bug 1415300
116124
[browser_dbg-search-project.js]
117125
[browser_dbg-sourcemaps.js]
126+
[browser_dbg-sourcemaps-reload.js]
118127
[browser_dbg-sourcemaps-reloading.js]
119128
[browser_dbg-sourcemaps2.js]
120129
[browser_dbg-sourcemaps3.js]

src/test/mochitest/browser_dbg-reload.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ async function waitForBreakpoint(dbg, location) {
1818
}
1919

2020
add_task(async function() {
21-
const dbg = await initDebugger("reload/doc_reload.html", "sjs_code_reload");
21+
22+
const dbg = await initDebugger("reload/doc-reload.html");
23+
await waitForSource(dbg, "sjs_code_reload");
2224

2325
await selectSource(dbg, "sjs_code_reload");
2426
await waitForSelectedSource(dbg, "sjs_code_reload");
27+
2528
await addBreakpoint(dbg, "sjs_code_reload", 2);
2629

2730
await reload(dbg, "sjs_code_reload");
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
/*
5+
* Test reloading:
6+
* 1. reload the source
7+
* 2. re-sync breakpoints
8+
*/
9+
10+
async function waitForBreakpoint(dbg, location) {
11+
return waitForState(
12+
dbg,
13+
state => {
14+
return dbg.selectors.getBreakpoint(dbg.getState(), location);
15+
},
16+
"Waiting for breakpoint"
17+
);
18+
}
19+
20+
function getBreakpoints(dbg) {
21+
const breakpoints = dbg.selectors.getBreakpoints(dbg.getState());
22+
return breakpoints.valueSeq().toJS();
23+
}
24+
25+
add_task(async function() {
26+
const dbg = await initDebugger("doc-minified.html");
27+
28+
await navigate(dbg, "sourcemaps-reload/doc-sourcemaps-reload.html", "v1");
29+
30+
await waitForSource(dbg, "v1");
31+
await selectSource(dbg, "v1");
32+
33+
await addBreakpoint(dbg, "v1", 6);
34+
let breakpoint = getBreakpoints(dbg)[0];
35+
is(breakpoint.location.line, 6);
36+
37+
let syncBp = waitForDispatch(dbg, "SYNC_BREAKPOINT");
38+
await reload(dbg);
39+
40+
await waitForPaused(dbg);
41+
await syncBp;
42+
assertDebugLine(dbg, 72);
43+
breakpoint = getBreakpoints(dbg)[0];
44+
45+
is(breakpoint.location.line, 9);
46+
is(breakpoint.generatedLocation.line, 73);
47+
48+
await resume(dbg);
49+
syncBp = waitForDispatch(dbg, "SYNC_BREAKPOINT", 2);
50+
await selectSource(dbg, "v1");
51+
await addBreakpoint(dbg, "v1", 13);
52+
53+
await reload(dbg);
54+
await waitForSource(dbg, "v1");
55+
await syncBp;
56+
await waitForSelectedSource(dbg, "v1");
57+
58+
is(getBreakpoints(dbg).length, 0, "No breakpoints");
59+
});
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["transform-async-to-generator"]
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Steps to Rebuild
2+
3+
1. make changes to v1.js, v2.js, v3.js
4+
2. run `yarn` to install webpack & babel
5+
3. run `webpack`
6+
4. change `sources` reference in `v2.bundle.js.map` to `v1.js`
7+
5. change `sources` reference in `v3.bundle.js.map` to `v1.js`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- Any copyright is dedicated to the Public Domain.
2+
http://creativecommons.org/publicdomain/zero/1.0/ -->
3+
<!doctype html>
4+
5+
<html>
6+
<script src="sjs_code_reload.sjs?foo"></script>
7+
<head>
8+
<meta charset="utf-8"/>
9+
<title>Empty test page 1</title>
10+
</head>
11+
12+
<body>
13+
</body>
14+
15+
</html>

0 commit comments

Comments
 (0)