michael@0: /* -*- Mode: javascript; js-indent-level: 4; -*- */ michael@0: // Source.prototype.displayURL can be a string or null. michael@0: michael@0: let g = newGlobal('new-compartment'); michael@0: let dbg = new Debugger; michael@0: let gw = dbg.addDebuggee(g); michael@0: michael@0: function getDisplayURL() { michael@0: let fw = gw.makeDebuggeeValue(g.f); michael@0: return fw.script.source.displayURL; michael@0: } michael@0: michael@0: // Without a source url michael@0: g.evaluate("function f(x) { return 2*x; }"); michael@0: assertEq(getDisplayURL(), null); michael@0: michael@0: // With a source url michael@0: g.evaluate("function f(x) { return 2*x; }", {displayURL: 'file:///var/foo.js'}); michael@0: assertEq(getDisplayURL(), 'file:///var/foo.js'); 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.source.displayURL, 'file:///var/bar.js'); michael@0: }; michael@0: g.evaluate('(function () { (function () { debugger; })(); })();', michael@0: {displayURL: 'file:///var/bar.js'}); michael@0: assertEq(fired, true); michael@0: michael@0: // Comment pragmas michael@0: g.evaluate('function f() {}\n' + michael@0: '//# sourceURL=file:///var/quux.js'); michael@0: assertEq(getDisplayURL(), 'file:///var/quux.js'); michael@0: michael@0: g.evaluate('function f() {}\n' + michael@0: '/*//# sourceURL=file:///var/quux.js*/'); michael@0: assertEq(getDisplayURL(), 'file:///var/quux.js'); michael@0: michael@0: g.evaluate('function f() {}\n' + michael@0: '/*\n' + michael@0: '//# sourceURL=file:///var/quux.js\n' + michael@0: '*/'); michael@0: assertEq(getDisplayURL(), 'file:///var/quux.js'); 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: '//# sourceURL=http://example.com/has illegal spaces'); michael@0: assertEq(getDisplayURL(), '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: '//# sourceURL=\n' + michael@0: 'function z() {}'); michael@0: assertEq(getDisplayURL(), 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 displayURL. michael@0: g.evaluate('function f() {}\n' + michael@0: '//# sourceURL=http://example.com/foo.js\n' + michael@0: '//# sourceURL=http://example.com/bar.js'); michael@0: assertEq(getDisplayURL(), 'http://example.com/bar.js'); michael@0: michael@0: // With both a comment and the evaluate option. michael@0: g.evaluate('function f() {}\n' + michael@0: '//# sourceURL=http://example.com/foo.js', michael@0: {displayURL: 'http://example.com/bar.js'}); michael@0: assertEq(getDisplayURL(), 'http://example.com/foo.js'); michael@0: