PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/js/src/jit-test/tests/debug/breakpoint-07.js

http://github.com/zpao/v8monkey
JavaScript | 30 lines | 26 code | 3 blank | 1 comment | 2 complexity | 85391ef160734cfc1ca1867264a1b1db MD5 | raw file
 1// Code runs fine if do-nothing breakpoints are set on every line.
 2
 3var g = newGlobal('new-compartment');
 4var src = ("var line0 = Error().lineNumber;\n" +
 5           "function gcd(a, b) {\n" +       // line0 + 1
 6           "    if (a > b)\n" +             // line0 + 2
 7           "            return gcd(b, a);\n" +  // line0 + 3
 8           "    var c = b % a;\n" +         // line0 + 4
 9           "    if (c === 0)\n" +           // line0 + 5
10           "            return a;\n" +          // line0 + 6
11           "    return gcd(c, a);\n" +      // line0 + 7
12           "}\n");                          // line0 + 8
13g.eval(src);
14
15var dbg = Debugger(g);
16var hits = 0 ;
17dbg.onDebuggerStatement = function (frame) {
18    var s = frame.eval("gcd").return.script;
19    var offs;
20    for (var lineno = g.line0 + 2; (offs = s.getLineOffsets(lineno)).length > 0; lineno++) {
21        for (var i = 0; i < offs.length; i++)
22            s.setBreakpoint(offs[i], {hit: function (f) { hits++; }});
23    }
24    assertEq(lineno > g.line0 + 7, true);
25    assertEq(lineno <= g.line0 + 9, true);
26};
27
28g.eval("debugger;");
29assertEq(g.gcd(31 * 7 * 5 * 3 * 2, 11 * 3 * 3 * 2), 6);
30assertEq(hits >= 18, true);