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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Check that source maps and breakpoints work with minified javascript.
*/
var gDebuggee;
var gClient;
var gThreadClient;
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;
test_minified();
});
});
do_test_pending();
}
function test_minified()
{
let newSourceFired = false;
gThreadClient.addOneTimeListener("newSource", function _onNewSource(aEvent, aPacket) {
do_check_eq(aEvent, "newSource");
do_check_eq(aPacket.type, "newSource");
do_check_true(!!aPacket.source);
do_check_eq(aPacket.source.url, "http://example.com/foo.js",
"The new source should be foo.js");
do_check_eq(aPacket.source.url.indexOf("foo.min.js"), -1,
"The new source should not be the minified file");
newSourceFired = true;
});
gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
do_check_eq(aEvent, "paused");
do_check_eq(aPacket.why.type, "debuggerStatement");
let location = {
line: 5
};
getSource(gThreadClient, "http://example.com/foo.js").then(source => {
source.setBreakpoint(location, function (aResponse, bpClient) {
do_check_true(!aResponse.error);
testHitBreakpoint();
});
});
});
// This is the original foo.js, which was then minified with uglifyjs version
// 2.2.5 and the "--mangle" option.
//
// (function () {
// debugger;
// function foo(n) {
// var bar = n + n;
// var unused = null;
// return bar;
// }
// for (var i = 0; i < 10; i++) {
// foo(i);
// }
// }());
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"}';
Components.utils.evalInSandbox(code, gDebuggee, "1.8",
"http://example.com/foo.min.js", 1);
}
function testHitBreakpoint(timesHit = 0) {
gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
++timesHit;
do_check_eq(aEvent, "paused");
do_check_eq(aPacket.why.type, "breakpoint");
if (timesHit === 10) {
gThreadClient.resume(() => finishClient(gClient));
} else {
testHitBreakpoint(timesHit);
}
});
gThreadClient.resume();
}
|