Source-displayURL.js (3117B)
1 /* -*- js-indent-level: 4; indent-tabs-mode: nil -*- */ 2 // Source.prototype.displayURL can be a string or null. 3 4 let g = newGlobal({newCompartment: true}); 5 let dbg = new Debugger; 6 let gw = dbg.addDebuggee(g); 7 8 function getDisplayURL() { 9 let fw = gw.makeDebuggeeValue(g.f); 10 return fw.script.source.displayURL; 11 } 12 13 // Without a source url 14 g.evaluate("function f(x) { return 2*x; }"); 15 assertEq(getDisplayURL(), null); 16 17 // With a source url 18 g.evaluate("function f(x) { return 2*x; }", {displayURL: 'file:///var/foo.js'}); 19 assertEq(getDisplayURL(), 'file:///var/foo.js'); 20 21 // Nested functions 22 let fired = false; 23 dbg.onDebuggerStatement = function (frame) { 24 fired = true; 25 assertEq(frame.script.source.displayURL, 'file:///var/bar.js'); 26 }; 27 g.evaluate('(function () { (function () { debugger; })(); })();', 28 {displayURL: 'file:///var/bar.js'}); 29 assertEq(fired, true); 30 31 // Comment pragmas 32 g.evaluate('function f() {}\n' + 33 '//# sourceURL=file:///var/quux.js'); 34 assertEq(getDisplayURL(), 'file:///var/quux.js'); 35 36 g.evaluate('function f() {}\n' + 37 '/*//# sourceURL=file:///var/quux.js*/'); 38 assertEq(getDisplayURL(), 'file:///var/quux.js'); 39 40 g.evaluate('function f() {}\n' + 41 '/*\n' + 42 '//# sourceURL=file:///var/quux.js\n' + 43 '*/'); 44 assertEq(getDisplayURL(), 'file:///var/quux.js'); 45 46 // Spaces are disallowed by the URL spec (they should have been 47 // percent-encoded). 48 g.evaluate('function f() {}\n' + 49 '//# sourceURL=http://example.com/has illegal spaces'); 50 assertEq(getDisplayURL(), 'http://example.com/has'); 51 52 // When the URL is missing, we don't set the sourceMapURL and we don't skip the 53 // next line of input. 54 g.evaluate('function f() {}\n' + 55 '//# sourceURL=\n' + 56 'function z() {}'); 57 assertEq(getDisplayURL(), null); 58 assertEq('z' in g, true); 59 60 // The last comment pragma we see should be the one which sets the displayURL. 61 g.evaluate('function f() {}\n' + 62 '//# sourceURL=http://example.com/foo.js\n' + 63 '//# sourceURL=http://example.com/bar.js'); 64 assertEq(getDisplayURL(), 'http://example.com/bar.js'); 65 66 // With both a comment and the evaluate option. 67 g.evaluate('function f() {}\n' + 68 '//# sourceURL=http://example.com/foo.js', 69 {displayURL: 'http://example.com/bar.js'}); 70 assertEq(getDisplayURL(), 'http://example.com/foo.js'); 71 72 73 // Bug 981987 reported that we hadn't set sourceURL yet when firing onNewScript 74 // from the Function constructor. 75 var capturedScript; 76 var capturedDisplayURL; 77 var capturedSourceMapURL; 78 dbg.onNewScript = function (script) { 79 capturedScript = script; 80 capturedDisplayURL = script.source.displayURL; 81 capturedSourceMapURL = script.source.sourceMapURL; 82 dbg.onNewScript = undefined; 83 }; 84 var fun = gw.makeDebuggeeValue(g.Function('//# sourceURL=munge.js\n//# sourceMappingURL=grunge.map\n')); 85 assertEq(capturedScript, fun.script); 86 87 assertEq(capturedDisplayURL, fun.script.source.displayURL); 88 assertEq(capturedDisplayURL, 'munge.js'); 89 90 assertEq(capturedSourceMapURL, fun.script.source.sourceMapURL); 91 assertEq(capturedSourceMapURL, 'grunge.map');