michael@0: // Script.prototype.sourceMapURL can be a string or null. michael@0: michael@0: let g = newGlobal(); michael@0: let dbg = new Debugger; michael@0: let gw = dbg.addDebuggee(g); michael@0: michael@0: function getSourceMapURL() { michael@0: let fw = gw.makeDebuggeeValue(g.f); michael@0: return fw.script.sourceMapURL; michael@0: } michael@0: michael@0: // Without a source map michael@0: g.evaluate("function f(x) { return 2*x; }"); michael@0: assertEq(getSourceMapURL(), null); michael@0: michael@0: // With a source map michael@0: g.evaluate("function f(x) { return 2*x; }", {sourceMapURL: 'file:///var/foo.js.map'}); michael@0: assertEq(getSourceMapURL(), 'file:///var/foo.js.map'); michael@0: michael@0: // Nested functions michael@0: let fired = false; michael@0: dbg.onDebuggerStatement = function (frame) { michael@0: fired = true; michael@0: assertEq(frame.script.sourceMapURL, 'file:///var/bar.js.map'); michael@0: }; michael@0: g.evaluate('(function () { (function () { debugger; })(); })();', michael@0: {sourceMapURL: 'file:///var/bar.js.map'}); michael@0: assertEq(fired, true); michael@0: michael@0: // Comment pragmas michael@0: g.evaluate('function f() {}\n' + michael@0: '//@ sourceMappingURL=file:///var/quux.js.map'); michael@0: assertEq(getSourceMapURL(), 'file:///var/quux.js.map'); michael@0: michael@0: g.evaluate('function f() {}\n' + michael@0: '/*//@ sourceMappingURL=file:///var/quux.js.map*/'); michael@0: assertEq(getSourceMapURL(), 'file:///var/quux.js.map'); michael@0: michael@0: g.evaluate('function f() {}\n' + michael@0: '/*\n' + michael@0: '//@ sourceMappingURL=file:///var/quux.js.map\n' + michael@0: '*/'); michael@0: assertEq(getSourceMapURL(), 'file:///var/quux.js.map'); michael@0: michael@0: // Spaces are disallowed by the URL spec (they should have been michael@0: // percent-encoded). michael@0: g.evaluate('function f() {}\n' + michael@0: '//@ sourceMappingURL=http://example.com/has illegal spaces.map'); michael@0: assertEq(getSourceMapURL(), 'http://example.com/has'); michael@0: michael@0: // When the URL is missing, we don't set the sourceMapURL and we don't skip the michael@0: // next line of input. michael@0: g.evaluate('function f() {}\n' + michael@0: '//@ sourceMappingURL=\n' + michael@0: 'function z() {}'); michael@0: assertEq(getSourceMapURL(), null); michael@0: assertEq('z' in g, true); michael@0: michael@0: // The last comment pragma we see should be the one which sets the source map's michael@0: // URL. michael@0: g.evaluate('function f() {}\n' + michael@0: '//@ sourceMappingURL=http://example.com/foo.js.map\n' + michael@0: '//@ sourceMappingURL=http://example.com/bar.js.map'); michael@0: assertEq(getSourceMapURL(), 'http://example.com/bar.js.map'); michael@0: michael@0: // With both a comment and the evaluate option. michael@0: g.evaluate('function f() {}\n' + michael@0: '//@ sourceMappingURL=http://example.com/foo.js.map', michael@0: {sourceMapURL: 'http://example.com/bar.js.map'}); michael@0: assertEq(getSourceMapURL(), 'http://example.com/foo.js.map');