1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Check that we continue stepping when a single original source's line
* corresponds to multiple generated js lines.
*/
var gDebuggee;
var gClient;
var gThreadClient;
const {SourceNode} = require("source-map");
function run_test() {
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-source-map");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect().then(function () {
attachTestTabAndResume(gClient, "test-source-map", function (aResponse, aTabClient, aThreadClient) {
gThreadClient = aThreadClient;
define_code();
});
});
do_test_pending();
}
function define_code() {
let { code, map } = (new SourceNode(null, null, null, [
new SourceNode(1, 0, "a.js", "function runTest() {\n"),
// A bunch of js lines map to the same original source line.
new SourceNode(2, 0, "a.js", " debugger;\n"),
new SourceNode(2, 0, "a.js", " var sum = 0;\n"),
new SourceNode(2, 0, "a.js", " for (var i = 0; i < 5; i++) {\n"),
new SourceNode(2, 0, "a.js", " sum += i;\n"),
new SourceNode(2, 0, "a.js", " }\n"),
// And now we have a new line in the original source that we should stop at.
new SourceNode(3, 0, "a.js", " sum;\n"),
new SourceNode(3, 0, "a.js", "}\n"),
])).toStringWithSourceMap({
file: "abc.js",
sourceRoot: "http://example.com/"
});
code += "//# sourceMappingURL=data:text/json," + map.toString();
Components.utils.evalInSandbox(code, gDebuggee, "1.8",
"http://example.com/abc.js", 1);
run_code();
}
function run_code() {
gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
do_check_eq(aPacket.why.type, "debuggerStatement");
step_in();
});
gDebuggee.runTest();
}
function step_in() {
gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
do_check_eq(aPacket.why.type, "resumeLimit");
let { frame: { environment, where: { source, line } } } = aPacket;
// Stepping should have moved us to the next source mapped line.
do_check_eq(source.url, "http://example.com/a.js");
do_check_eq(line, 3);
// Which should have skipped over the for loop in the generated js and sum
// should be calculated.
do_check_eq(environment.bindings.variables.sum.value, 10);
finishClient(gClient);
});
gThreadClient.stepIn();
}
|