diff options
33 files changed, 57 insertions, 45 deletions
diff --git a/Libraries/LibJS/Runtime/Array.cpp b/Libraries/LibJS/Runtime/Array.cpp index 9cb68a1b47..98948de0ca 100644 --- a/Libraries/LibJS/Runtime/Array.cpp +++ b/Libraries/LibJS/Runtime/Array.cpp @@ -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); } diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 56248b2e86..f5a1c9832a 100644 --- a/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -42,7 +42,7 @@ namespace JS { ArrayPrototype::ArrayPrototype(GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/BigIntObject.cpp b/Libraries/LibJS/Runtime/BigIntObject.cpp index 6955ac93ad..e3c0ef608c 100644 --- a/Libraries/LibJS/Runtime/BigIntObject.cpp +++ b/Libraries/LibJS/Runtime/BigIntObject.cpp @@ -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) { } diff --git a/Libraries/LibJS/Runtime/BigIntPrototype.cpp b/Libraries/LibJS/Runtime/BigIntPrototype.cpp index 92011cc931..0a0cac411b 100644 --- a/Libraries/LibJS/Runtime/BigIntPrototype.cpp +++ b/Libraries/LibJS/Runtime/BigIntPrototype.cpp @@ -33,7 +33,7 @@ namespace JS { BigIntPrototype::BigIntPrototype(GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/BooleanObject.cpp b/Libraries/LibJS/Runtime/BooleanObject.cpp index 2d2acb99de..14076c3861 100644 --- a/Libraries/LibJS/Runtime/BooleanObject.cpp +++ b/Libraries/LibJS/Runtime/BooleanObject.cpp @@ -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) { } diff --git a/Libraries/LibJS/Runtime/ConsoleObject.cpp b/Libraries/LibJS/Runtime/ConsoleObject.cpp index 3b6297cc78..77207062d5 100644 --- a/Libraries/LibJS/Runtime/ConsoleObject.cpp +++ b/Libraries/LibJS/Runtime/ConsoleObject.cpp @@ -36,7 +36,7 @@ namespace JS { ConsoleObject::ConsoleObject(GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/Date.cpp b/Libraries/LibJS/Runtime/Date.cpp index 1ddee4e411..3bc14b269b 100644 --- a/Libraries/LibJS/Runtime/Date.cpp +++ b/Libraries/LibJS/Runtime/Date.cpp @@ -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) { diff --git a/Libraries/LibJS/Runtime/DatePrototype.cpp b/Libraries/LibJS/Runtime/DatePrototype.cpp index 593baf579e..4101d1d1fe 100644 --- a/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -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()) { } diff --git a/Libraries/LibJS/Runtime/Error.cpp b/Libraries/LibJS/Runtime/Error.cpp index df2a79eec6..200f0055e1 100644 --- a/Libraries/LibJS/Runtime/Error.cpp +++ b/Libraries/LibJS/Runtime/Error.cpp @@ -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) { diff --git a/Libraries/LibJS/Runtime/ErrorPrototype.cpp b/Libraries/LibJS/Runtime/ErrorPrototype.cpp index 1c597b8762..6fb0879315 100644 --- a/Libraries/LibJS/Runtime/ErrorPrototype.cpp +++ b/Libraries/LibJS/Runtime/ErrorPrototype.cpp @@ -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() { } diff --git a/Libraries/LibJS/Runtime/Function.cpp b/Libraries/LibJS/Runtime/Function.cpp index 47dee74d7c..1f8266b3c1 100644 --- a/Libraries/LibJS/Runtime/Function.cpp +++ b/Libraries/LibJS/Runtime/Function.cpp @@ -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)) { diff --git a/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Libraries/LibJS/Runtime/FunctionPrototype.cpp index 34f39061e4..3d63513327 100644 --- a/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -39,7 +39,7 @@ namespace JS { FunctionPrototype::FunctionPrototype(GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp index 4ce48b3eb6..9dd2b4e9d7 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -64,7 +64,7 @@ namespace JS { GlobalObject::GlobalObject() - : Object(nullptr) + : Object(GlobalObjectTag::Tag) { } diff --git a/Libraries/LibJS/Runtime/JSONObject.cpp b/Libraries/LibJS/Runtime/JSONObject.cpp index ca20bbe4eb..50effdeda5 100644 --- a/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Libraries/LibJS/Runtime/JSONObject.cpp @@ -38,7 +38,7 @@ namespace JS { JSONObject::JSONObject(GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/MathObject.cpp b/Libraries/LibJS/Runtime/MathObject.cpp index 86759e63a9..ac104dedd0 100644 --- a/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Libraries/LibJS/Runtime/MathObject.cpp @@ -35,7 +35,7 @@ namespace JS { MathObject::MathObject(GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/NativeProperty.cpp b/Libraries/LibJS/Runtime/NativeProperty.cpp index 95cebf903b..0993a871e0 100644 --- a/Libraries/LibJS/Runtime/NativeProperty.cpp +++ b/Libraries/LibJS/Runtime/NativeProperty.cpp @@ -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)) { diff --git a/Libraries/LibJS/Runtime/NativeProperty.h b/Libraries/LibJS/Runtime/NativeProperty.h index 05e0102bc7..1cdcbc4f2d 100644 --- a/Libraries/LibJS/Runtime/NativeProperty.h +++ b/Libraries/LibJS/Runtime/NativeProperty.h @@ -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; diff --git a/Libraries/LibJS/Runtime/NumberObject.cpp b/Libraries/LibJS/Runtime/NumberObject.cpp index b97806e53e..1cded8c32e 100644 --- a/Libraries/LibJS/Runtime/NumberObject.cpp +++ b/Libraries/LibJS/Runtime/NumberObject.cpp @@ -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) { } diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index bfcaa7314e..1bd852c96e 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -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) diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h index ec434bf05b..e8b7771381 100644 --- a/Libraries/LibJS/Runtime/Object.h +++ b/Libraries/LibJS/Runtime/Object.h @@ -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); diff --git a/Libraries/LibJS/Runtime/ObjectPrototype.cpp b/Libraries/LibJS/Runtime/ObjectPrototype.cpp index 562f67846f..2d49372eb4 100644 --- a/Libraries/LibJS/Runtime/ObjectPrototype.cpp +++ b/Libraries/LibJS/Runtime/ObjectPrototype.cpp @@ -34,8 +34,8 @@ namespace JS { -ObjectPrototype::ObjectPrototype(GlobalObject&) - : Object(nullptr) +ObjectPrototype::ObjectPrototype(GlobalObject& global_object) + : Object(Object::ConstructWithoutPrototypeTag::Tag, global_object) { } diff --git a/Libraries/LibJS/Runtime/ProxyObject.cpp b/Libraries/LibJS/Runtime/ProxyObject.cpp index fb8b62e1fc..2f9809c4ad 100644 --- a/Libraries/LibJS/Runtime/ProxyObject.cpp +++ b/Libraries/LibJS/Runtime/ProxyObject.cpp @@ -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) { diff --git a/Libraries/LibJS/Runtime/ProxyPrototype.cpp b/Libraries/LibJS/Runtime/ProxyPrototype.cpp index aea07ebd10..ae8e1b8229 100644 --- a/Libraries/LibJS/Runtime/ProxyPrototype.cpp +++ b/Libraries/LibJS/Runtime/ProxyPrototype.cpp @@ -35,7 +35,7 @@ namespace JS { ProxyPrototype::ProxyPrototype(GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/ReflectObject.cpp b/Libraries/LibJS/Runtime/ReflectObject.cpp index 2c3cfa251c..b013591876 100644 --- a/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -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()) { } diff --git a/Libraries/LibJS/Runtime/RegExpObject.cpp b/Libraries/LibJS/Runtime/RegExpObject.cpp index 34f5e424b8..c9bd9da6b1 100644 --- a/Libraries/LibJS/Runtime/RegExpObject.cpp +++ b/Libraries/LibJS/Runtime/RegExpObject.cpp @@ -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) { diff --git a/Libraries/LibJS/Runtime/StringObject.cpp b/Libraries/LibJS/Runtime/StringObject.cpp index 4a86d7bc64..bb7c04f79a 100644 --- a/Libraries/LibJS/Runtime/StringObject.cpp +++ b/Libraries/LibJS/Runtime/StringObject.cpp @@ -40,7 +40,7 @@ StringObject* StringObject::create(GlobalObject& global_object, PrimitiveString& } StringObject::StringObject(PrimitiveString& string, Object& prototype) - : Object(&prototype) + : Object(prototype) , m_string(string) { } diff --git a/Libraries/LibJS/Runtime/SymbolObject.cpp b/Libraries/LibJS/Runtime/SymbolObject.cpp index e4d0ab3405..873a4d1b38 100644 --- a/Libraries/LibJS/Runtime/SymbolObject.cpp +++ b/Libraries/LibJS/Runtime/SymbolObject.cpp @@ -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) { } diff --git a/Libraries/LibJS/Runtime/SymbolPrototype.cpp b/Libraries/LibJS/Runtime/SymbolPrototype.cpp index 09238db05d..5531c221f8 100644 --- a/Libraries/LibJS/Runtime/SymbolPrototype.cpp +++ b/Libraries/LibJS/Runtime/SymbolPrototype.cpp @@ -40,7 +40,7 @@ namespace JS { SymbolPrototype::SymbolPrototype(GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp b/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp index ef5eb6f45d..99738b8f47 100644 --- a/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp +++ b/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp @@ -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); diff --git a/Libraries/LibWeb/Bindings/LocationObject.cpp b/Libraries/LibWeb/Bindings/LocationObject.cpp index bb14fa368b..09fa7be967 100644 --- a/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -36,7 +36,7 @@ namespace Web { namespace Bindings { LocationObject::LocationObject(JS::GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibWeb/Bindings/NavigatorObject.cpp b/Libraries/LibWeb/Bindings/NavigatorObject.cpp index 5dce741196..a2787a9c09 100644 --- a/Libraries/LibWeb/Bindings/NavigatorObject.cpp +++ b/Libraries/LibWeb/Bindings/NavigatorObject.cpp @@ -35,7 +35,7 @@ namespace Web { namespace Bindings { NavigatorObject::NavigatorObject(JS::GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } diff --git a/Libraries/LibWeb/Bindings/Wrapper.h b/Libraries/LibWeb/Bindings/Wrapper.h index 5fc5abc606..b24cadd02e 100644 --- a/Libraries/LibWeb/Bindings/Wrapper.h +++ b/Libraries/LibWeb/Bindings/Wrapper.h @@ -42,7 +42,7 @@ class Wrapper public: protected: explicit Wrapper(Object& prototype) - : Object(&prototype) + : Object(prototype) { } }; diff --git a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp index 85bc482422..32dee9d033 100644 --- a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp +++ b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp @@ -36,7 +36,7 @@ namespace Web { namespace Bindings { XMLHttpRequestPrototype::XMLHttpRequestPrototype(JS::GlobalObject& global_object) - : Object(global_object.object_prototype()) + : Object(*global_object.object_prototype()) { } |