PageRenderTime 35ms CodeModel.GetById 18ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/js/src/jit-test/tests/debug/Script-getLineOffsets-05.js

http://github.com/zpao/v8monkey
JavaScript | 65 lines | 51 code | 9 blank | 5 comment | 2 complexity | c382e5f959930186462f6dcb258bc90c MD5 | raw file
 1// getLineOffsets identifies multiple ways to land on a line.
 2
 3var g = newGlobal('new-compartment');
 4g.line0 = null;
 5var dbg = Debugger(g);
 6var where;
 7dbg.onDebuggerStatement = function (frame) {
 8    var s = frame.script, lineno, offs;
 9
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    }
16
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    }
23
24    g.log += 'A';
25};
26
27function 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}
38
39// if-statement with yes and no paths on a single line
40g.i = 0;
41test("if (i === 0)\n" +
42     "    log += '!'; else log += 'X';\n");
43test("if (i === 2)\n" +
44     "    log += 'X'; else log += '!';\n");
45
46// break to a line that has code inside and outside the loop
47g.i = 2;
48test("while (1) {\n" +
49     "    if (i === 2) break;\n" +
50     "    log += 'X'; } log += '!';\n");
51
52// leaving a while loop by failing the test, when the last line has stuff both inside and outside the loop
53g.i = 0;
54test("while (i > 0) {\n" +
55     "    if (i === 70) log += 'X';\n" +
56     "    --i;  } log += '!';\n");
57
58// multiple case-labels on the same line
59g.i = 0;
60test("switch (i) {\n" +
61     "    case 0: case 1: log += '!'; break; }\n");
62test("switch ('' + i) {\n" +
63     "    case '0': case '1': log += '!'; break; }\n");
64test("switch (i) {\n" +
65     "    case 'ok' + i: case i - i: log += '!'; break; }\n");