js/src/jit-test/tests/debug/Source-displayURL.js

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

mercurial