|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Check that we source map frame locations returned by "frames" requests. |
|
6 */ |
|
7 |
|
8 var gDebuggee; |
|
9 var gClient; |
|
10 var gThreadClient; |
|
11 |
|
12 Components.utils.import('resource:///modules/devtools/SourceMap.jsm'); |
|
13 |
|
14 function run_test() { |
|
15 initTestDebuggerServer(); |
|
16 gDebuggee = addTestGlobal("test-source-map"); |
|
17 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
18 gClient.connect(function() { |
|
19 attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) { |
|
20 gThreadClient = aThreadClient; |
|
21 promise.resolve(define_code()) |
|
22 .then(run_code) |
|
23 .then(test_frames) |
|
24 .then(null, error => { |
|
25 dump(error + "\n"); |
|
26 dump(error.stack); |
|
27 do_check_true(false); |
|
28 }) |
|
29 .then(() => { |
|
30 finishClient(gClient); |
|
31 }); |
|
32 }); |
|
33 }); |
|
34 do_test_pending(); |
|
35 } |
|
36 |
|
37 function define_code() { |
|
38 let { code, map } = (new SourceNode(null, null, null, [ |
|
39 new SourceNode(1, 0, "a.js", "function a() {\n"), |
|
40 new SourceNode(2, 0, "a.js", " b();\n"), |
|
41 new SourceNode(3, 0, "a.js", "}\n"), |
|
42 new SourceNode(1, 0, "b.js", "function b() {\n"), |
|
43 new SourceNode(2, 0, "b.js", " c();\n"), |
|
44 new SourceNode(3, 0, "b.js", "}\n"), |
|
45 new SourceNode(1, 0, "c.js", "function c() {\n"), |
|
46 new SourceNode(2, 0, "c.js", " debugger;\n"), |
|
47 new SourceNode(3, 0, "c.js", "}\n"), |
|
48 ])).toStringWithSourceMap({ |
|
49 file: "abc.js", |
|
50 sourceRoot: "http://example.com/www/js/" |
|
51 }); |
|
52 |
|
53 code += "//# sourceMappingURL=data:text/json," + map.toString(); |
|
54 |
|
55 Components.utils.evalInSandbox(code, gDebuggee, "1.8", |
|
56 "http://example.com/www/js/abc.js", 1); |
|
57 } |
|
58 |
|
59 function run_code() { |
|
60 const d = promise.defer(); |
|
61 gClient.addOneTimeListener("paused", function () { |
|
62 gThreadClient.getFrames(0, 3, function (aResponse) { |
|
63 d.resolve(aResponse); |
|
64 gThreadClient.resume(); |
|
65 }) |
|
66 }); |
|
67 gDebuggee.a(); |
|
68 return d.promise; |
|
69 } |
|
70 |
|
71 function test_frames({ error, frames }) { |
|
72 do_check_true(!error); |
|
73 do_check_eq(frames.length, 3); |
|
74 check_frame(frames[0], "http://example.com/www/js/c.js"); |
|
75 check_frame(frames[1], "http://example.com/www/js/b.js"); |
|
76 check_frame(frames[2], "http://example.com/www/js/a.js"); |
|
77 } |
|
78 |
|
79 function check_frame({ where: { url, line, column } }, aExpectedUrl) { |
|
80 do_check_eq(url, aExpectedUrl); |
|
81 do_check_eq(line, 2); |
|
82 do_check_eq(column, 0); |
|
83 } |