summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Frame-identity-03.js
blob: 19c62def8593182836a42580d03f7e43c3c93b2d (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
41
42
43
44
45
46
47
48
49
// Test that we create new Debugger.Frames and reuse old ones correctly with recursion.

var g = newGlobal();
g.debuggeeGlobal = this;
g.eval("(" + function () {
        function id(f) {
            return ("id" in f) ? f.id : (f.id = nextid++);
        }

        var dbg = new Debugger(debuggeeGlobal);
        dbg.onDebuggerStatement = function (frame) {
            var a = [];
            for (; frame; frame = frame.older)
                a.push(frame);
            var s = '';
            while (a.length)
                s += id(a.pop());
            results.push(s);
        };
    } + ")();");

function cons(a, b) {
    debugger;
    return [a, b];
}

function tree(n) {
    if (n < 2)
        return n;
    return cons(tree(n - 1), tree(n - 2));
}

g.eval("results = []; nextid = 0;");
debugger;
assertEq(g.results.join(","), "0");
assertEq(g.nextid, 1);

g.eval("results = [];");
tree(2);
assertEq(g.results.join(","), "012"); // 0=global, 1=tree, 2=cons

g.eval("results = []; nextid = 1;");
tree(3);
assertEq(g.results.join(","), "0123,014"); //0=global, 1=tree(3), 2=tree(2), 3=cons, 4=cons

g.eval("results = []; nextid = 1;");
tree(4);
// 0=global, 1=tree(4), 2=tree(3), 3=tree(2), 4=cons, tree(1), 5=cons, 6=tree(2), 7=cons, 8=cons
assertEq(g.results.join(","), "01234,0125,0167,018");