js/src/jit-test/tests/debug/Script-getLineOffsets-05.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-getLineOffsets-05.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +// getLineOffsets identifies multiple ways to land on a line.
     1.5 +
     1.6 +var g = newGlobal();
     1.7 +g.line0 = null;
     1.8 +var dbg = Debugger(g);
     1.9 +var where;
    1.10 +dbg.onDebuggerStatement = function (frame) {
    1.11 +    var s = frame.script, lineno, offs;
    1.12 +
    1.13 +    lineno = g.line0 + where;
    1.14 +    offs = s.getLineOffsets(lineno);
    1.15 +    for (var i = 0; i < offs.length; i++) {
    1.16 +        assertEq(s.getOffsetLine(offs[i]), lineno);
    1.17 +        s.setBreakpoint(offs[i], {hit: function () { g.log += 'B'; }});
    1.18 +    }
    1.19 +
    1.20 +    lineno++;
    1.21 +    offs = s.getLineOffsets(lineno);
    1.22 +    for (var i = 0; i < offs.length; i++) {
    1.23 +        assertEq(s.getOffsetLine(offs[i]), lineno);
    1.24 +        s.setBreakpoint(offs[i], {hit: function () { g.log += 'C'; }});
    1.25 +    }
    1.26 +
    1.27 +    g.log += 'A';
    1.28 +};
    1.29 +
    1.30 +function test(s) {
    1.31 +    assertEq(s.charAt(s.length - 1), '\n');
    1.32 +    var count = (s.split(/\n/).length - 1); // number of lines in s
    1.33 +    g.log = '';
    1.34 +    where = 1 + count;
    1.35 +    g.eval("line0 = Error().lineNumber;\n" +
    1.36 +           "debugger;\n" +          // line0 + 1
    1.37 +           s +                      // line0 + 2 ... line0 + where
    1.38 +           "log += 'D';\n");
    1.39 +    assertEq(g.log, 'AB!CD');
    1.40 +}
    1.41 +
    1.42 +// if-statement with yes and no paths on a single line
    1.43 +g.i = 0;
    1.44 +test("if (i === 0)\n" +
    1.45 +     "    log += '!'; else log += 'X';\n");
    1.46 +test("if (i === 2)\n" +
    1.47 +     "    log += 'X'; else log += '!';\n");
    1.48 +
    1.49 +// break to a line that has code inside and outside the loop
    1.50 +g.i = 2;
    1.51 +test("while (1) {\n" +
    1.52 +     "    if (i === 2) break;\n" +
    1.53 +     "    log += 'X'; } log += '!';\n");
    1.54 +
    1.55 +// leaving a while loop by failing the test, when the last line has stuff both inside and outside the loop
    1.56 +g.i = 0;
    1.57 +test("while (i > 0) {\n" +
    1.58 +     "    if (i === 70) log += 'X';\n" +
    1.59 +     "    --i;  } log += '!';\n");
    1.60 +
    1.61 +// multiple case-labels on the same line
    1.62 +g.i = 0;
    1.63 +test("switch (i) {\n" +
    1.64 +     "    case 0: case 1: log += '!'; break; }\n");
    1.65 +test("switch ('' + i) {\n" +
    1.66 +     "    case '0': case '1': log += '!'; break; }\n");
    1.67 +test("switch (i) {\n" +
    1.68 +     "    case 'ok' + i: case i - i: log += '!'; break; }\n");

mercurial