|
1 // Script.prototype.sourceMapURL can be a string or null. |
|
2 |
|
3 let g = newGlobal(); |
|
4 let dbg = new Debugger; |
|
5 let gw = dbg.addDebuggee(g); |
|
6 |
|
7 function getSourceMapURL() { |
|
8 let fw = gw.makeDebuggeeValue(g.f); |
|
9 return fw.script.sourceMapURL; |
|
10 } |
|
11 |
|
12 // Without a source map |
|
13 g.evaluate("function f(x) { return 2*x; }"); |
|
14 assertEq(getSourceMapURL(), null); |
|
15 |
|
16 // With a source map |
|
17 g.evaluate("function f(x) { return 2*x; }", {sourceMapURL: 'file:///var/foo.js.map'}); |
|
18 assertEq(getSourceMapURL(), 'file:///var/foo.js.map'); |
|
19 |
|
20 // Nested functions |
|
21 let fired = false; |
|
22 dbg.onDebuggerStatement = function (frame) { |
|
23 fired = true; |
|
24 assertEq(frame.script.sourceMapURL, 'file:///var/bar.js.map'); |
|
25 }; |
|
26 g.evaluate('(function () { (function () { debugger; })(); })();', |
|
27 {sourceMapURL: 'file:///var/bar.js.map'}); |
|
28 assertEq(fired, true); |
|
29 |
|
30 // Comment pragmas |
|
31 g.evaluate('function f() {}\n' + |
|
32 '//# sourceMappingURL=file:///var/quux.js.map'); |
|
33 assertEq(getSourceMapURL(), 'file:///var/quux.js.map'); |
|
34 |
|
35 g.evaluate('function f() {}\n' + |
|
36 '/*//# sourceMappingURL=file:///var/quux.js.map*/'); |
|
37 assertEq(getSourceMapURL(), 'file:///var/quux.js.map'); |
|
38 |
|
39 g.evaluate('function f() {}\n' + |
|
40 '/*\n' + |
|
41 '//# sourceMappingURL=file:///var/quux.js.map\n' + |
|
42 '*/'); |
|
43 assertEq(getSourceMapURL(), 'file:///var/quux.js.map'); |
|
44 |
|
45 // Spaces are disallowed by the URL spec (they should have been |
|
46 // percent-encoded). |
|
47 g.evaluate('function f() {}\n' + |
|
48 '//# sourceMappingURL=http://example.com/has illegal spaces.map'); |
|
49 assertEq(getSourceMapURL(), 'http://example.com/has'); |
|
50 |
|
51 // When the URL is missing, we don't set the sourceMapURL and we don't skip the |
|
52 // next line of input. |
|
53 g.evaluate('function f() {}\n' + |
|
54 '//# sourceMappingURL=\n' + |
|
55 'function z() {}'); |
|
56 assertEq(getSourceMapURL(), null); |
|
57 assertEq('z' in g, true); |
|
58 |
|
59 // The last comment pragma we see should be the one which sets the source map's |
|
60 // URL. |
|
61 g.evaluate('function f() {}\n' + |
|
62 '//# sourceMappingURL=http://example.com/foo.js.map\n' + |
|
63 '//# sourceMappingURL=http://example.com/bar.js.map'); |
|
64 assertEq(getSourceMapURL(), 'http://example.com/bar.js.map'); |
|
65 |
|
66 // With both a comment and the evaluate option. |
|
67 g.evaluate('function f() {}\n' + |
|
68 '//# sourceMappingURL=http://example.com/foo.js.map', |
|
69 {sourceMapURL: 'http://example.com/bar.js.map'}); |
|
70 assertEq(getSourceMapURL(), 'http://example.com/foo.js.map'); |