mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:07:36 +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:
parent
c500ebdcd5
commit
84c9f3e0d0
2 changed files with 14 additions and 5 deletions
|
@ -546,11 +546,7 @@ ThrowCompletionOr<bool> Object::internal_set_prototype_of(Object* new_prototype)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9. Set O.[[Prototype]] to V.
|
// 9. Set O.[[Prototype]] to V.
|
||||||
auto& shape = this->shape();
|
set_prototype(new_prototype);
|
||||||
if (shape.is_unique())
|
|
||||||
shape.set_prototype_without_transition(new_prototype);
|
|
||||||
else
|
|
||||||
m_shape = shape.create_prototype_transition(new_prototype);
|
|
||||||
|
|
||||||
// 10. Return true.
|
// 10. Return true.
|
||||||
return true;
|
return true;
|
||||||
|
@ -983,6 +979,17 @@ void Object::storage_delete(PropertyName const& property_name)
|
||||||
m_storage.remove(metadata->offset);
|
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)
|
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();
|
auto& vm = this->vm();
|
||||||
|
|
|
@ -171,6 +171,8 @@ protected:
|
||||||
explicit Object(GlobalObjectTag);
|
explicit Object(GlobalObjectTag);
|
||||||
Object(ConstructWithoutPrototypeTag, GlobalObject&);
|
Object(ConstructWithoutPrototypeTag, GlobalObject&);
|
||||||
|
|
||||||
|
void set_prototype(Object*);
|
||||||
|
|
||||||
// [[Extensible]]
|
// [[Extensible]]
|
||||||
bool m_is_extensible { true };
|
bool m_is_extensible { true };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue