michael@0: // for-of on a proxy causes a predictable sequence of trap calls. michael@0: michael@0: load(libdir + "iteration.js"); michael@0: michael@0: var s = ''; michael@0: michael@0: var i = 0; michael@0: var next_fn = Proxy.createFunction({}, function () { michael@0: s += "n"; michael@0: if (i == 3) michael@0: return { value: undefined, done: true }; michael@0: return { value: i++, done: false }; michael@0: }); michael@0: michael@0: var it = Proxy.create({ michael@0: get: function (receiver, name) { michael@0: if (name == 'toSource') { michael@0: s += '?'; michael@0: return function () 'it'; michael@0: } michael@0: assertEq(name, "next"); michael@0: s += "N"; michael@0: return next_fn; michael@0: } michael@0: }); michael@0: michael@0: var iterator_fn = Proxy.createFunction({}, function () { michael@0: s += 'i'; michael@0: return it; michael@0: }); michael@0: michael@0: var obj = Proxy.create({ michael@0: get: function (receiver, name) { michael@0: assertEq(name, std_iterator); michael@0: s += "I"; michael@0: return iterator_fn; michael@0: } michael@0: }); michael@0: michael@0: for (var v of obj) michael@0: s += v; michael@0: michael@0: assertEq(s, 'IiNn0Nn1Nn2Nn');