Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Script.prototype.sourceMapURL can be a string or null. |
michael@0 | 2 | |
michael@0 | 3 | let g = newGlobal(); |
michael@0 | 4 | let dbg = new Debugger; |
michael@0 | 5 | let gw = dbg.addDebuggee(g); |
michael@0 | 6 | |
michael@0 | 7 | function getSourceMapURL() { |
michael@0 | 8 | let fw = gw.makeDebuggeeValue(g.f); |
michael@0 | 9 | return fw.script.sourceMapURL; |
michael@0 | 10 | } |
michael@0 | 11 | |
michael@0 | 12 | // Without a source map |
michael@0 | 13 | g.evaluate("function f(x) { return 2*x; }"); |
michael@0 | 14 | assertEq(getSourceMapURL(), null); |
michael@0 | 15 | |
michael@0 | 16 | // With a source map |
michael@0 | 17 | g.evaluate("function f(x) { return 2*x; }", {sourceMapURL: 'file:///var/foo.js.map'}); |
michael@0 | 18 | assertEq(getSourceMapURL(), 'file:///var/foo.js.map'); |
michael@0 | 19 | |
michael@0 | 20 | // Nested functions |
michael@0 | 21 | let fired = false; |
michael@0 | 22 | dbg.onDebuggerStatement = function (frame) { |
michael@0 | 23 | fired = true; |
michael@0 | 24 | assertEq(frame.script.sourceMapURL, 'file:///var/bar.js.map'); |
michael@0 | 25 | }; |
michael@0 | 26 | g.evaluate('(function () { (function () { debugger; })(); })();', |
michael@0 | 27 | {sourceMapURL: 'file:///var/bar.js.map'}); |
michael@0 | 28 | assertEq(fired, true); |
michael@0 | 29 | |
michael@0 | 30 | // Comment pragmas |
michael@0 | 31 | g.evaluate('function f() {}\n' + |
michael@0 | 32 | '//@ sourceMappingURL=file:///var/quux.js.map'); |
michael@0 | 33 | assertEq(getSourceMapURL(), 'file:///var/quux.js.map'); |
michael@0 | 34 | |
michael@0 | 35 | g.evaluate('function f() {}\n' + |
michael@0 | 36 | '/*//@ sourceMappingURL=file:///var/quux.js.map*/'); |
michael@0 | 37 | assertEq(getSourceMapURL(), 'file:///var/quux.js.map'); |
michael@0 | 38 | |
michael@0 | 39 | g.evaluate('function f() {}\n' + |
michael@0 | 40 | '/*\n' + |
michael@0 | 41 | '//@ sourceMappingURL=file:///var/quux.js.map\n' + |
michael@0 | 42 | '*/'); |
michael@0 | 43 | assertEq(getSourceMapURL(), 'file:///var/quux.js.map'); |
michael@0 | 44 | |
michael@0 | 45 | // Spaces are disallowed by the URL spec (they should have been |
michael@0 | 46 | // percent-encoded). |
michael@0 | 47 | g.evaluate('function f() {}\n' + |
michael@0 | 48 | '//@ sourceMappingURL=http://example.com/has illegal spaces.map'); |
michael@0 | 49 | assertEq(getSourceMapURL(), 'http://example.com/has'); |
michael@0 | 50 | |
michael@0 | 51 | // When the URL is missing, we don't set the sourceMapURL and we don't skip the |
michael@0 | 52 | // next line of input. |
michael@0 | 53 | g.evaluate('function f() {}\n' + |
michael@0 | 54 | '//@ sourceMappingURL=\n' + |
michael@0 | 55 | 'function z() {}'); |
michael@0 | 56 | assertEq(getSourceMapURL(), null); |
michael@0 | 57 | assertEq('z' in g, true); |
michael@0 | 58 | |
michael@0 | 59 | // The last comment pragma we see should be the one which sets the source map's |
michael@0 | 60 | // URL. |
michael@0 | 61 | g.evaluate('function f() {}\n' + |
michael@0 | 62 | '//@ sourceMappingURL=http://example.com/foo.js.map\n' + |
michael@0 | 63 | '//@ sourceMappingURL=http://example.com/bar.js.map'); |
michael@0 | 64 | assertEq(getSourceMapURL(), 'http://example.com/bar.js.map'); |
michael@0 | 65 | |
michael@0 | 66 | // With both a comment and the evaluate option. |
michael@0 | 67 | g.evaluate('function f() {}\n' + |
michael@0 | 68 | '//@ sourceMappingURL=http://example.com/foo.js.map', |
michael@0 | 69 | {sourceMapURL: 'http://example.com/bar.js.map'}); |
michael@0 | 70 | assertEq(getSourceMapURL(), 'http://example.com/foo.js.map'); |