michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: var gTestfile = 'destructuring-for-inof-__proto__.js'; michael@0: var BUGNUMBER = 963641; michael@0: var summary = michael@0: "__proto__ should work in destructuring patterns as the targets of " + michael@0: "for-in/for-of loops"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: function objectWithProtoProperty(v) michael@0: { michael@0: var obj = {}; michael@0: return Object.defineProperty(obj, "__proto__", michael@0: { michael@0: enumerable: true, michael@0: configurable: true, michael@0: writable: true, michael@0: value: v michael@0: }); michael@0: } michael@0: michael@0: function* objectWithProtoGenerator(v) michael@0: { michael@0: yield objectWithProtoProperty(v); michael@0: } michael@0: michael@0: function* identityGenerator(v) michael@0: { michael@0: yield v; michael@0: } michael@0: michael@0: for (var { __proto__: target } of objectWithProtoGenerator(null)) michael@0: assertEq(target, null); michael@0: michael@0: for ({ __proto__: target } of objectWithProtoGenerator("aacchhorrt")) michael@0: assertEq(target, "aacchhorrt"); michael@0: michael@0: for ({ __proto__: target } of identityGenerator(42)) michael@0: assertEq(target, Number.prototype); michael@0: michael@0: for (var { __proto__: target } in { prop: "kneedle" }) michael@0: assertEq(target, String.prototype); michael@0: michael@0: for ({ __proto__: target } in { prop: "snork" }) michael@0: assertEq(target, String.prototype); michael@0: michael@0: for ({ __proto__: target } in { prop: "ohia" }) michael@0: assertEq(target, String.prototype); michael@0: michael@0: function nested() michael@0: { michael@0: for (var { __proto__: target } of objectWithProtoGenerator(null)) michael@0: assertEq(target, null); michael@0: michael@0: for ({ __proto__: target } of objectWithProtoGenerator("aacchhorrt")) michael@0: assertEq(target, "aacchhorrt"); michael@0: michael@0: for ({ __proto__: target } of identityGenerator(42)) michael@0: assertEq(target, Number.prototype); michael@0: michael@0: for (var { __proto__: target } in { prop: "kneedle" }) michael@0: assertEq(target, String.prototype); michael@0: michael@0: for ({ __proto__: target } in { prop: "snork" }) michael@0: assertEq(target, String.prototype); michael@0: michael@0: for ({ __proto__: target } in { prop: "ohia" }) michael@0: assertEq(target, String.prototype); michael@0: } michael@0: nested(); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");