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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/debug/gc-04.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,25 @@
     1.4 +// Storing a Debugger.Object as a key in a WeakMap protects it from GC as long as
     1.5 +// the referent is alive.
     1.6 +
     1.7 +var g = newGlobal();
     1.8 +var N = g.N = 10;
     1.9 +var dbg = Debugger(g);
    1.10 +var cache = new WeakMap;
    1.11 +
    1.12 +var i = 0;
    1.13 +dbg.onDebuggerStatement = function (frame) {
    1.14 +    cache.set(frame.arguments[0], i++);
    1.15 +};
    1.16 +g.eval("function f(x) { debugger; }");
    1.17 +g.eval("var arr = [], j; for (j = 0; j < N; j++) arr[j] = {};");
    1.18 +g.eval("for (j = 0; j < N; j++) f(arr[j]);");
    1.19 +assertEq(i, N);
    1.20 +
    1.21 +gc(); gc();
    1.22 +
    1.23 +i = 0;
    1.24 +dbg.onDebuggerStatement = function (frame) {
    1.25 +    assertEq(cache.get(frame.arguments[0]), i++)
    1.26 +};
    1.27 +g.eval("for (j = 0; j < N; j++) f(arr[j]);");
    1.28 +assertEq(i, N);

mercurial