js/src/jit-test/tests/debug/Script-sourceStart-02.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-sourceStart-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,32 @@
     1.4 +/*
     1.5 + * For function statements, Script.prototype.sourceStart and
     1.6 + * Script.prototype.sourceLength should comprise both the opening '(' and the
     1.7 + * closing '}'.
     1.8 + */
     1.9 +let g = newGlobal();
    1.10 +let dbg = new Debugger(g);
    1.11 +
    1.12 +function test(string, ranges) {
    1.13 +    var index = 0;
    1.14 +    dbg.onNewScript = function (script) {
    1.15 +        function traverse(script) {
    1.16 +            script.getChildScripts().forEach(function (script) {
    1.17 +                assertEq(script.sourceStart, ranges[index][0]);
    1.18 +                assertEq(script.sourceLength, ranges[index][1]);
    1.19 +                ++index;
    1.20 +                traverse(script);
    1.21 +            });
    1.22 +        }
    1.23 +        traverse(script);
    1.24 +    };
    1.25 +
    1.26 +    g.eval(string);
    1.27 +    assertEq(index, ranges.length);
    1.28 +};
    1.29 +
    1.30 +test("function f() {}", [[10, 5]]);
    1.31 +test("function f() { function g() {} }", [[10, 22], [25, 5]]);
    1.32 +test("function f() { function g() { function h() {} } }", [[10, 39], [25, 22], [40, 5]]);
    1.33 +test("function f() { if (true) function g() {} }", [[10, 32], [35, 5]]); 
    1.34 +test("var o = { get p () {} }", [[16, 5]]);
    1.35 +test("var o = { set p (x) {} }", [[16, 6]]);

mercurial