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 = 'proxy-__proto__.js'; michael@0: var BUGNUMBER = 770344; michael@0: var summary = "Behavior of __proto__ on proxies"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var protoDesc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__"); michael@0: var protoGetter = protoDesc.get; michael@0: var protoSetter = protoDesc.set; michael@0: michael@0: function pp(arr) michael@0: { michael@0: return arr.map(function(v) { return "" + v; }).join(", "); michael@0: } michael@0: michael@0: function testProxy(creator, args, proto) michael@0: { michael@0: print("Now testing behavior for " + michael@0: "Proxy." + creator + "(" + pp(args) + ")"); michael@0: michael@0: var pobj = Proxy[creator].apply(Proxy, args); michael@0: michael@0: // Check [[Prototype]] before attempted mutation michael@0: assertEq(Object.getPrototypeOf(pobj), proto); michael@0: assertEq(protoGetter.call(pobj), proto); michael@0: michael@0: // Attempt [[Prototype]] mutation michael@0: protoSetter.call(pobj, null); michael@0: michael@0: // Check [[Prototype]] after attempted mutation michael@0: assertEq(Object.getPrototypeOf(pobj), null); michael@0: assertEq(protoGetter.call(pobj), null); michael@0: } michael@0: michael@0: // Proxy object with non-null [[Prototype]] michael@0: var nonNullProto = { toString: function() { return "non-null prototype"; } }; michael@0: var nonNullHandler = { toString: function() { return "non-null handler"; } }; michael@0: testProxy("create", [nonNullHandler, nonNullProto], nonNullProto); michael@0: michael@0: // Proxy object with null [[Prototype]] michael@0: var nullProto = null; michael@0: var nullHandler = { toString: function() { return "null handler"; } }; michael@0: testProxy("create", [nullHandler, nullProto], nullProto); michael@0: michael@0: // Proxy function with [[Call]] michael@0: var callForCallOnly = function () { }; michael@0: callForCallOnly.toString = function() { return "callForCallOnly"; }; michael@0: var callOnlyHandler = { toString: function() { return "call-only handler"; } }; michael@0: testProxy("createFunction", michael@0: [callOnlyHandler, callForCallOnly], Function.prototype); michael@0: michael@0: // Proxy function with [[Call]] and [[Construct]] michael@0: var callForCallConstruct = function() { }; michael@0: callForCallConstruct.toString = function() { return "call/construct call"; }; michael@0: var constructForCallConstruct = function() { }; michael@0: constructForCallConstruct.toString = michael@0: function() { return "call/construct construct"; }; michael@0: var handlerForCallConstruct = michael@0: { toString: function() { return "call/construct handler"; } }; michael@0: testProxy("createFunction", michael@0: [handlerForCallConstruct, michael@0: callForCallConstruct, michael@0: constructForCallConstruct], michael@0: Function.prototype); michael@0: michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");