michael@0: // A closure's .environment keeps the lexical environment alive even if the closure is destroyed. michael@0: michael@0: var N = 4; michael@0: var g = newGlobal(); michael@0: g.eval("function add(a) { return function (b) { return eval('a + b'); }; }"); michael@0: var dbg = new Debugger; michael@0: var gw = dbg.addDebuggee(g); michael@0: var aw = gw.getOwnPropertyDescriptor("add").value; michael@0: michael@0: // Create N closures and collect environments. michael@0: var arr = []; michael@0: for (var i = 0; i < N; i++) michael@0: arr[i] = aw.call(null, i).return.environment; michael@0: michael@0: // Test that they work now. michael@0: function check() { michael@0: for (var i = 0; i < N; i++) { michael@0: assertEq(arr[i].find("b"), null); michael@0: assertEq(arr[i].find("a"), arr[i]); michael@0: } michael@0: } michael@0: check(); michael@0: michael@0: // Test that they work after gc. michael@0: gc(); michael@0: gc({}); michael@0: g.gc(g); michael@0: check();