Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | var gTestfile = 'destructuring-for-inof-__proto__.js'; |
michael@0 | 7 | var BUGNUMBER = 963641; |
michael@0 | 8 | var summary = |
michael@0 | 9 | "__proto__ should work in destructuring patterns as the targets of " + |
michael@0 | 10 | "for-in/for-of loops"; |
michael@0 | 11 | |
michael@0 | 12 | print(BUGNUMBER + ": " + summary); |
michael@0 | 13 | |
michael@0 | 14 | /************** |
michael@0 | 15 | * BEGIN TEST * |
michael@0 | 16 | **************/ |
michael@0 | 17 | |
michael@0 | 18 | function objectWithProtoProperty(v) |
michael@0 | 19 | { |
michael@0 | 20 | var obj = {}; |
michael@0 | 21 | return Object.defineProperty(obj, "__proto__", |
michael@0 | 22 | { |
michael@0 | 23 | enumerable: true, |
michael@0 | 24 | configurable: true, |
michael@0 | 25 | writable: true, |
michael@0 | 26 | value: v |
michael@0 | 27 | }); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function* objectWithProtoGenerator(v) |
michael@0 | 31 | { |
michael@0 | 32 | yield objectWithProtoProperty(v); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function* identityGenerator(v) |
michael@0 | 36 | { |
michael@0 | 37 | yield v; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | for (var { __proto__: target } of objectWithProtoGenerator(null)) |
michael@0 | 41 | assertEq(target, null); |
michael@0 | 42 | |
michael@0 | 43 | for ({ __proto__: target } of objectWithProtoGenerator("aacchhorrt")) |
michael@0 | 44 | assertEq(target, "aacchhorrt"); |
michael@0 | 45 | |
michael@0 | 46 | for ({ __proto__: target } of identityGenerator(42)) |
michael@0 | 47 | assertEq(target, Number.prototype); |
michael@0 | 48 | |
michael@0 | 49 | for (var { __proto__: target } in { prop: "kneedle" }) |
michael@0 | 50 | assertEq(target, String.prototype); |
michael@0 | 51 | |
michael@0 | 52 | for ({ __proto__: target } in { prop: "snork" }) |
michael@0 | 53 | assertEq(target, String.prototype); |
michael@0 | 54 | |
michael@0 | 55 | for ({ __proto__: target } in { prop: "ohia" }) |
michael@0 | 56 | assertEq(target, String.prototype); |
michael@0 | 57 | |
michael@0 | 58 | function nested() |
michael@0 | 59 | { |
michael@0 | 60 | for (var { __proto__: target } of objectWithProtoGenerator(null)) |
michael@0 | 61 | assertEq(target, null); |
michael@0 | 62 | |
michael@0 | 63 | for ({ __proto__: target } of objectWithProtoGenerator("aacchhorrt")) |
michael@0 | 64 | assertEq(target, "aacchhorrt"); |
michael@0 | 65 | |
michael@0 | 66 | for ({ __proto__: target } of identityGenerator(42)) |
michael@0 | 67 | assertEq(target, Number.prototype); |
michael@0 | 68 | |
michael@0 | 69 | for (var { __proto__: target } in { prop: "kneedle" }) |
michael@0 | 70 | assertEq(target, String.prototype); |
michael@0 | 71 | |
michael@0 | 72 | for ({ __proto__: target } in { prop: "snork" }) |
michael@0 | 73 | assertEq(target, String.prototype); |
michael@0 | 74 | |
michael@0 | 75 | for ({ __proto__: target } in { prop: "ohia" }) |
michael@0 | 76 | assertEq(target, String.prototype); |
michael@0 | 77 | } |
michael@0 | 78 | nested(); |
michael@0 | 79 | |
michael@0 | 80 | /******************************************************************************/ |
michael@0 | 81 | |
michael@0 | 82 | if (typeof reportCompare === "function") |
michael@0 | 83 | reportCompare(true, true); |
michael@0 | 84 | |
michael@0 | 85 | print("Tests complete"); |