1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/for-of/proxy-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,28 @@ 1.4 +// Basic for-of test with Proxy. 1.5 + 1.6 +function iterableProxy(arr) { 1.7 + return Proxy.create({ 1.8 + getPropertyDescriptor: function (name) { 1.9 + for (var obj = arr; obj; obj = Object.getPrototypeOf(obj)) { 1.10 + var desc = Object.getOwnPropertyDescriptor(obj, name); 1.11 + if (desc) 1.12 + return desc; 1.13 + } 1.14 + return undefined; 1.15 + } 1.16 + }); 1.17 +} 1.18 + 1.19 +var s = ''; 1.20 +var arr = ['a', 'b', 'c', 'd']; 1.21 +var p = iterableProxy(arr); 1.22 + 1.23 +// Test the same proxy twice. Each time through the loop, the proxy handler's 1.24 +// getPropertyDescriptor method will be called 10 times (once for 'iterator', 1.25 +// five times for 'length', and once for each of the four elements). 1.26 +for (var i = 0; i < 2; i++) { 1.27 + var j = 0; 1.28 + for (var x of p) 1.29 + assertEq(x, arr[j++]); 1.30 + assertEq(j, arr.length); 1.31 +}