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