diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/extensions/mutable-proto-special-form.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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"); |