js/src/jit-test/tests/debug/Script-getLineOffsets-05.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 // getLineOffsets identifies multiple ways to land on a line.
     3 var g = newGlobal();
     4 g.line0 = null;
     5 var dbg = Debugger(g);
     6 var where;
     7 dbg.onDebuggerStatement = function (frame) {
     8     var s = frame.script, lineno, offs;
    10     lineno = g.line0 + where;
    11     offs = s.getLineOffsets(lineno);
    12     for (var i = 0; i < offs.length; i++) {
    13         assertEq(s.getOffsetLine(offs[i]), lineno);
    14         s.setBreakpoint(offs[i], {hit: function () { g.log += 'B'; }});
    15     }
    17     lineno++;
    18     offs = s.getLineOffsets(lineno);
    19     for (var i = 0; i < offs.length; i++) {
    20         assertEq(s.getOffsetLine(offs[i]), lineno);
    21         s.setBreakpoint(offs[i], {hit: function () { g.log += 'C'; }});
    22     }
    24     g.log += 'A';
    25 };
    27 function test(s) {
    28     assertEq(s.charAt(s.length - 1), '\n');
    29     var count = (s.split(/\n/).length - 1); // number of lines in s
    30     g.log = '';
    31     where = 1 + count;
    32     g.eval("line0 = Error().lineNumber;\n" +
    33            "debugger;\n" +          // line0 + 1
    34            s +                      // line0 + 2 ... line0 + where
    35            "log += 'D';\n");
    36     assertEq(g.log, 'AB!CD');
    37 }
    39 // if-statement with yes and no paths on a single line
    40 g.i = 0;
    41 test("if (i === 0)\n" +
    42      "    log += '!'; else log += 'X';\n");
    43 test("if (i === 2)\n" +
    44      "    log += 'X'; else log += '!';\n");
    46 // break to a line that has code inside and outside the loop
    47 g.i = 2;
    48 test("while (1) {\n" +
    49      "    if (i === 2) break;\n" +
    50      "    log += 'X'; } log += '!';\n");
    52 // leaving a while loop by failing the test, when the last line has stuff both inside and outside the loop
    53 g.i = 0;
    54 test("while (i > 0) {\n" +
    55      "    if (i === 70) log += 'X';\n" +
    56      "    --i;  } log += '!';\n");
    58 // multiple case-labels on the same line
    59 g.i = 0;
    60 test("switch (i) {\n" +
    61      "    case 0: case 1: log += '!'; break; }\n");
    62 test("switch ('' + i) {\n" +
    63      "    case '0': case '1': log += '!'; break; }\n");
    64 test("switch (i) {\n" +
    65      "    case 'ok' + i: case i - i: log += '!'; break; }\n");

mercurial