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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/debug/Source-displayURL.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* -*- Mode: javascript; js-indent-level: 4; -*- */
     1.5 +// Source.prototype.displayURL can be a string or null.
     1.6 +
     1.7 +let g = newGlobal('new-compartment');
     1.8 +let dbg = new Debugger;
     1.9 +let gw = dbg.addDebuggee(g);
    1.10 +
    1.11 +function getDisplayURL() {
    1.12 +    let fw = gw.makeDebuggeeValue(g.f);
    1.13 +    return fw.script.source.displayURL;
    1.14 +}
    1.15 +
    1.16 +// Without a source url
    1.17 +g.evaluate("function f(x) { return 2*x; }");
    1.18 +assertEq(getDisplayURL(), null);
    1.19 +
    1.20 +// With a source url
    1.21 +g.evaluate("function f(x) { return 2*x; }", {displayURL: 'file:///var/foo.js'});
    1.22 +assertEq(getDisplayURL(), 'file:///var/foo.js');
    1.23 +
    1.24 +// Nested functions
    1.25 +let fired = false;
    1.26 +dbg.onDebuggerStatement = function (frame) {
    1.27 +    fired = true;
    1.28 +    assertEq(frame.script.source.displayURL, 'file:///var/bar.js');
    1.29 +};
    1.30 +g.evaluate('(function () { (function () { debugger; })(); })();',
    1.31 +           {displayURL: 'file:///var/bar.js'});
    1.32 +assertEq(fired, true);
    1.33 +
    1.34 +// Comment pragmas
    1.35 +g.evaluate('function f() {}\n' +
    1.36 +           '//# sourceURL=file:///var/quux.js');
    1.37 +assertEq(getDisplayURL(), 'file:///var/quux.js');
    1.38 +
    1.39 +g.evaluate('function f() {}\n' +
    1.40 +           '/*//# sourceURL=file:///var/quux.js*/');
    1.41 +assertEq(getDisplayURL(), 'file:///var/quux.js');
    1.42 +
    1.43 +g.evaluate('function f() {}\n' +
    1.44 +           '/*\n' +
    1.45 +           '//# sourceURL=file:///var/quux.js\n' +
    1.46 +           '*/');
    1.47 +assertEq(getDisplayURL(), 'file:///var/quux.js');
    1.48 +
    1.49 +// Spaces are disallowed by the URL spec (they should have been
    1.50 +// percent-encoded).
    1.51 +g.evaluate('function f() {}\n' +
    1.52 +           '//# sourceURL=http://example.com/has illegal spaces');
    1.53 +assertEq(getDisplayURL(), 'http://example.com/has');
    1.54 +
    1.55 +// When the URL is missing, we don't set the sourceMapURL and we don't skip the
    1.56 +// next line of input.
    1.57 +g.evaluate('function f() {}\n' +
    1.58 +           '//# sourceURL=\n' +
    1.59 +           'function z() {}');
    1.60 +assertEq(getDisplayURL(), null);
    1.61 +assertEq('z' in g, true);
    1.62 +
    1.63 +// The last comment pragma we see should be the one which sets the displayURL.
    1.64 +g.evaluate('function f() {}\n' +
    1.65 +           '//# sourceURL=http://example.com/foo.js\n' +
    1.66 +           '//# sourceURL=http://example.com/bar.js');
    1.67 +assertEq(getDisplayURL(), 'http://example.com/bar.js');
    1.68 +
    1.69 +// With both a comment and the evaluate option.
    1.70 +g.evaluate('function f() {}\n' +
    1.71 +           '//# sourceURL=http://example.com/foo.js',
    1.72 +           {displayURL: 'http://example.com/bar.js'});
    1.73 +assertEq(getDisplayURL(), 'http://example.com/foo.js');
    1.74 +

mercurial