michael@0: // The LHS of a for-loop is not bound to a particular scope until after the .next() method returns. michael@0: michael@0: var obj = {}; michael@0: michael@0: // Test 1 michael@0: function g() { michael@0: obj.x = 0; michael@0: yield 1; michael@0: } michael@0: var x = 2, n = 0; michael@0: with (obj) { michael@0: for (x of g()) // g().next() inserts a binding for x on obj michael@0: n++; michael@0: } michael@0: assertEq(x, 2); michael@0: assertEq(obj.x, 1); michael@0: assertEq(n, 1); michael@0: michael@0: // Test 2 michael@0: function h() { michael@0: delete obj.x; michael@0: yield 3; michael@0: } michael@0: n = 0; michael@0: with (obj) { michael@0: for (x of h()) // h().next() deletes the binding for x on obj michael@0: n++; michael@0: } michael@0: assertEq(x, 3); michael@0: assertEq("x" in obj, false); michael@0: assertEq(n, 1);