michael@0: // Basic for-of test with Proxy. michael@0: michael@0: function iterableProxy(arr) { michael@0: return Proxy.create({ michael@0: getPropertyDescriptor: function (name) { michael@0: for (var obj = arr; obj; obj = Object.getPrototypeOf(obj)) { michael@0: var desc = Object.getOwnPropertyDescriptor(obj, name); michael@0: if (desc) michael@0: return desc; michael@0: } michael@0: return undefined; michael@0: } michael@0: }); michael@0: } michael@0: michael@0: var s = ''; michael@0: var arr = ['a', 'b', 'c', 'd']; michael@0: var p = iterableProxy(arr); michael@0: michael@0: // Test the same proxy twice. Each time through the loop, the proxy handler's michael@0: // getPropertyDescriptor method will be called 10 times (once for 'iterator', michael@0: // five times for 'length', and once for each of the four elements). michael@0: for (var i = 0; i < 2; i++) { michael@0: var j = 0; michael@0: for (var x of p) michael@0: assertEq(x, arr[j++]); michael@0: assertEq(j, arr.length); michael@0: }