michael@0: function g1(x) { michael@0: return x + 1; michael@0: } michael@0: function f1() { michael@0: var y = 0; michael@0: for (var i=0; i<100; i++) { michael@0: y += g1(g1(i)); michael@0: } michael@0: return y; michael@0: } michael@0: g1(10); michael@0: assertEq(f1(), 5150); michael@0: michael@0: x = 1; michael@0: other = newGlobal("same-compartment"); michael@0: other.eval("f = function() { return x; }; x = 2;"); michael@0: michael@0: h = other.f; michael@0: michael@0: function testOtherGlobal() { michael@0: var y = 0; michael@0: for (var i=0; i<100; i++) { michael@0: y += h(); michael@0: } michael@0: return y; michael@0: } michael@0: h(); michael@0: assertEq(testOtherGlobal(), 200); michael@0: michael@0: // Note: this test requires on On-Stack Invalidation. michael@0: f2 = function() { michael@0: return x; michael@0: } michael@0: function test2() { michael@0: var y = 0; michael@0: for (var i=0; i<50; i++) { michael@0: y += f2(); michael@0: } michael@0: return y; michael@0: } michael@0: assertEq(test2(), 50); michael@0: f2 = h; michael@0: assertEq(test2(), 100);