js/src/tests/js1_8_5/extensions/mutable-proto-special-form.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // Any copyright is dedicated to the Public Domain.
michael@0 2 // http://creativecommons.org/licenses/publicdomain/
michael@0 3
michael@0 4 //-----------------------------------------------------------------------------
michael@0 5 var BUGNUMBER = 948583;
michael@0 6 var summary =
michael@0 7 "Make __proto__ in object literals a special form not influenced by " +
michael@0 8 "|Object.prototype|";
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 passed = true;
michael@0 17
michael@0 18 function performProtoTests(msg)
michael@0 19 {
michael@0 20 print("Testing " + msg);
michael@0 21 assertEq(passed, true, "passed wrong at start of test set");
michael@0 22
michael@0 23 assertEq(Object.getPrototypeOf({ __proto__: null }), null);
michael@0 24 assertEq(Object.getPrototypeOf({ __proto__: undefined }), Object.prototype);
michael@0 25 assertEq(Object.getPrototypeOf({ __proto__: 17 }), Object.prototype);
michael@0 26
michael@0 27 var obj = {};
michael@0 28 assertEq(Object.getPrototypeOf({ __proto__: obj }), obj);
michael@0 29
michael@0 30 assertEq(passed, true, "passed wrong at end of test set");
michael@0 31 print("Tests of " + msg + " passed!");
michael@0 32 }
michael@0 33
michael@0 34 function poisonProto(obj)
michael@0 35 {
michael@0 36 Object.defineProperty(obj, "__proto__",
michael@0 37 {
michael@0 38 configurable: true,
michael@0 39 enumerable: true,
michael@0 40 set: function(v) { passed = false; },
michael@0 41 });
michael@0 42 }
michael@0 43
michael@0 44 performProtoTests("initial behavior");
michael@0 45
michael@0 46 var desc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__");
michael@0 47 var setProto = desc.set;
michael@0 48 delete Object.prototype.__proto__;
michael@0 49
michael@0 50 performProtoTests("behavior after Object.prototype.__proto__ deletion");
michael@0 51
michael@0 52 Object.defineProperty(Object.prototype, "__proto__",
michael@0 53 {
michael@0 54 configurable: true,
michael@0 55 enumerable: false,
michael@0 56 set: function(v) { passed = false; },
michael@0 57 });
michael@0 58
michael@0 59 performProtoTests("behavior after making Object.prototype.__proto__ a " +
michael@0 60 "custom setter");
michael@0 61
michael@0 62 Object.defineProperty(Object.prototype, "__proto__", { set: undefined });
michael@0 63
michael@0 64 performProtoTests("behavior after making Object.prototype.__proto__'s " +
michael@0 65 "[[Set]] === undefined");
michael@0 66
michael@0 67
michael@0 68 var superProto = Object.create(null);
michael@0 69 poisonProto(superProto);
michael@0 70 setProto.call(Object.prototype, superProto);
michael@0 71
michael@0 72 performProtoTests("behavior after mutating Object.prototype.[[Prototype]]");
michael@0 73
michael@0 74 // Note: The handler below will have to be updated to exempt a scriptable
michael@0 75 // getPrototypeOf trap (to instead consult the target whose [[Prototype]]
michael@0 76 // is safely non-recursive), if we ever implement one.
michael@0 77 var death = new Proxy(Object.create(null),
michael@0 78 new Proxy({}, { get: function() { passed = false; } }));
michael@0 79
michael@0 80 setProto.call(Object.prototype, death);
michael@0 81
michael@0 82 performProtoTests("behavior after making Object.prototype.[[Prototype]] a " +
michael@0 83 "proxy that throws for any access");
michael@0 84
michael@0 85
michael@0 86 if (typeof reportCompare === "function")
michael@0 87 reportCompare(true, true);
michael@0 88
michael@0 89 print("Tests complete");

mercurial