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