michael@0: // The LHS of a for-of loop is not evaluated until after the .next() method returns. michael@0: michael@0: var s; michael@0: function f() { michael@0: s += 'f'; michael@0: return {}; michael@0: } michael@0: michael@0: // Test 1: .next() throws StopIteration right away. f is never called. michael@0: s = ''; michael@0: for (f().x of []) michael@0: s += '.'; michael@0: assertEq(s, ''); michael@0: michael@0: // Test 2: check proper interleaving of f calls, iterator.next() calls, and the loop body. michael@0: function g() { michael@0: s += 'g'; michael@0: yield 0; michael@0: s += 'g'; michael@0: yield 1; michael@0: s += 'g'; michael@0: } michael@0: for (f().x of g()) michael@0: s += '.'; michael@0: assertEq(s, 'gf.gf.g');