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

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     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 }

mercurial