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.

     1 /* -*- Mode: javascript; js-indent-level: 4; -*- */
     2 // Source.prototype.displayURL can be a string or null.
     4 let g = newGlobal('new-compartment');
     5 let dbg = new Debugger;
     6 let gw = dbg.addDebuggee(g);
     8 function getDisplayURL() {
     9     let fw = gw.makeDebuggeeValue(g.f);
    10     return fw.script.source.displayURL;
    11 }
    13 // Without a source url
    14 g.evaluate("function f(x) { return 2*x; }");
    15 assertEq(getDisplayURL(), null);
    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');
    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);
    31 // Comment pragmas
    32 g.evaluate('function f() {}\n' +
    33            '//# sourceURL=file:///var/quux.js');
    34 assertEq(getDisplayURL(), 'file:///var/quux.js');
    36 g.evaluate('function f() {}\n' +
    37            '/*//# sourceURL=file:///var/quux.js*/');
    38 assertEq(getDisplayURL(), 'file:///var/quux.js');
    40 g.evaluate('function f() {}\n' +
    41            '/*\n' +
    42            '//# sourceURL=file:///var/quux.js\n' +
    43            '*/');
    44 assertEq(getDisplayURL(), 'file:///var/quux.js');
    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');
    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);
    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');
    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');

mercurial