js/src/tests/ecma_5/extensions/destructuring-for-inof-__proto__.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/
     4  */
     6 var gTestfile = 'destructuring-for-inof-__proto__.js';
     7 var BUGNUMBER = 963641;
     8 var summary =
     9   "__proto__ should work in destructuring patterns as the targets of " +
    10   "for-in/for-of loops";
    12 print(BUGNUMBER + ": " + summary);
    14 /**************
    15  * BEGIN TEST *
    16  **************/
    18 function objectWithProtoProperty(v)
    19 {
    20   var obj = {};
    21   return Object.defineProperty(obj, "__proto__",
    22                                {
    23                                  enumerable: true,
    24                                  configurable: true,
    25                                  writable: true,
    26                                  value: v
    27                                });
    28 }
    30 function* objectWithProtoGenerator(v)
    31 {
    32   yield objectWithProtoProperty(v);
    33 }
    35 function* identityGenerator(v)
    36 {
    37   yield v;
    38 }
    40 for (var { __proto__: target } of objectWithProtoGenerator(null))
    41   assertEq(target, null);
    43 for ({ __proto__: target } of objectWithProtoGenerator("aacchhorrt"))
    44   assertEq(target, "aacchhorrt");
    46 for ({ __proto__: target } of identityGenerator(42))
    47   assertEq(target, Number.prototype);
    49 for (var { __proto__: target } in { prop: "kneedle" })
    50   assertEq(target, String.prototype);
    52 for ({ __proto__: target } in { prop: "snork" })
    53   assertEq(target, String.prototype);
    55 for ({ __proto__: target } in { prop: "ohia" })
    56   assertEq(target, String.prototype);
    58 function nested()
    59 {
    60   for (var { __proto__: target } of objectWithProtoGenerator(null))
    61     assertEq(target, null);
    63   for ({ __proto__: target } of objectWithProtoGenerator("aacchhorrt"))
    64     assertEq(target, "aacchhorrt");
    66   for ({ __proto__: target } of identityGenerator(42))
    67     assertEq(target, Number.prototype);
    69   for (var { __proto__: target } in { prop: "kneedle" })
    70     assertEq(target, String.prototype);
    72   for ({ __proto__: target } in { prop: "snork" })
    73     assertEq(target, String.prototype);
    75   for ({ __proto__: target } in { prop: "ohia" })
    76     assertEq(target, String.prototype);
    77 }
    78 nested();
    80 /******************************************************************************/
    82 if (typeof reportCompare === "function")
    83   reportCompare(true, true);
    85 print("Tests complete");

mercurial