|
1 // Test adding hooks during dispatch. The behavior is deterministic and "nice", |
|
2 // but mainly what we are checking here is that we do not crash due to |
|
3 // modifying a data structure while we're iterating over it. |
|
4 |
|
5 var g = newGlobal(); |
|
6 var n = 0; |
|
7 var hits; |
|
8 |
|
9 function addDebugger() { |
|
10 var dbg = new Debugger(g); |
|
11 dbg.onDebuggerStatement = function (stack) { |
|
12 hits++; |
|
13 addDebugger(); |
|
14 }; |
|
15 } |
|
16 |
|
17 addDebugger(); // now there is one enabled Debugger |
|
18 hits = 0; |
|
19 g.eval("debugger;"); // after this there are two |
|
20 assertEq(hits, 1); |
|
21 |
|
22 hits = 0; |
|
23 g.eval("debugger;"); // after this there are four |
|
24 assertEq(hits, 2); |
|
25 |
|
26 hits = 0; |
|
27 g.eval("debugger;"); // after this there are eight |
|
28 assertEq(hits, 4); |
|
29 |
|
30 hits = 0; |
|
31 g.eval("debugger;"); |
|
32 assertEq(hits, 8); |