michael@0: // Test the scope chain walk. michael@0: function test1() { michael@0: var x = 0; michael@0: function f1(addprop) { michael@0: function f2() { michael@0: eval(""); michael@0: function f3() { michael@0: eval(""); michael@0: function f4() { michael@0: for (var i=0; i<100; i++) { michael@0: x = x + i; michael@0: } michael@0: } michael@0: return f4; michael@0: } michael@0: return f3(); michael@0: } michael@0: var g = f2(); michael@0: g(); michael@0: if (addprop) michael@0: eval("var a1 = 3; var x = 33;"); michael@0: g(); michael@0: if (addprop) michael@0: assertEq(x, 4983); michael@0: return f2(); michael@0: } michael@0: michael@0: var g = f1(true); michael@0: g(); michael@0: g = f1(false); michael@0: eval("var y = 2020; var z = y + 3;"); michael@0: g(); michael@0: return x; michael@0: } michael@0: assertEq(test1(), 19800); michael@0: michael@0: // Test with non-cacheable objects on the scope chain. michael@0: function test2(o) { michael@0: var x = 0; michael@0: with ({}) { michael@0: with (o) { michael@0: var f = function() { michael@0: for (var i=0; i<100; i++) { michael@0: x++; michael@0: } michael@0: }; michael@0: } michael@0: } michael@0: f(); michael@0: assertEq(o.x, 110); michael@0: assertEq(x, 0); michael@0: } michael@0: test2({x: 10});