Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // Basic for-of test with Proxy.
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 }
16 var s = '';
17 var arr = ['a', 'b', 'c', 'd'];
18 var p = iterableProxy(arr);
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 }