mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
LibJS: Clarify Object (base class) construction somewhat
Divide the Object constructor into three variants: - The regular one (takes an Object& prototype) - One for use by GlobalObject - One for use by objects without a prototype (e.g ObjectPrototype)
This commit is contained in:
parent
fc4ed8d444
commit
ba641e97d9
33 changed files with 57 additions and 45 deletions
|
@ -82,18 +82,24 @@ PropertyDescriptor PropertyDescriptor::from_dictionary(Interpreter& interpreter,
|
|||
|
||||
Object* Object::create_empty(Interpreter&, GlobalObject& global_object)
|
||||
{
|
||||
return global_object.heap().allocate<Object>(global_object, global_object.object_prototype());
|
||||
return global_object.heap().allocate<Object>(global_object, *global_object.object_prototype());
|
||||
}
|
||||
|
||||
Object::Object(Object* prototype)
|
||||
Object::Object(GlobalObjectTag)
|
||||
{
|
||||
if (prototype) {
|
||||
m_shape = interpreter().global_object().empty_object_shape();
|
||||
set_prototype(prototype);
|
||||
} else {
|
||||
// This is the global object
|
||||
m_shape = interpreter().heap().allocate<Shape>(static_cast<GlobalObject&>(*this), static_cast<GlobalObject&>(*this));
|
||||
}
|
||||
// This is the global object
|
||||
m_shape = interpreter().heap().allocate<Shape>(static_cast<GlobalObject&>(*this), static_cast<GlobalObject&>(*this));
|
||||
}
|
||||
|
||||
Object::Object(ConstructWithoutPrototypeTag, GlobalObject& global_object)
|
||||
{
|
||||
m_shape = interpreter().heap().allocate<Shape>(global_object, global_object);
|
||||
}
|
||||
|
||||
Object::Object(Object& prototype)
|
||||
{
|
||||
m_shape = prototype.global_object().empty_object_shape();
|
||||
set_prototype(&prototype);
|
||||
}
|
||||
|
||||
void Object::initialize(Interpreter&, GlobalObject&)
|
||||
|
@ -698,7 +704,7 @@ bool Object::define_native_function(const FlyString& property_name, AK::Function
|
|||
|
||||
bool Object::define_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter, PropertyAttributes attribute)
|
||||
{
|
||||
return define_property(property_name, heap().allocate<NativeProperty>(global_object(), move(getter), move(setter)), attribute);
|
||||
return define_property(property_name, heap().allocate<NativeProperty>(global_object(), global_object(), move(getter), move(setter)), attribute);
|
||||
}
|
||||
|
||||
void Object::visit_children(Cell::Visitor& visitor)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue