PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/js/src/jit-test/tests/debug/gc-03.js

http://github.com/zpao/v8monkey
JavaScript | 24 lines | 18 code | 4 blank | 2 comment | 0 complexity | 9828807cf1d0fd6b6a66dfc71cb4012e MD5 | raw file
 1// Storing a property on a Debugger.Object protects it from GC as long as the
 2// referent is alive.
 3
 4var g = newGlobal('new-compartment');
 5var N = g.N = 3;
 6var dbg = Debugger(g);
 7
 8var i = 0;
 9dbg.onDebuggerStatement = function (frame) {
10    frame.arguments[0].id = i++;
11};
12g.eval("function f(x) { debugger; }");
13g.eval("var arr = [], j; for (j = 0; j < N; j++) arr[j] = {};");
14g.eval("for (j = 0; j < N; j++) f(arr[j]);");
15assertEq(i, N);
16
17gc(); gc();
18
19i = 0;
20dbg.onDebuggerStatement = function (frame) {
21    assertEq(frame.arguments[0].id, i++)
22}
23g.eval("for (j = 0; j < N; j++) f(arr[j]);");
24assertEq(i, N);