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