value-done-access.js (508B)
1 // Test that each yield* loop just checks "done", and "value" is only 2 // fetched once at the end. 3 4 load(libdir + 'iteration.js'); 5 6 var log = ""; 7 8 function Iter(val, count) { 9 function next() { 10 return { 11 get done() { log += "d"; return count-- == 0; }, 12 get value() { log += "v"; return val; } 13 } 14 } 15 16 this[Symbol.iterator] = function() { return this; }; 17 this.next = next; 18 } 19 20 for (var x of new Iter(42, 5)) 21 assertEq(x, 42); 22 23 assertEq(log, "dvdvdvdvdvd");