semantics-11.js (803B)
1 // for-of on a proxy causes a predictable sequence of trap calls. 2 3 load(libdir + "iteration.js"); 4 5 var s = ''; 6 7 var i = 0; 8 var next_fn = new Proxy(function() {}, { 9 apply() { 10 s += "n"; 11 if (i == 3) 12 return { value: undefined, done: true }; 13 return { value: i++, done: false }; 14 } 15 }); 16 17 var it = new Proxy({}, { 18 get(target, property, receiver) { 19 assertEq(property, "next"); 20 s += "N"; 21 return next_fn; 22 } 23 }); 24 25 var iterator_fn = new Proxy(function() {}, { 26 apply() { 27 s += 'i'; 28 return it; 29 } 30 }); 31 32 var obj = new Proxy({}, { 33 get: function (receiver, name) { 34 assertEq(name, Symbol.iterator); 35 s += "I"; 36 return iterator_fn; 37 } 38 }); 39 40 for (var v of obj) 41 s += v; 42 43 assertEq(s, 'IiNn0n1n2n');