PageRenderTime 25ms CodeModel.GetById 9ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/zpao/v8monkey
JavaScript | 53 lines | 46 code | 6 blank | 1 comment | 1 complexity | e1928e85b93416cee76bbec26d4456cf MD5 | raw file
 1// getLineOffsets works with instructions reachable only by breaking out of a loop or switch.
 2
 3var g = newGlobal('new-compartment');
 4g.line0 = null;
 5var dbg = Debugger(g);
 6var where;
 7dbg.onDebuggerStatement = function (frame) {
 8    var s = frame.eval("f").return.script;
 9    var lineno = g.line0 + where;
10    var offs = s.getLineOffsets(lineno);
11    for (var i = 0; i < offs.length; i++) {
12        assertEq(s.getOffsetLine(offs[i]), lineno);
13        s.setBreakpoint(offs[i], {hit: function () { g.log += 'B'; }});
14    }
15    g.log += 'A';
16};
17
18function test(s) {
19    var count = (s.split(/\n/).length - 1); // number of newlines in s
20    g.log = '';
21    where = 3 + count + 1;
22    g.eval("line0 = Error().lineNumber;\n" +
23           "debugger;\n" +          // line0 + 1
24           "function f(i) {\n" +    // line0 + 2
25           s +                      // line0 + 3 ... line0 + where - 2
26           "    log += '?';\n" +    // line0 + where - 1
27           "    log += '!';\n" +    // line0 + where
28           "}\n");
29    g.f(0);
30    assertEq(g.log, 'A?B!');
31}
32
33test("i = 128;\n" +
34     "for (;;) {\n" +
35     "    var x = i - 10;;\n" +
36     "    if (x < 0)\n" +
37     "        break;\n" +
38     "    i >>= 2;\n" +
39     "}\n");
40
41test("while (true)\n" +
42     "    if (++i === 2) break;\n");
43
44test("do {\n" +
45     "    if (++i === 2) break;\n" +
46     "} while (true);\n");
47
48test("switch (i) {\n" +
49     "  case 2: return 7;\n" +
50     "  case 1: return 8;\n" +
51     "  case 0: break;\n" +
52     "  default: return -i;\n" +
53     "}\n");