summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Source-sourceMapURL-deprecated.js
blob: f25f652a0451e309c5670b3bcbd7ce2527b25b32 (plain)
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
// Source.prototype.sourceMapURL can be a string or null.

let g = newGlobal({newCompartment: true});
let dbg = new Debugger;
let gw = dbg.addDebuggee(g);

function getSourceMapURL() {
    let fw = gw.makeDebuggeeValue(g.f);
    return fw.script.source.sourceMapURL;
}

function setSourceMapURL(url) {
    let fw = gw.makeDebuggeeValue(g.f);
    fw.script.source.sourceMapURL = url;
}

// Without a source map
g.evaluate("function f(x) { return 2*x; }");
assertEq(getSourceMapURL(), null);

// With a source map
g.evaluate("function f(x) { return 2*x; }", {sourceMapURL: 'file:///var/foo.js.map'});
assertEq(getSourceMapURL(), 'file:///var/foo.js.map');

// Nested functions
let fired = false;
dbg.onDebuggerStatement = function (frame) {
    fired = true;
    assertEq(frame.script.source.sourceMapURL, 'file:///var/bar.js.map');
};
g.evaluate('(function () { (function () { debugger; })(); })();',
           {sourceMapURL: 'file:///var/bar.js.map'});
assertEq(fired, true);

// Comment pragmas
g.evaluate('function f() {}\n' +
           '//@ sourceMappingURL=file:///var/quux.js.map');
assertEq(getSourceMapURL(), 'file:///var/quux.js.map');

g.evaluate('function f() {}\n' +
           '/*//@ sourceMappingURL=file:///var/quux.js.map*/');
assertEq(getSourceMapURL(), 'file:///var/quux.js.map');

g.evaluate('function f() {}\n' +
           '/*\n' +
           '//@ sourceMappingURL=file:///var/quux.js.map\n' +
           '*/');
assertEq(getSourceMapURL(), 'file:///var/quux.js.map');

// Spaces are disallowed by the URL spec (they should have been
// percent-encoded).
g.evaluate('function f() {}\n' +
           '//@ sourceMappingURL=http://example.com/has illegal spaces.map');
assertEq(getSourceMapURL(), 'http://example.com/has');

// When the URL is missing, we don't set the sourceMapURL and we don't skip the
// next line of input.
g.evaluate('function f() {}\n' +
           '//@ sourceMappingURL=\n' +
           'function z() {}');
assertEq(getSourceMapURL(), null);
assertEq('z' in g, true);

// The last comment pragma we see should be the one which sets the source map's
// URL.
g.evaluate('function f() {}\n' +
           '//@ sourceMappingURL=http://example.com/foo.js.map\n' +
           '//@ sourceMappingURL=http://example.com/bar.js.map');
assertEq(getSourceMapURL(), 'http://example.com/bar.js.map');

// With both a comment and the evaluate option.
g.evaluate('function f() {}\n' +
           '//@ sourceMappingURL=http://example.com/foo.js.map',
           {sourceMapURL: 'http://example.com/bar.js.map'});
assertEq(getSourceMapURL(), 'http://example.com/foo.js.map');

// Make sure setting the sourceMapURL manually works
setSourceMapURL('baz.js.map');
assertEq(getSourceMapURL(), 'baz.js.map');

setSourceMapURL('');
assertEq(getSourceMapURL(), 'baz.js.map');