summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Script-getBreakpoints-01.js
blob: ac143588fbb63bc336b17ace75e4e753119eabcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Basic Script.prototype.getBreakpoints tests.

var g = newGlobal({newCompartment: true});
g.eval("var line0 = Error().lineNumber;\n" +
       "function f(x) {\n" +        // line0 + 1
       "    if (x < 0)\n" +         // line0 + 2
       "        return -x;\n" +     // line0 + 3
       "    return x;\n" +
       "}");

var s;
var offsets = [];
var handlers = [];
var dbg = Debugger(g);
dbg.onDebuggerStatement = function (frame) {
    s = frame.eval("f").return.script;
    var off;

    for (var i = 0; i < 3; i++) {
        var off = s.getLineOffsets(g.line0 + 2 + i)[0];
        assertEq(typeof off, 'number');
        handlers[i] = {};
        s.setBreakpoint(off, handlers[i]);
        offsets[i] = off;
    }
};
g.eval("debugger;");

// getBreakpoints without an offset gets all breakpoints in the script.
var bps = s.getBreakpoints();
assertEq(bps.length, handlers.length);
for (var i = 0; i < bps.length; i++)
    assertEq(bps.indexOf(handlers[i]) !== -1, true);

// getBreakpoints with an offset finds only breakpoints at that offset.
for (var i = 0; i < offsets.length; i++) {
    var bps = s.getBreakpoints(offsets[i]);
    assertEq(bps.length, 1);
    assertEq(bps[0], handlers[i]);
}