js/src/tests/ecma_5/extensions/proxy-__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.

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 = 'proxy-__proto__.js';
michael@0 7 var BUGNUMBER = 770344;
michael@0 8 var summary = "Behavior of __proto__ on proxies";
michael@0 9
michael@0 10 print(BUGNUMBER + ": " + summary);
michael@0 11
michael@0 12 /**************
michael@0 13 * BEGIN TEST *
michael@0 14 **************/
michael@0 15
michael@0 16 var protoDesc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__");
michael@0 17 var protoGetter = protoDesc.get;
michael@0 18 var protoSetter = protoDesc.set;
michael@0 19
michael@0 20 function pp(arr)
michael@0 21 {
michael@0 22 return arr.map(function(v) { return "" + v; }).join(", ");
michael@0 23 }
michael@0 24
michael@0 25 function testProxy(creator, args, proto)
michael@0 26 {
michael@0 27 print("Now testing behavior for " +
michael@0 28 "Proxy." + creator + "(" + pp(args) + ")");
michael@0 29
michael@0 30 var pobj = Proxy[creator].apply(Proxy, args);
michael@0 31
michael@0 32 // Check [[Prototype]] before attempted mutation
michael@0 33 assertEq(Object.getPrototypeOf(pobj), proto);
michael@0 34 assertEq(protoGetter.call(pobj), proto);
michael@0 35
michael@0 36 // Attempt [[Prototype]] mutation
michael@0 37 protoSetter.call(pobj, null);
michael@0 38
michael@0 39 // Check [[Prototype]] after attempted mutation
michael@0 40 assertEq(Object.getPrototypeOf(pobj), null);
michael@0 41 assertEq(protoGetter.call(pobj), null);
michael@0 42 }
michael@0 43
michael@0 44 // Proxy object with non-null [[Prototype]]
michael@0 45 var nonNullProto = { toString: function() { return "non-null prototype"; } };
michael@0 46 var nonNullHandler = { toString: function() { return "non-null handler"; } };
michael@0 47 testProxy("create", [nonNullHandler, nonNullProto], nonNullProto);
michael@0 48
michael@0 49 // Proxy object with null [[Prototype]]
michael@0 50 var nullProto = null;
michael@0 51 var nullHandler = { toString: function() { return "null handler"; } };
michael@0 52 testProxy("create", [nullHandler, nullProto], nullProto);
michael@0 53
michael@0 54 // Proxy function with [[Call]]
michael@0 55 var callForCallOnly = function () { };
michael@0 56 callForCallOnly.toString = function() { return "callForCallOnly"; };
michael@0 57 var callOnlyHandler = { toString: function() { return "call-only handler"; } };
michael@0 58 testProxy("createFunction",
michael@0 59 [callOnlyHandler, callForCallOnly], Function.prototype);
michael@0 60
michael@0 61 // Proxy function with [[Call]] and [[Construct]]
michael@0 62 var callForCallConstruct = function() { };
michael@0 63 callForCallConstruct.toString = function() { return "call/construct call"; };
michael@0 64 var constructForCallConstruct = function() { };
michael@0 65 constructForCallConstruct.toString =
michael@0 66 function() { return "call/construct construct"; };
michael@0 67 var handlerForCallConstruct =
michael@0 68 { toString: function() { return "call/construct handler"; } };
michael@0 69 testProxy("createFunction",
michael@0 70 [handlerForCallConstruct,
michael@0 71 callForCallConstruct,
michael@0 72 constructForCallConstruct],
michael@0 73 Function.prototype);
michael@0 74
michael@0 75
michael@0 76 /******************************************************************************/
michael@0 77
michael@0 78 if (typeof reportCompare === "function")
michael@0 79 reportCompare(true, true);
michael@0 80
michael@0 81 print("Tests complete");

mercurial