mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:38:10 +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:
parent
8cf1ded478
commit
b958e4f573
4 changed files with 22 additions and 6 deletions
|
@ -69,15 +69,18 @@ const Object* Object::prototype() const
|
|||
return shape().prototype();
|
||||
}
|
||||
|
||||
void Object::set_prototype(Object* new_prototype)
|
||||
bool Object::set_prototype(Object* new_prototype)
|
||||
{
|
||||
if (prototype() == new_prototype)
|
||||
return;
|
||||
return true;
|
||||
if (!m_is_extensible)
|
||||
return false;
|
||||
if (shape().is_unique()) {
|
||||
shape().set_prototype_without_transition(new_prototype);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
m_shape = m_shape->create_prototype_transition(new_prototype);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Object::has_prototype(const Object* prototype) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue