|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Check that source maps and breakpoints work with minified javascript. |
|
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 { |
|
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 test_minified(); |
|
23 }); |
|
24 }); |
|
25 do_test_pending(); |
|
26 } |
|
27 |
|
28 function test_minified() |
|
29 { |
|
30 let newSourceFired = false; |
|
31 |
|
32 gClient.addOneTimeListener("newSource", function _onNewSource(aEvent, aPacket) { |
|
33 do_check_eq(aEvent, "newSource"); |
|
34 do_check_eq(aPacket.type, "newSource"); |
|
35 do_check_true(!!aPacket.source); |
|
36 |
|
37 do_check_eq(aPacket.source.url, "http://example.com/foo.js", |
|
38 "The new source should be foo.js"); |
|
39 do_check_eq(aPacket.source.url.indexOf("foo.min.js"), -1, |
|
40 "The new source should not be the minified file"); |
|
41 |
|
42 newSourceFired = true; |
|
43 }); |
|
44 |
|
45 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
46 do_check_eq(aEvent, "paused"); |
|
47 do_check_eq(aPacket.why.type, "debuggerStatement"); |
|
48 |
|
49 const location = { |
|
50 url: "http://example.com/foo.js", |
|
51 line: 5 |
|
52 }; |
|
53 |
|
54 gThreadClient.setBreakpoint(location, function (aResponse, bpClient) { |
|
55 do_check_true(!aResponse.error); |
|
56 testHitBreakpoint(); |
|
57 }); |
|
58 }); |
|
59 |
|
60 // This is the original foo.js, which was then minified with uglifyjs version |
|
61 // 2.2.5 and the "--mangle" option. |
|
62 // |
|
63 // (function () { |
|
64 // debugger; |
|
65 // function foo(n) { |
|
66 // var bar = n + n; |
|
67 // var unused = null; |
|
68 // return bar; |
|
69 // } |
|
70 // for (var i = 0; i < 10; i++) { |
|
71 // foo(i); |
|
72 // } |
|
73 // }()); |
|
74 |
|
75 let code = '(function(){debugger;function r(r){var n=r+r;var u=null;return n}for(var n=0;n<10;n++){r(n)}})();\n//# sourceMappingURL=data:text/json,{"file":"foo.min.js","version":3,"sources":["foo.js"],"names":["foo","n","bar","unused","i"],"mappings":"CAAC,WACC,QACA,SAASA,GAAIC,GACX,GAAIC,GAAMD,EAAIA,CACd,IAAIE,GAAS,IACb,OAAOD,GAET,IAAK,GAAIE,GAAI,EAAGA,EAAI,GAAIA,IAAK,CAC3BJ,EAAII"}'; |
|
76 |
|
77 Components.utils.evalInSandbox(code, gDebuggee, "1.8", |
|
78 "http://example.com/foo.min.js", 1); |
|
79 } |
|
80 |
|
81 function testHitBreakpoint(timesHit=0) { |
|
82 gClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
83 ++timesHit; |
|
84 |
|
85 do_check_eq(aEvent, "paused"); |
|
86 do_check_eq(aPacket.why.type, "breakpoint"); |
|
87 |
|
88 if (timesHit === 10) { |
|
89 gThreadClient.resume(() => finishClient(gClient)); |
|
90 } else { |
|
91 testHitBreakpoint(timesHit); |
|
92 } |
|
93 }); |
|
94 |
|
95 gThreadClient.resume(); |
|
96 } |