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

Commit 78ba7d5

Browse files
committed
Send pause points to the server (#5721)
* Send pause points to the server * Update dbg.js
1 parent f64b4a1 commit 78ba7d5

File tree

15 files changed

+96
-49
lines changed

15 files changed

+96
-49
lines changed

src/actions/ast.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function setOutOfScopeLocations() {
9393
}
9494

9595
export function setPausePoints(sourceId: SourceId) {
96-
return async ({ dispatch, getState }: ThunkArgs) => {
96+
return async ({ dispatch, getState, client }: ThunkArgs) => {
9797
const sourceRecord = getSource(getState(), sourceId);
9898
if (!sourceRecord) {
9999
return;
@@ -105,6 +105,8 @@ export function setPausePoints(sourceId: SourceId) {
105105
}
106106

107107
const pausePoints = await getPausePoints(source.id);
108+
await client.setPausePoints(sourceId, pausePoints);
109+
108110
dispatch({
109111
type: "SET_PAUSE_POINTS",
110112
source,

src/actions/tests/ast.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ const threadClient = {
3232
})
3333
);
3434
},
35-
getFrameScopes: function() {
36-
return Promise.resolve({});
37-
},
35+
setPausePoints: async () => {},
36+
getFrameScopes: async () => {},
3837
evaluate: function(expression) {
3938
return new Promise((resolve, reject) =>
4039
resolve({ result: evaluationResult[expression] })

src/actions/tests/helpers/threadClient.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const simpleMockThreadClient = {
3434

3535
setBreakpointCondition: (_id, _location, _condition, _noSliding) =>
3636
Promise.resolve({ sourceId: "a", line: 5 }),
37-
37+
setPausePoints: () => Promise.resolve({}),
3838
sourceContents: sourceId =>
3939
new Promise((resolve, reject) => {
4040
if (sources.includes(sourceId)) {
@@ -85,5 +85,6 @@ export const sourceThreadClient = {
8585
reject(`unknown source: ${sourceId}`);
8686
});
8787
},
88+
threadClient: async () => {},
8889
getFrameScopes: async () => {}
8990
};

src/actions/tests/preview.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ const threadClient = {
1717
})
1818
);
1919
},
20-
getFrameScopes: function() {
21-
return Promise.resolve({});
22-
},
20+
setPausePoints: async () => {},
21+
getFrameScopes: async () => {},
2322
evaluate: function(expression) {
2423
return new Promise((resolve, reject) =>
2524
resolve({ result: evaluationResult[expression] })

src/client/firefox/commands.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import type {
2525
BPClients
2626
} from "./types";
2727

28+
import type { PausePoint } from "../../workers/parser";
29+
2830
import { makePendingLocationId } from "../../utils/breakpoint";
2931

3032
import { createSource, createBreakpointLocation } from "./create";
@@ -52,6 +54,10 @@ function setupCommands(dependencies: Dependencies): { bpClients: BPClients } {
5254
return { bpClients };
5355
}
5456

57+
function sendPacket(packet: Object, callback?: Function) {
58+
debuggerClient.request(packet).then(callback);
59+
}
60+
5561
function resume(): Promise<*> {
5662
return new Promise(resolve => {
5763
threadClient.resume(resolve);
@@ -290,6 +296,10 @@ function disablePrettyPrint(sourceId: SourceId): Promise<*> {
290296
return sourceClient.disablePrettyPrint();
291297
}
292298

299+
async function setPausePoints(sourceId: SourceId, pausePoints: PausePoint[]) {
300+
return sendPacket({ to: sourceId, type: "setPausePoints", pausePoints });
301+
}
302+
293303
function interrupt(): Promise<*> {
294304
return threadClient.interrupt();
295305
}
@@ -352,7 +362,9 @@ const clientCommands = {
352362
prettyPrint,
353363
disablePrettyPrint,
354364
fetchSources,
355-
fetchWorkers
365+
fetchWorkers,
366+
sendPacket,
367+
setPausePoints
356368
};
357369

358370
export { setupCommands, clientCommands };

src/client/firefox/types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ export type DebuggerClient = {
268268
traits: any
269269
},
270270
connect: () => Promise<*>,
271-
listTabs: () => Promise<*>
271+
listTabs: () => Promise<*>,
272+
request: (packet: Object) => Promise<*>
272273
};
273274

274275
export type TabClient = {

src/client/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async function onConnect(
5252
store,
5353
actions,
5454
selectors,
55+
connection,
5556
client: client.clientCommands
5657
});
5758

src/reducers/ast.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import * as I from "immutable";
1414
import makeRecord from "../utils/makeRecord";
1515
import { findEmptyLines } from "../utils/ast";
1616

17-
import type { SymbolDeclarations, AstLocation } from "../workers/parser/types";
17+
import type {
18+
SymbolDeclarations,
19+
AstLocation,
20+
PausePoint
21+
} from "../workers/parser";
1822

1923
import type { Map } from "immutable";
2024
import type { Source } from "../types";
@@ -31,7 +35,7 @@ export type SourceMetaDataType = {
3135
};
3236

3337
export type SourceMetaDataMap = Map<string, SourceMetaDataType>;
34-
export type PausePointsMap = Map<string, any>;
38+
export type PausePointsMap = Map<string, PausePoint>;
3539

3640
export type Preview =
3741
| {| updating: true |}

src/utils/dbg.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { bindActionCreators } from "redux";
22
import * as timings from "./timings";
33
import { prefs, features } from "./prefs";
44
import { isDevelopment } from "devtools-config";
5+
import { formatPausePoints } from "./pause/pausePoints";
56

67
function findSource(dbg, url) {
78
const sources = dbg.selectors.getSources();
@@ -15,9 +16,15 @@ function findSource(dbg, url) {
1516
}
1617

1718
function sendPacket(dbg, packet, callback) {
18-
dbg.connection.tabConnection.debuggerClient
19-
.request(packet)
20-
.then(callback || console.log);
19+
dbg.client.sendPacket(packet, callback || console.log);
20+
}
21+
22+
function sendPacketToThread(dbg, packet, callback) {
23+
sendPacket(
24+
dbg,
25+
{ to: dbg.connection.tabConnection.threadClient.actor, ...packet },
26+
callback
27+
);
2128
}
2229

2330
function evaluate(dbg, expression, callback) {
@@ -37,6 +44,12 @@ function getCM() {
3744
return cm && cm.CodeMirror;
3845
}
3946

47+
function _formatPausePoints(dbg, url) {
48+
const source = dbg.helpers.findSource(url);
49+
const pausePoints = dbg.selectors.getPausePoints(source);
50+
console.log(formatPausePoints(source.text, pausePoints));
51+
}
52+
4053
export function setupHelper(obj) {
4154
const selectors = bindSelectors(obj);
4255
const actions = bindActionCreators(obj.actions, obj.store.dispatch);
@@ -51,7 +64,11 @@ export function setupHelper(obj) {
5164
helpers: {
5265
findSource: url => findSource(dbg, url),
5366
evaluate: (expression, cbk) => evaluate(dbg, expression, cbk),
67+
sendPacketToThread: (packet, cbk) => sendPacketToThread(dbg, packet, cbk),
5468
sendPacket: (packet, cbk) => sendPacket(dbg, packet, cbk)
69+
},
70+
formatters: {
71+
pausePoints: url => _formatPausePoints(dbg, url)
5572
}
5673
};
5774

src/utils/pause/pausePoints.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { reverse, sortBy } from "lodash";
2+
function insertStrtAt(string, index, newString) {
3+
const start = string.slice(0, index);
4+
const end = string.slice(index);
5+
return `${start}${newString}${end}`;
6+
}
7+
8+
export function formatPausePoints(text, nodes) {
9+
nodes = reverse(sortBy(nodes, ["location.line", "location.column"]));
10+
const lines = text.split("\n");
11+
nodes.forEach((node, index) => {
12+
const { line, column } = node.location;
13+
const { breakpoint, stepOver } = node.types;
14+
const num = nodes.length - index;
15+
const types = `${breakpoint ? "b" : ""}${stepOver ? "s" : ""}`;
16+
lines[line - 1] = insertStrtAt(
17+
lines[line - 1],
18+
column,
19+
`/*${types} ${num}*/`
20+
);
21+
});
22+
23+
return lines.join("\n");
24+
}

0 commit comments

Comments
 (0)