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

Commit cdccd0a

Browse files
authored
Revert breakpoint clearing (#3113)
* Revert breakpoint clearing * fix breakpoint regression
1 parent 2d4eecc commit cdccd0a

File tree

6 files changed

+77
-24
lines changed

6 files changed

+77
-24
lines changed

src/actions/breakpoints.js

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ async function _getGeneratedLocation(source, sourceMaps, location) {
4545
return await sourceMaps.getGeneratedLocation(location, source.toJS());
4646
}
4747

48+
async function _formatClientBreakpoint(clientBreakpoint, sourceMaps, location) {
49+
const clientOriginalLocation = await sourceMaps.getOriginalLocation(
50+
clientBreakpoint.actualLocation
51+
);
52+
53+
// make sure that we are re-adding the same type of breakpoint. Column
54+
// or line
55+
const actualLocation = equalizeLocationColumn(
56+
clientOriginalLocation,
57+
location
58+
);
59+
60+
// the generatedLocation might have slid, so now we can adjust it
61+
const generatedLocation = clientBreakpoint.actualLocation;
62+
63+
const { id, hitCount } = clientBreakpoint;
64+
return { id, actualLocation, hitCount, generatedLocation };
65+
}
66+
67+
// we have three forms of syncing: disabled syncing, existing server syncing
68+
// and adding a new breakpoint
4869
async function syncClientBreakpoint(
4970
sourceId: string,
5071
client,
@@ -62,16 +83,31 @@ async function syncClientBreakpoint(
6283
sourceId: generatedSourceId
6384
};
6485

65-
// early return if breakpoint is disabled with overrides to update
66-
// the id as expected, without talking to server
86+
/** ******* CASE 1: Disabled ***********/
87+
// early return if breakpoint is disabled, send overrides to update
88+
// the id as expected
6789
if (pendingBreakpoint.disabled) {
6890
return {
6991
id: generatedSourceId,
7092
actualLocation: { ...pendingBreakpoint.location, id: sourceId },
71-
oldGeneratedLocation
93+
generatedLocation: oldGeneratedLocation
7294
};
7395
}
7496

97+
/** ******* CASE 2: Merge Server Breakpoint ***********/
98+
// early return if breakpoint exists on the server, send overrides
99+
// to update the id as expected
100+
const existingClient = client.getBreakpointByLocation(oldGeneratedLocation);
101+
102+
if (existingClient) {
103+
return _formatClientBreakpoint(
104+
existingClient,
105+
sourceMaps,
106+
pendingBreakpoint.location
107+
);
108+
}
109+
110+
/** ******* CASE 3: Add New Breakpoint ***********/
75111
// If we are not disabled, set the breakpoint on the server and get
76112
// that info so we can set it on our breakpoints.
77113
const clientBreakpoint = await client.setBreakpoint(
@@ -80,23 +116,11 @@ async function syncClientBreakpoint(
80116
sourceMaps.isOriginalId(sourceId)
81117
);
82118

83-
// Original location is the location in the src file
84-
const clientOriginalLocation = await sourceMaps.getOriginalLocation(
85-
clientBreakpoint.actualLocation
86-
);
87-
88-
// make sure that we are re-adding the same type of breakpoint. Column
89-
// or line
90-
const actualLocation = equalizeLocationColumn(
91-
clientOriginalLocation,
119+
return _formatClientBreakpoint(
120+
clientBreakpoint,
121+
sourceMaps,
92122
pendingBreakpoint.location
93123
);
94-
95-
// the generatedLocation might have slid, so now we can adjust it
96-
const generatedLocation = clientBreakpoint.actualLocation;
97-
98-
const { id, hitCount } = clientBreakpoint;
99-
return { id, actualLocation, hitCount, generatedLocation };
100124
}
101125

102126
async function addClientBreakpoint(state, client, sourceMaps, breakpoint) {

src/actions/tests/__snapshots__/pending-breakpoints.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Object {
1313
"id": "bar.js:7:",
1414
"loading": false,
1515
"location": Object {
16+
"column": undefined,
1617
"line": 7,
1718
"sourceId": "bar.js",
1819
"sourceUrl": "http://localhost:8000/examples/bar.js",

src/actions/tests/helpers/breakpoints.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function mockPendingBreakpoint(overrides = {}) {
2121

2222
function generateCorrectingThreadClient(offset = 0) {
2323
return {
24+
getBreakpointByLocation: jest.fn(),
2425
setBreakpoint: (location, condition) => {
2526
const actualLocation = Object.assign({}, location, {
2627
line: location.line + offset
@@ -60,6 +61,7 @@ export function generateBreakpoint(filename) {
6061
}
6162

6263
export const simpleMockThreadClient = {
64+
getBreakpointByLocation: jest.fn(),
6365
setBreakpoint: (location, _condition) =>
6466
Promise.resolve({ id: "hi", actualLocation: location }),
6567

src/client/firefox/commands.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @flow
2+
import _ from "lodash";
23

34
import type {
45
BreakpointId,
@@ -75,6 +76,34 @@ function sourceContents(sourceId: SourceId): Source {
7576
return sourceClient.source();
7677
}
7778

79+
function getBreakpointByLocation(location: Location) {
80+
const values = _.values(bpClients);
81+
const bpClient = values.find(value => {
82+
const { actor, line, column, condition } = value.location;
83+
return (
84+
location.line === line &&
85+
location.sourceId === actor &&
86+
location.column === column &&
87+
location.condition === condition
88+
);
89+
});
90+
91+
if (bpClient) {
92+
const { actor, url, line, column, condition } = bpClient.location;
93+
return {
94+
id: bpClient.actor,
95+
actualLocation: {
96+
line,
97+
column,
98+
condition,
99+
sourceId: actor,
100+
sourceUrl: url
101+
}
102+
};
103+
}
104+
return null;
105+
}
106+
78107
function setBreakpoint(
79108
location: Location,
80109
condition: boolean,
@@ -261,6 +290,7 @@ const clientCommands = {
261290
stepOver,
262291
breakOnNext,
263292
sourceContents,
293+
getBreakpointByLocation,
264294
setBreakpoint,
265295
removeBreakpoint,
266296
setBreakpointCondition,

src/reducers/breakpoints.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ function update(
9090
setPendingBreakpoints(newState);
9191
return newState;
9292
}
93-
94-
case "NAVIGATE": {
95-
return initialState();
96-
}
9793
}
9894

9995
return state;

src/utils/breakpoint/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export function allBreakpointsDisabled(state) {
3434
}
3535

3636
// syncing
37-
export function equalizeLocationColumn(location, hasColumn) {
38-
if (hasColumn) {
37+
export function equalizeLocationColumn(location, referenceLocation) {
38+
if (referenceLocation.column) {
3939
return location;
4040
}
4141
return { ...location, column: undefined };

0 commit comments

Comments
 (0)