diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/non262/extensions/mutable-proto-special-form.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/extensions/mutable-proto-special-form.js')
-rw-r--r-- | js/src/tests/non262/extensions/mutable-proto-special-form.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/js/src/tests/non262/extensions/mutable-proto-special-form.js b/js/src/tests/non262/extensions/mutable-proto-special-form.js new file mode 100644 index 0000000000..b196507f25 --- /dev/null +++ b/js/src/tests/non262/extensions/mutable-proto-special-form.js @@ -0,0 +1,91 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 948583; +var summary = + "Make __proto__ in object literals a special form not influenced by " + + "|Object.prototype|"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +var passed = true; + +function performProtoTests(msg) +{ + print("Testing " + msg); + assertEq(passed, true, "passed wrong at start of test set"); + + assertEq(Object.getPrototypeOf({ __proto__: null }), null); + assertEq(Object.getPrototypeOf({ __proto__: undefined }), Object.prototype); + assertEq(Object.getPrototypeOf({ __proto__: 17 }), Object.prototype); + + var obj = {}; + assertEq(Object.getPrototypeOf({ __proto__: obj }), obj); + + assertEq(passed, true, "passed wrong at end of test set"); + print("Tests of " + msg + " passed!"); +} + +function poisonProto(obj) +{ + Object.defineProperty(obj, "__proto__", + { + configurable: true, + enumerable: true, + set: function(v) { passed = false; }, + }); +} + +performProtoTests("initial behavior"); + +var desc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__"); +var setProto = desc.set; +delete Object.prototype.__proto__; + +performProtoTests("behavior after Object.prototype.__proto__ deletion"); + +Object.defineProperty(Object.prototype, "__proto__", + { + configurable: true, + enumerable: false, + set: function(v) { passed = false; }, + }); + +performProtoTests("behavior after making Object.prototype.__proto__ a " + + "custom setter"); + +Object.defineProperty(Object.prototype, "__proto__", { set: undefined }); + +performProtoTests("behavior after making Object.prototype.__proto__'s " + + "[[Set]] === undefined"); + +try +{ + var superProto = Object.create(null); + poisonProto(superProto); + setProto.call(Object.prototype, superProto); + + performProtoTests("behavior after mutating Object.prototype.[[Prototype]]"); + + // Note: The handler below will have to be updated to exempt a scriptable + // getPrototypeOf trap (to instead consult the target whose [[Prototype]] + // is safely non-recursive), if we ever implement one. + var death = new Proxy(Object.create(null), + new Proxy({}, { get: function() { passed = false; } })); + + setProto.call(Object.prototype, death); + + performProtoTests("behavior after making Object.prototype.[[Prototype]] a " + + "proxy that throws for any access"); +} +catch (e) {} + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("Tests complete"); |