|
1 // |jit-test| debug |
|
2 // Test that we create new Debugger.Frames and reuse old ones correctly with recursion. |
|
3 |
|
4 var g = newGlobal(); |
|
5 g.debuggeeGlobal = this; |
|
6 g.eval("(" + function () { |
|
7 function id(f) { |
|
8 return ("id" in f) ? f.id : (f.id = nextid++); |
|
9 } |
|
10 |
|
11 var dbg = new Debugger(debuggeeGlobal); |
|
12 dbg.onDebuggerStatement = function (frame) { |
|
13 var a = []; |
|
14 for (; frame; frame = frame.older) |
|
15 a.push(frame); |
|
16 var s = ''; |
|
17 while (a.length) |
|
18 s += id(a.pop()); |
|
19 results.push(s); |
|
20 }; |
|
21 } + ")();"); |
|
22 |
|
23 function cons(a, b) { |
|
24 debugger; |
|
25 return [a, b]; |
|
26 } |
|
27 |
|
28 function tree(n) { |
|
29 if (n < 2) |
|
30 return n; |
|
31 return cons(tree(n - 1), tree(n - 2)); |
|
32 } |
|
33 |
|
34 g.eval("results = []; nextid = 0;"); |
|
35 debugger; |
|
36 assertEq(g.results.join(","), "0"); |
|
37 assertEq(g.nextid, 1); |
|
38 |
|
39 g.eval("results = [];"); |
|
40 tree(2); |
|
41 assertEq(g.results.join(","), "012"); // 0=global, 1=tree, 2=cons |
|
42 |
|
43 g.eval("results = []; nextid = 1;"); |
|
44 tree(3); |
|
45 assertEq(g.results.join(","), "0123,014"); //0=global, 1=tree(3), 2=tree(2), 3=cons, 4=cons |
|
46 |
|
47 g.eval("results = []; nextid = 1;"); |
|
48 tree(4); |
|
49 // 0=global, 1=tree(4), 2=tree(3), 3=tree(2), 4=cons, tree(1), 5=cons, 6=tree(2), 7=cons, 8=cons |
|
50 assertEq(g.results.join(","), "01234,0125,0167,018"); |