1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:27:35 +00:00

LibJS: Disallow changing the prototype of non-extensible objects

Object::set_prototype() now returns a boolean indicating success.
Setting the prototype to an identical object is always considered
successful, even if the object is non-extensible.
This commit is contained in:
Linus Groh 2020-06-02 12:32:54 +01:00 committed by Andreas Kling
parent 8cf1ded478
commit b958e4f573
4 changed files with 22 additions and 6 deletions

View file

@ -11,7 +11,17 @@ try {
});
o = {};
assert(Object.setPrototypeOf(o, {}) === o);
p = {};
assert(Object.setPrototypeOf(o, p) === o);
Object.preventExtensions(o);
assertThrowsError(() => {
Object.setPrototypeOf(o, {});
}, {
error: TypeError,
message: "Can't set prototype of non-extensible object"
});
assert(Object.setPrototypeOf(o, p) === o);
console.log("PASS");
} catch (e) {