|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/licenses/publicdomain/ |
|
4 */ |
|
5 |
|
6 var gTestfile = 'proxy-__proto__.js'; |
|
7 var BUGNUMBER = 950407; |
|
8 var summary = "Behavior of __proto__ on ES6 proxies"; |
|
9 |
|
10 print(BUGNUMBER + ": " + summary); |
|
11 |
|
12 /************** |
|
13 * BEGIN TEST * |
|
14 **************/ |
|
15 |
|
16 var protoDesc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__"); |
|
17 var protoGetter = protoDesc.get; |
|
18 var protoSetter = protoDesc.set; |
|
19 |
|
20 function testProxy(target, initialProto) |
|
21 { |
|
22 print("Now testing behavior for new Proxy(" + ("" + target) + ", {})"); |
|
23 |
|
24 var pobj = new Proxy(target, {}); |
|
25 |
|
26 // Check [[Prototype]] before attempted mutation |
|
27 assertEq(Object.getPrototypeOf(pobj), initialProto); |
|
28 assertEq(protoGetter.call(pobj), initialProto); |
|
29 |
|
30 // Attempt [[Prototype]] mutation |
|
31 protoSetter.call(pobj, null); |
|
32 |
|
33 // Check [[Prototype]] after attempted mutation |
|
34 assertEq(Object.getPrototypeOf(pobj), null); |
|
35 assertEq(protoGetter.call(pobj), null); |
|
36 assertEq(Object.getPrototypeOf(target), null); |
|
37 } |
|
38 |
|
39 // Proxy object with non-null [[Prototype]] |
|
40 var nonNullProto = { toString: function() { return "non-null prototype"; } }; |
|
41 var target = Object.create(nonNullProto); |
|
42 testProxy(target, nonNullProto); |
|
43 |
|
44 // Proxy object with null [[Prototype]] |
|
45 target = Object.create(null); |
|
46 target.toString = function() { return "null prototype" }; |
|
47 testProxy(target, null); |
|
48 |
|
49 // Proxy function with [[Call]] |
|
50 var callForCallOnly = function () { }; |
|
51 callForCallOnly.toString = function() { return "callable target"; }; |
|
52 testProxy(callForCallOnly, Function.prototype); |
|
53 |
|
54 /******************************************************************************/ |
|
55 |
|
56 if (typeof reportCompare === "function") |
|
57 reportCompare(true, true); |
|
58 |
|
59 print("Tests complete"); |