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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // Basic for-of test with Proxy whose iterator method is a generator.
     3 var arr = ['a', 'b', 'c', 'd'];
     4 var proxy = Proxy.create({
     5     getPropertyDescriptor: function (name) {
     6         if (name == 'iterator') {
     7             return {
     8                 configurable: false,
     9                 enumerable: false,
    10                 writeable: false,
    11                 value:  function () {
    12                     for (var i = 0; i < arr.length; i++)
    13                         yield arr[i];
    14                 }
    15             };
    16         }
    18         // Otherwise, inherit the property from arr.
    19         for (var obj = arr; obj; obj = Object.getPrototypeOf(obj)) {
    20             var desc = Object.getOwnPropertyDescriptor(obj, name);
    21             if (desc)
    22                 return desc;
    23         }
    24         return undefined;
    25     }
    26 });
    28 for (var i = 0; i < 2; i++)
    29     assertEq([v for (v of proxy)].join(","), "a,b,c,d");

mercurial