|
1 // Storing a Debugger.Object as a key in a WeakMap protects it from GC as long as |
|
2 // the referent is alive. |
|
3 |
|
4 var g = newGlobal(); |
|
5 var N = g.N = 10; |
|
6 var dbg = Debugger(g); |
|
7 var cache = new WeakMap; |
|
8 |
|
9 var i = 0; |
|
10 dbg.onDebuggerStatement = function (frame) { |
|
11 cache.set(frame.arguments[0], i++); |
|
12 }; |
|
13 g.eval("function f(x) { debugger; }"); |
|
14 g.eval("var arr = [], j; for (j = 0; j < N; j++) arr[j] = {};"); |
|
15 g.eval("for (j = 0; j < N; j++) f(arr[j]);"); |
|
16 assertEq(i, N); |
|
17 |
|
18 gc(); gc(); |
|
19 |
|
20 i = 0; |
|
21 dbg.onDebuggerStatement = function (frame) { |
|
22 assertEq(cache.get(frame.arguments[0]), i++) |
|
23 }; |
|
24 g.eval("for (j = 0; j < N; j++) f(arr[j]);"); |
|
25 assertEq(i, N); |