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

LibJS: Add Object::set_prototype()

This is just factoring out step "9. Set O.[[Prototype]] to V." of
10.1.2 [[SetPrototypeOf]] into its own method so that we don't have to
use internal_set_prototype_of() for setting an object prototype in all
cases.
This commit is contained in:
Linus Groh 2021-10-02 14:20:39 +01:00
parent c500ebdcd5
commit 84c9f3e0d0
2 changed files with 14 additions and 5 deletions

View file

@ -546,11 +546,7 @@ ThrowCompletionOr<bool> Object::internal_set_prototype_of(Object* new_prototype)
}
// 9. Set O.[[Prototype]] to V.
auto& shape = this->shape();
if (shape.is_unique())
shape.set_prototype_without_transition(new_prototype);
else
m_shape = shape.create_prototype_transition(new_prototype);
set_prototype(new_prototype);
// 10. Return true.
return true;
@ -983,6 +979,17 @@ void Object::storage_delete(PropertyName const& property_name)
m_storage.remove(metadata->offset);
}
void Object::set_prototype(Object* new_prototype)
{
if (prototype() == new_prototype)
return;
auto& shape = this->shape();
if (shape.is_unique())
shape.set_prototype_without_transition(new_prototype);
else
m_shape = shape.create_prototype_transition(new_prototype);
}
void Object::define_native_accessor(PropertyName const& property_name, Function<Value(VM&, GlobalObject&)> getter, Function<Value(VM&, GlobalObject&)> setter, PropertyAttributes attribute)
{
auto& vm = this->vm();