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

Commit

Permalink
Revert breakpoint clearing (#3113)
Browse files Browse the repository at this point in the history
* Revert breakpoint clearing

* fix breakpoint regression
  • Loading branch information
jasonLaster authored Jun 7, 2017
1 parent 2d4eecc commit cdccd0a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 24 deletions.
60 changes: 42 additions & 18 deletions src/actions/breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ async function _getGeneratedLocation(source, sourceMaps, location) {
return await sourceMaps.getGeneratedLocation(location, source.toJS());
}

async function _formatClientBreakpoint(clientBreakpoint, sourceMaps, location) {
const clientOriginalLocation = await sourceMaps.getOriginalLocation(
clientBreakpoint.actualLocation
);

// make sure that we are re-adding the same type of breakpoint. Column
// or line
const actualLocation = equalizeLocationColumn(
clientOriginalLocation,
location
);

// the generatedLocation might have slid, so now we can adjust it
const generatedLocation = clientBreakpoint.actualLocation;

const { id, hitCount } = clientBreakpoint;
return { id, actualLocation, hitCount, generatedLocation };
}

// we have three forms of syncing: disabled syncing, existing server syncing
// and adding a new breakpoint
async function syncClientBreakpoint(
sourceId: string,
client,
Expand All @@ -62,16 +83,31 @@ async function syncClientBreakpoint(
sourceId: generatedSourceId
};

// early return if breakpoint is disabled with overrides to update
// the id as expected, without talking to server
/** ******* CASE 1: Disabled ***********/
// early return if breakpoint is disabled, send overrides to update
// the id as expected
if (pendingBreakpoint.disabled) {
return {
id: generatedSourceId,
actualLocation: { ...pendingBreakpoint.location, id: sourceId },
oldGeneratedLocation
generatedLocation: oldGeneratedLocation
};
}

/** ******* CASE 2: Merge Server Breakpoint ***********/
// early return if breakpoint exists on the server, send overrides
// to update the id as expected
const existingClient = client.getBreakpointByLocation(oldGeneratedLocation);

if (existingClient) {
return _formatClientBreakpoint(
existingClient,
sourceMaps,
pendingBreakpoint.location
);
}

/** ******* CASE 3: Add New Breakpoint ***********/
// If we are not disabled, set the breakpoint on the server and get
// that info so we can set it on our breakpoints.
const clientBreakpoint = await client.setBreakpoint(
Expand All @@ -80,23 +116,11 @@ async function syncClientBreakpoint(
sourceMaps.isOriginalId(sourceId)
);

// Original location is the location in the src file
const clientOriginalLocation = await sourceMaps.getOriginalLocation(
clientBreakpoint.actualLocation
);

// make sure that we are re-adding the same type of breakpoint. Column
// or line
const actualLocation = equalizeLocationColumn(
clientOriginalLocation,
return _formatClientBreakpoint(
clientBreakpoint,
sourceMaps,
pendingBreakpoint.location
);

// the generatedLocation might have slid, so now we can adjust it
const generatedLocation = clientBreakpoint.actualLocation;

const { id, hitCount } = clientBreakpoint;
return { id, actualLocation, hitCount, generatedLocation };
}

async function addClientBreakpoint(state, client, sourceMaps, breakpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Object {
"id": "bar.js:7:",
"loading": false,
"location": Object {
"column": undefined,
"line": 7,
"sourceId": "bar.js",
"sourceUrl": "http://localhost:8000/examples/bar.js",
Expand Down
2 changes: 2 additions & 0 deletions src/actions/tests/helpers/breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function mockPendingBreakpoint(overrides = {}) {

function generateCorrectingThreadClient(offset = 0) {
return {
getBreakpointByLocation: jest.fn(),
setBreakpoint: (location, condition) => {
const actualLocation = Object.assign({}, location, {
line: location.line + offset
Expand Down Expand Up @@ -60,6 +61,7 @@ export function generateBreakpoint(filename) {
}

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

Expand Down
30 changes: 30 additions & 0 deletions src/client/firefox/commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import _ from "lodash";

import type {
BreakpointId,
Expand Down Expand Up @@ -75,6 +76,34 @@ function sourceContents(sourceId: SourceId): Source {
return sourceClient.source();
}

function getBreakpointByLocation(location: Location) {
const values = _.values(bpClients);
const bpClient = values.find(value => {
const { actor, line, column, condition } = value.location;
return (
location.line === line &&
location.sourceId === actor &&
location.column === column &&
location.condition === condition
);
});

if (bpClient) {
const { actor, url, line, column, condition } = bpClient.location;
return {
id: bpClient.actor,
actualLocation: {
line,
column,
condition,
sourceId: actor,
sourceUrl: url
}
};
}
return null;
}

function setBreakpoint(
location: Location,
condition: boolean,
Expand Down Expand Up @@ -261,6 +290,7 @@ const clientCommands = {
stepOver,
breakOnNext,
sourceContents,
getBreakpointByLocation,
setBreakpoint,
removeBreakpoint,
setBreakpointCondition,
Expand Down
4 changes: 0 additions & 4 deletions src/reducers/breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ function update(
setPendingBreakpoints(newState);
return newState;
}

case "NAVIGATE": {
return initialState();
}
}

return state;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/breakpoint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export function allBreakpointsDisabled(state) {
}

// syncing
export function equalizeLocationColumn(location, hasColumn) {
if (hasColumn) {
export function equalizeLocationColumn(location, referenceLocation) {
if (referenceLocation.column) {
return location;
}
return { ...location, column: undefined };
Expand Down

0 comments on commit cdccd0a

Please sign in to comment.