mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:08:13 +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
|
@ -40,7 +40,7 @@ Array* Array::create(GlobalObject& global_object)
|
|||
}
|
||||
|
||||
Array::Array(Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
{
|
||||
define_native_property("length", length_getter, length_setter, Attribute::Writable);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
namespace JS {
|
||||
|
||||
ArrayPrototype::ArrayPrototype(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ BigIntObject* BigIntObject::create(GlobalObject& global_object, BigInt& bigint)
|
|||
}
|
||||
|
||||
BigIntObject::BigIntObject(BigInt& bigint, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_bigint(bigint)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
namespace JS {
|
||||
|
||||
BigIntPrototype::BigIntPrototype(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ BooleanObject* BooleanObject::create(GlobalObject& global_object, bool value)
|
|||
}
|
||||
|
||||
BooleanObject::BooleanObject(bool value, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
namespace JS {
|
||||
|
||||
ConsoleObject::ConsoleObject(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ Date* Date::create(GlobalObject& global_object, Core::DateTime datetime, u16 mil
|
|||
}
|
||||
|
||||
Date::Date(Core::DateTime datetime, u16 milliseconds, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_datetime(datetime)
|
||||
, m_milliseconds(milliseconds)
|
||||
{
|
||||
|
|
|
@ -49,7 +49,7 @@ static Date* typed_this(Interpreter& interpreter, GlobalObject& global_object)
|
|||
}
|
||||
|
||||
DatePrototype::DatePrototype(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ Error* Error::create(GlobalObject& global_object, const FlyString& name, const S
|
|||
}
|
||||
|
||||
Error::Error(const FlyString& name, const String& message, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_name(name)
|
||||
, m_message(message)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
namespace JS {
|
||||
|
||||
ErrorPrototype::ErrorPrototype(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string)
|
|||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||
PrototypeName::PrototypeName(GlobalObject& global_object) \
|
||||
: Object(global_object.error_prototype()) \
|
||||
: Object(*global_object.error_prototype()) \
|
||||
{ \
|
||||
} \
|
||||
PrototypeName::~PrototypeName() { }
|
||||
|
|
|
@ -37,7 +37,7 @@ Function::Function(Object& prototype)
|
|||
}
|
||||
|
||||
Function::Function(Object& prototype, Value bound_this, Vector<Value> bound_arguments)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_bound_this(bound_this)
|
||||
, m_bound_arguments(move(bound_arguments))
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
namespace JS {
|
||||
|
||||
FunctionPrototype::FunctionPrototype(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
namespace JS {
|
||||
|
||||
GlobalObject::GlobalObject()
|
||||
: Object(nullptr)
|
||||
: Object(GlobalObjectTag::Tag)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
namespace JS {
|
||||
|
||||
JSONObject::JSONObject(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
namespace JS {
|
||||
|
||||
MathObject::MathObject(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
NativeProperty::NativeProperty(AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter)
|
||||
: Object(nullptr)
|
||||
NativeProperty::NativeProperty(GlobalObject& global_object, AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter)
|
||||
: Object(Object::ConstructWithoutPrototypeTag::Tag, global_object)
|
||||
, m_getter(move(getter))
|
||||
, m_setter(move(setter))
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@ class NativeProperty final : public Object {
|
|||
JS_OBJECT(NativeProperty, Object);
|
||||
|
||||
public:
|
||||
NativeProperty(AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter);
|
||||
NativeProperty(GlobalObject&, AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter);
|
||||
virtual ~NativeProperty() override;
|
||||
|
||||
Value get(Interpreter&, GlobalObject&) const;
|
||||
|
|
|
@ -39,7 +39,7 @@ NumberObject* NumberObject::create(GlobalObject& global_object, double value)
|
|||
}
|
||||
|
||||
NumberObject::NumberObject(double value, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -62,7 +62,7 @@ class Object : public Cell {
|
|||
public:
|
||||
static Object* create_empty(Interpreter&, GlobalObject&);
|
||||
|
||||
explicit Object(Object* prototype);
|
||||
explicit Object(Object& prototype);
|
||||
virtual void initialize(Interpreter&, GlobalObject&) override;
|
||||
virtual ~Object();
|
||||
|
||||
|
@ -142,6 +142,12 @@ public:
|
|||
|
||||
Value invoke(const FlyString& property_name, Optional<MarkedValueList> arguments = {});
|
||||
|
||||
protected:
|
||||
enum class GlobalObjectTag { Tag };
|
||||
enum class ConstructWithoutPrototypeTag { Tag };
|
||||
explicit Object(GlobalObjectTag);
|
||||
Object(ConstructWithoutPrototypeTag, GlobalObject&);
|
||||
|
||||
private:
|
||||
virtual Value get_by_index(u32 property_index) const;
|
||||
virtual bool put_by_index(u32 property_index, Value);
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
ObjectPrototype::ObjectPrototype(GlobalObject&)
|
||||
: Object(nullptr)
|
||||
ObjectPrototype::ObjectPrototype(GlobalObject& global_object)
|
||||
: Object(Object::ConstructWithoutPrototypeTag::Tag, global_object)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ ProxyObject* ProxyObject::create(GlobalObject& global_object, Object& target, Ob
|
|||
}
|
||||
|
||||
ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_target(target)
|
||||
, m_handler(handler)
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
namespace JS {
|
||||
|
||||
ProxyPrototype::ProxyPrototype(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ static void prepare_arguments_list(Interpreter& interpreter, Value value, Marked
|
|||
}
|
||||
|
||||
ReflectObject::ReflectObject(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ RegExpObject* RegExpObject::create(GlobalObject& global_object, String content,
|
|||
}
|
||||
|
||||
RegExpObject::RegExpObject(String content, String flags, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_content(content)
|
||||
, m_flags(flags)
|
||||
{
|
||||
|
|
|
@ -40,7 +40,7 @@ StringObject* StringObject::create(GlobalObject& global_object, PrimitiveString&
|
|||
}
|
||||
|
||||
StringObject::StringObject(PrimitiveString& string, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_string(string)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ SymbolObject* SymbolObject::create(GlobalObject& global_object, Symbol& primitiv
|
|||
}
|
||||
|
||||
SymbolObject::SymbolObject(Symbol& symbol, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_symbol(symbol)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
namespace JS {
|
||||
|
||||
SymbolPrototype::SymbolPrototype(GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ Uint8ClampedArray* Uint8ClampedArray::create(GlobalObject& global_object, u32 le
|
|||
}
|
||||
|
||||
Uint8ClampedArray::Uint8ClampedArray(u32 length, Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
, m_length(length)
|
||||
{
|
||||
define_native_property("length", length_getter, nullptr);
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Web {
|
|||
namespace Bindings {
|
||||
|
||||
LocationObject::LocationObject(JS::GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Web {
|
|||
namespace Bindings {
|
||||
|
||||
NavigatorObject::NavigatorObject(JS::GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class Wrapper
|
|||
public:
|
||||
protected:
|
||||
explicit Wrapper(Object& prototype)
|
||||
: Object(&prototype)
|
||||
: Object(prototype)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Web {
|
|||
namespace Bindings {
|
||||
|
||||
XMLHttpRequestPrototype::XMLHttpRequestPrototype(JS::GlobalObject& global_object)
|
||||
: Object(global_object.object_prototype())
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue