Skip to content

Commit b0ceadd

Browse files
bhackett1024jasonLaster
authored andcommitted
Split Source into Source/SourceActor, and Breakpoint into Breakpoint/BreakpointActor (firefox-devtools#7796)
1 parent 98882a9 commit b0ceadd

51 files changed

Lines changed: 709 additions & 453 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/actions/ast/setPausePoints.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// @flow
66

7-
import { getSourceFromId } from "../../selectors";
7+
import { getSourceFromId, getSourceActors } from "../../selectors";
88
import * as parser from "../../workers/parser";
99
import { isGenerated } from "../../utils/source";
1010
import { convertToList } from "../../utils/pause/pausePoints";
@@ -62,7 +62,9 @@ export function setPausePoints(sourceId: SourceId) {
6262

6363
if (isGenerated(source)) {
6464
const compressed = compressPausePoints(pausePoints);
65-
await client.setPausePoints(sourceId, compressed);
65+
for (const sourceActor of getSourceActors(getState(), sourceId)) {
66+
await client.setPausePoints(sourceActor, compressed);
67+
}
6668
}
6769

6870
pausePoints = await mapLocations(

src/actions/breakpoints/addBreakpoint.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ import {
1111
assertBreakpoint,
1212
createBreakpoint,
1313
getASTLocation,
14-
assertLocation
14+
assertLocation,
15+
makeLocationId,
16+
makeSourceActorLocation
1517
} from "../../utils/breakpoint";
1618
import { PROMISE } from "../utils/middleware/promise";
1719
import {
1820
getSource,
21+
getSourceActors,
1922
getSymbols,
2023
getFirstPausePointLocation
2124
} from "../../selectors";
@@ -54,6 +57,12 @@ async function addBreakpointPromise(getState, client, sourceMaps, breakpoint) {
5457

5558
const generatedSource = getSource(state, generatedLocation.sourceId);
5659

60+
if (!generatedSource) {
61+
throw new Error(
62+
`Unable to find generated source: ${generatedLocation.sourceId}`
63+
);
64+
}
65+
5766
assertLocation(location);
5867
assertLocation(generatedLocation);
5968

@@ -63,13 +72,23 @@ async function addBreakpointPromise(getState, client, sourceMaps, breakpoint) {
6372
return { breakpoint: newBreakpoint };
6473
}
6574

66-
const { id, actualLocation } = await client.setBreakpoint(
67-
generatedLocation,
68-
breakpoint.options,
69-
isOriginalId(location.sourceId)
70-
);
75+
const sourceActors = getSourceActors(state, generatedSource.id);
76+
const newGeneratedLocation = { ...generatedLocation };
77+
78+
for (const sourceActor of sourceActors) {
79+
const sourceActorLocation = makeSourceActorLocation(
80+
sourceActor,
81+
generatedLocation
82+
);
83+
const { actualLocation } = await client.setBreakpoint(
84+
sourceActorLocation,
85+
breakpoint.options,
86+
isOriginalId(location.sourceId)
87+
);
88+
newGeneratedLocation.line = actualLocation.line;
89+
newGeneratedLocation.column = actualLocation.column;
90+
}
7191

72-
const newGeneratedLocation = actualLocation || generatedLocation;
7392
const newLocation = await sourceMaps.getOriginalLocation(
7493
newGeneratedLocation
7594
);
@@ -78,10 +97,10 @@ async function addBreakpointPromise(getState, client, sourceMaps, breakpoint) {
7897
const astLocation = await getASTLocation(source, symbols, newLocation);
7998

8099
const originalText = getTextAtPosition(source, location);
81-
const text = getTextAtPosition(generatedSource, actualLocation);
100+
const text = getTextAtPosition(generatedSource, newGeneratedLocation);
82101

83102
const newBreakpoint = {
84-
id,
103+
id: makeLocationId(generatedLocation),
85104
disabled: false,
86105
loading: false,
87106
options: breakpoint.options,

src/actions/breakpoints/index.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ import {
1717
getSelectedSource,
1818
getBreakpointAtLocation,
1919
getConditionalPanelLocation,
20-
getBreakpointsForSource
20+
getBreakpointsForSource,
21+
getSourceActors
2122
} from "../../selectors";
22-
import { assertBreakpoint, createXHRBreakpoint } from "../../utils/breakpoint";
23+
import {
24+
assertBreakpoint,
25+
createXHRBreakpoint,
26+
makeSourceActorLocation
27+
} from "../../utils/breakpoint";
2328
import {
2429
addBreakpoint,
2530
addHiddenBreakpoint,
@@ -43,6 +48,22 @@ import type {
4348

4449
import { recordEvent } from "../../utils/telemetry";
4550

51+
async function removeBreakpointsPromise(client, state, breakpoint) {
52+
const sourceActors = getSourceActors(
53+
state,
54+
breakpoint.generatedLocation.sourceId
55+
);
56+
for (const sourceActor of sourceActors) {
57+
const sourceActorLocation = makeSourceActorLocation(
58+
sourceActor,
59+
breakpoint.generatedLocation
60+
);
61+
if (client.getBreakpointByLocation(sourceActorLocation)) {
62+
await client.removeBreakpoint(sourceActorLocation);
63+
}
64+
}
65+
}
66+
4667
/**
4768
* Remove a single breakpoint
4869
*
@@ -70,7 +91,7 @@ export function removeBreakpoint(breakpoint: Breakpoint) {
7091
type: "REMOVE_BREAKPOINT",
7192
breakpoint,
7293
disabled: false,
73-
[PROMISE]: client.removeBreakpoint(breakpoint.generatedLocation)
94+
[PROMISE]: removeBreakpointsPromise(client, getState(), breakpoint)
7495
});
7596
};
7697
}
@@ -87,7 +108,8 @@ export function disableBreakpoint(breakpoint: Breakpoint) {
87108
return;
88109
}
89110

90-
await client.removeBreakpoint(breakpoint.generatedLocation);
111+
await removeBreakpointsPromise(client, getState(), breakpoint);
112+
91113
const newBreakpoint: Breakpoint = { ...breakpoint, disabled: true };
92114

93115
return dispatch(
@@ -144,7 +166,7 @@ export function toggleAllBreakpoints(shouldDisableBreakpoints: boolean) {
144166

145167
for (const breakpoint of breakpoints) {
146168
if (shouldDisableBreakpoints) {
147-
await client.removeBreakpoint(breakpoint.generatedLocation);
169+
await removeBreakpointsPromise(client, getState(), breakpoint);
148170
const newBreakpoint: Breakpoint = { ...breakpoint, disabled: true };
149171
modifiedBreakpoints.push(newBreakpoint);
150172
} else {
@@ -282,7 +304,19 @@ export function setBreakpointOptions(
282304
await dispatch(enableBreakpoint(bp));
283305
}
284306

285-
await client.setBreakpointOptions(bp.id, location, options);
307+
const sourceActors = getSourceActors(
308+
getState(),
309+
bp.generatedLocation.sourceId
310+
);
311+
for (const sourceActor of sourceActors) {
312+
const sourceActorLocation = makeSourceActorLocation(
313+
sourceActor,
314+
bp.generatedLocation
315+
);
316+
if (client.getBreakpointByLocation(sourceActorLocation)) {
317+
await client.setBreakpointOptions(sourceActorLocation, options);
318+
}
319+
}
286320

287321
const newBreakpoint = { ...bp, disabled: false, options };
288322

src/actions/breakpoints/syncBreakpoint.js

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import {
88
createBreakpoint,
99
assertBreakpoint,
1010
assertPendingBreakpoint,
11-
findScopeByName
11+
findScopeByName,
12+
makeSourceActorLocation
1213
} from "../../utils/breakpoint";
1314

1415
import { getGeneratedLocation } from "../../utils/source-maps";
1516
import { getTextAtPosition } from "../../utils/source";
1617
import { originalToGeneratedId, isOriginalId } from "devtools-source-map";
17-
import { getSource } from "../../selectors";
18+
import { getSource, getSourceActors } from "../../selectors";
1819
import type { ThunkArgs, Action } from "../types";
1920

2021
import type {
@@ -49,7 +50,6 @@ async function makeScopedLocation(
4950
}
5051

5152
function createSyncData(
52-
id: SourceId,
5353
pendingBreakpoint: PendingBreakpoint,
5454
location: SourceLocation,
5555
generatedLocation: SourceLocation,
@@ -60,7 +60,6 @@ function createSyncData(
6060
const overrides = {
6161
...pendingBreakpoint,
6262
generatedLocation,
63-
id,
6463
text,
6564
originalText
6665
};
@@ -121,18 +120,32 @@ export async function syncBreakpointPromise(
121120
scopedGeneratedLocation
122121
);
123122

124-
const existingClient = client.getBreakpointByLocation(generatedLocation);
123+
const sourceActors = getSourceActors(getState(), sourceId);
125124

126125
/** ******* CASE 1: No server change ***********/
127126
// early return if breakpoint is disabled or we are in the sameLocation
128-
// send update only to redux
129-
if (pendingBreakpoint.disabled || (existingClient && isSameLocation)) {
130-
const id = pendingBreakpoint.disabled ? "" : existingClient.id;
127+
if (pendingBreakpoint.disabled || isSameLocation) {
128+
// Make sure the breakpoint is installed on all source actors.
129+
if (!pendingBreakpoint.disabled) {
130+
for (const sourceActor of sourceActors) {
131+
const sourceActorLocation = makeSourceActorLocation(
132+
sourceActor,
133+
generatedLocation
134+
);
135+
if (!client.getBreakpointByLocation(sourceActorLocation)) {
136+
await client.setBreakpoint(
137+
sourceActorLocation,
138+
pendingBreakpoint.options,
139+
isOriginalId(sourceId)
140+
);
141+
}
142+
}
143+
}
144+
131145
const originalText = getTextAtPosition(source, previousLocation);
132146
const text = getTextAtPosition(generatedSource, generatedLocation);
133147

134148
return createSyncData(
135-
id,
136149
pendingBreakpoint,
137150
scopedLocation,
138151
scopedGeneratedLocation,
@@ -143,8 +156,14 @@ export async function syncBreakpointPromise(
143156
}
144157

145158
// clear server breakpoints if they exist and we have moved
146-
if (existingClient) {
147-
await client.removeBreakpoint(generatedLocation);
159+
for (const sourceActor of sourceActors) {
160+
const sourceActorLocation = makeSourceActorLocation(
161+
sourceActor,
162+
generatedLocation
163+
);
164+
if (client.getBreakpointByLocation(sourceActorLocation)) {
165+
await client.removeBreakpoint(sourceActorLocation);
166+
}
148167
}
149168

150169
/** ******* Case 2: Add New Breakpoint ***********/
@@ -155,15 +174,23 @@ export async function syncBreakpointPromise(
155174
return { previousLocation, breakpoint: null };
156175
}
157176

158-
const { id, actualLocation } = await client.setBreakpoint(
159-
scopedGeneratedLocation,
160-
isOriginalId(sourceId),
161-
pendingBreakpoint.options
162-
);
177+
const newGeneratedLocation = { ...scopedGeneratedLocation };
178+
for (const sourceActor of sourceActors) {
179+
const sourceActorLocation = makeSourceActorLocation(
180+
sourceActor,
181+
scopedGeneratedLocation
182+
);
183+
const { actualLocation } = await client.setBreakpoint(
184+
sourceActorLocation,
185+
pendingBreakpoint.options,
186+
isOriginalId(sourceId)
187+
);
188+
newGeneratedLocation.line = actualLocation.line;
189+
newGeneratedLocation.column = actualLocation.column;
190+
}
163191

164192
// the breakpoint might have slid server side, so we want to get the location
165193
// based on the server's return value
166-
const newGeneratedLocation = actualLocation;
167194
const newLocation = await sourceMaps.getOriginalLocation(
168195
newGeneratedLocation
169196
);
@@ -172,7 +199,6 @@ export async function syncBreakpointPromise(
172199
const text = getTextAtPosition(generatedSource, newGeneratedLocation);
173200

174201
return createSyncData(
175-
id,
176202
pendingBreakpoint,
177203
newLocation,
178204
newGeneratedLocation,

src/actions/breakpoints/tests/__snapshots__/breakpoints.spec.js.snap

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Object {
1313
},
1414
"disabled": false,
1515
"generatedLocation": Object {
16+
"column": undefined,
1617
"line": 7,
1718
"sourceId": "a",
1819
"sourceUrl": "http://localhost:8000/examples/a",
@@ -50,11 +51,12 @@ Array [
5051
},
5152
"disabled": false,
5253
"generatedLocation": Object {
54+
"column": undefined,
5355
"line": 2,
5456
"sourceId": "a",
5557
"sourceUrl": "http://localhost:8000/examples/a",
5658
},
57-
"id": "hi",
59+
"id": "a:2:",
5860
"loading": false,
5961
"location": Object {
6062
"line": 2,
@@ -104,11 +106,12 @@ Object {
104106
},
105107
"disabled": false,
106108
"generatedLocation": Object {
109+
"column": undefined,
107110
"line": 1,
108111
"sourceId": "a.js",
109112
"sourceUrl": "http://localhost:8000/examples/a.js",
110113
},
111-
"id": "hi",
114+
"id": "a.js:1:",
112115
"loading": false,
113116
"location": Object {
114117
"column": 0,
@@ -142,11 +145,12 @@ Array [
142145
},
143146
"disabled": true,
144147
"generatedLocation": Object {
148+
"column": undefined,
145149
"line": 5,
146150
"sourceId": "a",
147151
"sourceUrl": "http://localhost:8000/examples/a",
148152
},
149-
"id": "hi",
153+
"id": "a:5:",
150154
"loading": false,
151155
"location": Object {
152156
"line": 5,

src/actions/breakpoints/tests/__snapshots__/syncing.spec.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Object {
1616
"sourceId": "gen.js",
1717
"sourceUrl": "http://localhost:8000/gen.js",
1818
},
19-
"id": "foo",
19+
"id": "magic.js:3:",
2020
"loading": false,
2121
"location": Object {
2222
"column": undefined,
@@ -57,7 +57,7 @@ Object {
5757
"sourceId": "gen.js",
5858
"sourceUrl": "http://localhost:8000/gen.js",
5959
},
60-
"id": "foo",
60+
"id": "magic.js:12:",
6161
"loading": false,
6262
"location": Object {
6363
"column": undefined,
@@ -127,7 +127,7 @@ Object {
127127
"sourceId": "gen.js",
128128
"sourceUrl": "http://localhost:8000/gen.js",
129129
},
130-
"id": "foo",
130+
"id": "magic.js:3:",
131131
"loading": false,
132132
"location": Object {
133133
"column": undefined,
@@ -168,7 +168,7 @@ Object {
168168
"sourceId": "gen.js",
169169
"sourceUrl": "http://localhost:8000/gen.js",
170170
},
171-
"id": "gen.js:5:",
171+
"id": "magic.js:3:",
172172
"loading": false,
173173
"location": Object {
174174
"column": undefined,

0 commit comments

Comments
 (0)