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

Commit df4b1f6

Browse files
committed
tweak pause points (#5771)
1 parent ea7cfe3 commit df4b1f6

File tree

3 files changed

+58
-41
lines changed

3 files changed

+58
-41
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
global:
1111
- DISPLAY=':99.0'
1212
- YARN_VERSION='0.24.5'
13-
- MC_COMMIT='0b997836c7cf' # https://hg.mozilla.org/mozilla-central/shortlog
13+
- MC_COMMIT='5bc910c1f477' # https://hg.mozilla.org/mozilla-central/shortlog
1414

1515
notifications:
1616
slack:

src/test/mochitest/browser_dbg-sourcemaps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ add_task(async function() {
6363

6464
// Test breaking on a breakpoint
6565
await addBreakpoint(dbg, "entry.js", 15);
66-
is(getBreakpoints(getState()).size, 2, "Two breakpoints exist");
66+
is(getBreakpoints(getState()).size, 1, "One breakpoint exists");
6767
assertBreakpointExists(dbg, entrySrc, 15);
6868

6969
invokeInTab("keepMeAlive");

src/workers/parser/pausePoints.js

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
4+
5+
// @flow
6+
17
import { traverseAst } from "./utils/ast";
28
import * as t from "@babel/types";
39

10+
import type { AstLocation } from "./types";
11+
import type { BabelNode } from "@babel/types";
12+
import type { SimplePath } from "./utils/simple-path";
13+
14+
export type PausePoint = {|
15+
location: AstLocation,
16+
types: {| breakpoint: boolean, stepOver: boolean |}
17+
|};
18+
19+
export type PausePoints = PausePoint[];
20+
421
const isControlFlow = node =>
522
t.isForStatement(node) || t.isWhileStatement(node) || t.isIfStatement(node);
623

@@ -15,69 +32,69 @@ const inExpression = parent =>
1532
t.isCallExpression(parent.node) ||
1633
t.isTemplateLiteral(parent.node);
1734

18-
export function getPausePoints(sourceId) {
35+
export function getPausePoints(sourceId: string) {
1936
const state = [];
2037
traverseAst(sourceId, { enter: onEnter }, state);
2138
return state;
2239
}
2340

24-
function formatNode(location, types) {
25-
return { location, types };
26-
}
27-
28-
function onEnter(node, ancestors, state) {
41+
function onEnter(node: BabelNode, ancestors: SimplePath[], state) {
2942
const parent = ancestors[ancestors.length - 1];
3043

31-
if (isAssignment(node) || isImport(node) || isControlFlow(node)) {
32-
state.push(
33-
formatNode(node.loc.start, { breakpoint: true, stepOver: true })
34-
);
44+
if (
45+
isAssignment(node) ||
46+
isImport(node) ||
47+
isControlFlow(node) ||
48+
t.isDebuggerStatement(node)
49+
) {
50+
addPoint(state, node.loc.start);
3551
}
3652

3753
if (isReturn(node)) {
3854
if (t.isCallExpression(node.argument)) {
39-
state.push(
40-
formatNode(node.loc.start, { breakpoint: false, stepOver: false })
41-
);
55+
addEmptyPoint(state, node.loc.start);
4256
} else {
43-
state.push(
44-
formatNode(node.loc.start, { breakpoint: true, stepOver: true })
45-
);
57+
addPoint(state, node.loc.start);
4658
}
4759
}
4860

4961
if (t.isCallExpression(node)) {
50-
state.push(
51-
formatNode(node.loc.start, {
52-
breakpoint: true,
53-
54-
// NOTE: we do not want to land inside an expression e.g. [], {}, call
55-
stepOver: !inExpression(parent)
56-
})
57-
);
58-
}
62+
addPoint(state, node.loc.start, {
63+
breakpoint: true,
5964

60-
if (t.isDebuggerStatement(node)) {
61-
state.push(
62-
formatNode(node.loc.start, { breakpoint: true, stepOver: true })
63-
);
65+
// NOTE: we do not want to land inside an expression e.g. [], {}, call
66+
stepOver: !inExpression(parent)
67+
});
6468
}
6569

6670
if (t.isFunction(node)) {
6771
const { line, column } = node.loc.end;
68-
state.push(formatNode(node.loc.start, { breakpoint: true }));
69-
state.push(
70-
formatNode(
71-
{ line, column: column - 1 },
72-
{ breakpoint: true, stepOver: true }
73-
)
74-
);
72+
addBreakPoint(state, node.loc.start);
73+
addPoint(state, { line, column: column - 1 });
7574
}
7675

7776
if (t.isProgram(node)) {
7877
const lastStatement = node.body[node.body.length - 1];
79-
state.push(
80-
formatNode(lastStatement.loc.end, { breakpoint: true, stepOver: true })
81-
);
78+
addPoint(state, lastStatement.loc.end);
8279
}
8380
}
81+
82+
function formatNode(location, types) {
83+
return { location, types };
84+
}
85+
86+
function addPoint(
87+
state,
88+
location,
89+
types = { breakpoint: true, stepOver: true }
90+
) {
91+
state.push(formatNode(location, types));
92+
}
93+
94+
function addEmptyPoint(state, location) {
95+
addPoint(state, location, { breakpoint: false, stepOver: false });
96+
}
97+
98+
function addBreakPoint(state, location) {
99+
addPoint(state, location, { breakpoint: true, stepOver: false });
100+
}

0 commit comments

Comments
 (0)