diff -r 000000000000 -r 6474c204b198 js/src/jit-test/tests/for-of/proxy-1.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/js/src/jit-test/tests/for-of/proxy-1.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,28 @@ +// 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); +}