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

mercurial