js/src/jit-test/tests/for-of/proxy-1.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:9f16b7e71d23
1 // Basic for-of test with Proxy.
2
3 function iterableProxy(arr) {
4 return Proxy.create({
5 getPropertyDescriptor: function (name) {
6 for (var obj = arr; obj; obj = Object.getPrototypeOf(obj)) {
7 var desc = Object.getOwnPropertyDescriptor(obj, name);
8 if (desc)
9 return desc;
10 }
11 return undefined;
12 }
13 });
14 }
15
16 var s = '';
17 var arr = ['a', 'b', 'c', 'd'];
18 var p = iterableProxy(arr);
19
20 // Test the same proxy twice. Each time through the loop, the proxy handler's
21 // getPropertyDescriptor method will be called 10 times (once for 'iterator',
22 // five times for 'length', and once for each of the four elements).
23 for (var i = 0; i < 2; i++) {
24 var j = 0;
25 for (var x of p)
26 assertEq(x, arr[j++]);
27 assertEq(j, arr.length);
28 }

mercurial