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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/for-of/proxy-2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,29 @@
     1.4 +// Basic for-of test with Proxy whose iterator method is a generator.
     1.5 +
     1.6 +var arr = ['a', 'b', 'c', 'd'];
     1.7 +var proxy = Proxy.create({
     1.8 +    getPropertyDescriptor: function (name) {
     1.9 +        if (name == 'iterator') {
    1.10 +            return {
    1.11 +                configurable: false,
    1.12 +                enumerable: false,
    1.13 +                writeable: false,
    1.14 +                value:  function () {
    1.15 +                    for (var i = 0; i < arr.length; i++)
    1.16 +                        yield arr[i];
    1.17 +                }
    1.18 +            };
    1.19 +        }
    1.20 +
    1.21 +        // Otherwise, inherit the property from arr.
    1.22 +        for (var obj = arr; obj; obj = Object.getPrototypeOf(obj)) {
    1.23 +            var desc = Object.getOwnPropertyDescriptor(obj, name);
    1.24 +            if (desc)
    1.25 +                return desc;
    1.26 +        }
    1.27 +        return undefined;
    1.28 +    }
    1.29 +});
    1.30 +
    1.31 +for (var i = 0; i < 2; i++)
    1.32 +    assertEq([v for (v of proxy)].join(","), "a,b,c,d");

mercurial