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

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 // Storing a Debugger.Object as a key in a WeakMap protects it from GC as long as
     2 // the referent is alive.
     4 var g = newGlobal();
     5 var N = g.N = 10;
     6 var dbg = Debugger(g);
     7 var cache = new WeakMap;
     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);
    18 gc(); gc();
    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);

mercurial