js/src/jit-test/tests/debug/Source-displayURL.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: javascript; js-indent-level: 4; -*- */
michael@0 2 // Source.prototype.displayURL can be a string or null.
michael@0 3
michael@0 4 let g = newGlobal('new-compartment');
michael@0 5 let dbg = new Debugger;
michael@0 6 let gw = dbg.addDebuggee(g);
michael@0 7
michael@0 8 function getDisplayURL() {
michael@0 9 let fw = gw.makeDebuggeeValue(g.f);
michael@0 10 return fw.script.source.displayURL;
michael@0 11 }
michael@0 12
michael@0 13 // Without a source url
michael@0 14 g.evaluate("function f(x) { return 2*x; }");
michael@0 15 assertEq(getDisplayURL(), null);
michael@0 16
michael@0 17 // With a source url
michael@0 18 g.evaluate("function f(x) { return 2*x; }", {displayURL: 'file:///var/foo.js'});
michael@0 19 assertEq(getDisplayURL(), 'file:///var/foo.js');
michael@0 20
michael@0 21 // Nested functions
michael@0 22 let fired = false;
michael@0 23 dbg.onDebuggerStatement = function (frame) {
michael@0 24 fired = true;
michael@0 25 assertEq(frame.script.source.displayURL, 'file:///var/bar.js');
michael@0 26 };
michael@0 27 g.evaluate('(function () { (function () { debugger; })(); })();',
michael@0 28 {displayURL: 'file:///var/bar.js'});
michael@0 29 assertEq(fired, true);
michael@0 30
michael@0 31 // Comment pragmas
michael@0 32 g.evaluate('function f() {}\n' +
michael@0 33 '//# sourceURL=file:///var/quux.js');
michael@0 34 assertEq(getDisplayURL(), 'file:///var/quux.js');
michael@0 35
michael@0 36 g.evaluate('function f() {}\n' +
michael@0 37 '/*//# sourceURL=file:///var/quux.js*/');
michael@0 38 assertEq(getDisplayURL(), 'file:///var/quux.js');
michael@0 39
michael@0 40 g.evaluate('function f() {}\n' +
michael@0 41 '/*\n' +
michael@0 42 '//# sourceURL=file:///var/quux.js\n' +
michael@0 43 '*/');
michael@0 44 assertEq(getDisplayURL(), 'file:///var/quux.js');
michael@0 45
michael@0 46 // Spaces are disallowed by the URL spec (they should have been
michael@0 47 // percent-encoded).
michael@0 48 g.evaluate('function f() {}\n' +
michael@0 49 '//# sourceURL=http://example.com/has illegal spaces');
michael@0 50 assertEq(getDisplayURL(), 'http://example.com/has');
michael@0 51
michael@0 52 // When the URL is missing, we don't set the sourceMapURL and we don't skip the
michael@0 53 // next line of input.
michael@0 54 g.evaluate('function f() {}\n' +
michael@0 55 '//# sourceURL=\n' +
michael@0 56 'function z() {}');
michael@0 57 assertEq(getDisplayURL(), null);
michael@0 58 assertEq('z' in g, true);
michael@0 59
michael@0 60 // The last comment pragma we see should be the one which sets the displayURL.
michael@0 61 g.evaluate('function f() {}\n' +
michael@0 62 '//# sourceURL=http://example.com/foo.js\n' +
michael@0 63 '//# sourceURL=http://example.com/bar.js');
michael@0 64 assertEq(getDisplayURL(), 'http://example.com/bar.js');
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 '//# sourceURL=http://example.com/foo.js',
michael@0 69 {displayURL: 'http://example.com/bar.js'});
michael@0 70 assertEq(getDisplayURL(), 'http://example.com/foo.js');
michael@0 71

mercurial