bindname.js (1107B)
1 // Test the scope chain walk. 2 function test1() { 3 var x = 0; 4 function f1(addprop) { 5 function f2() { 6 eval(""); 7 function f3() { 8 eval(""); 9 function f4() { 10 for (var i=0; i<100; i++) { 11 x = x + i; 12 } 13 } 14 return f4; 15 } 16 return f3(); 17 } 18 var g = f2(); 19 g(); 20 if (addprop) 21 eval("var a1 = 3; var x = 33;"); 22 g(); 23 if (addprop) 24 assertEq(x, 4983); 25 return f2(); 26 } 27 28 var g = f1(true); 29 g(); 30 g = f1(false); 31 eval("var y = 2020; var z = y + 3;"); 32 g(); 33 return x; 34 } 35 assertEq(test1(), 19800); 36 37 // Test with non-cacheable objects on the scope chain. 38 function test2(o) { 39 var x = 0; 40 with ({}) { 41 with (o) { 42 var f = function() { 43 for (var i=0; i<100; i++) { 44 x++; 45 } 46 }; 47 } 48 } 49 f(); 50 assertEq(o.x, 110); 51 assertEq(x, 0); 52 } 53 test2({x: 10});