diff --git a/Libraries/LibJS/Runtime/BooleanConstructor.cpp b/Libraries/LibJS/Runtime/BooleanConstructor.cpp index 3f5d54a68a..4ffdf9071d 100644 --- a/Libraries/LibJS/Runtime/BooleanConstructor.cpp +++ b/Libraries/LibJS/Runtime/BooleanConstructor.cpp @@ -50,8 +50,7 @@ Value BooleanConstructor::call(Interpreter& interpreter) Value BooleanConstructor::construct(Interpreter& interpreter) { - auto* bool_object = interpreter.heap().allocate(interpreter.argument(0).to_boolean()); - return Value(bool_object); + return BooleanObject::create(interpreter.global_object(), interpreter.argument(0).to_boolean()); } } diff --git a/Libraries/LibJS/Runtime/BooleanObject.cpp b/Libraries/LibJS/Runtime/BooleanObject.cpp index c0ac80d30b..f823759582 100644 --- a/Libraries/LibJS/Runtime/BooleanObject.cpp +++ b/Libraries/LibJS/Runtime/BooleanObject.cpp @@ -26,13 +26,20 @@ #include #include +#include namespace JS { -BooleanObject::BooleanObject(bool value) +BooleanObject* BooleanObject::create(GlobalObject& global_object, bool value) +{ + auto& interpreter = global_object.interpreter(); + return interpreter.heap().allocate(value, *interpreter.boolean_prototype()); +} + +BooleanObject::BooleanObject(bool value, Object& prototype) : m_value(value) { - set_prototype(interpreter().boolean_prototype()); + set_prototype(&prototype); } BooleanObject::~BooleanObject() diff --git a/Libraries/LibJS/Runtime/BooleanObject.h b/Libraries/LibJS/Runtime/BooleanObject.h index a27a129f61..c09a6b0f9d 100644 --- a/Libraries/LibJS/Runtime/BooleanObject.h +++ b/Libraries/LibJS/Runtime/BooleanObject.h @@ -31,7 +31,9 @@ namespace JS { class BooleanObject : public Object { public: - explicit BooleanObject(bool); + static BooleanObject* create(GlobalObject&, bool); + + BooleanObject(bool, Object& prototype); virtual ~BooleanObject() override; virtual Value value_of() const override diff --git a/Libraries/LibJS/Runtime/BooleanPrototype.cpp b/Libraries/LibJS/Runtime/BooleanPrototype.cpp index 84b9639a60..b4f4f36ded 100644 --- a/Libraries/LibJS/Runtime/BooleanPrototype.cpp +++ b/Libraries/LibJS/Runtime/BooleanPrototype.cpp @@ -32,9 +32,8 @@ namespace JS { BooleanPrototype::BooleanPrototype() - : BooleanObject(false) + : BooleanObject(false, *interpreter().object_prototype()) { - set_prototype(interpreter().object_prototype()); put_native_function("toString", to_string); put_native_function("valueOf", value_of); } diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index a5a6adba49..08fe1d67b0 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -119,7 +119,7 @@ Object* Value::to_object(Heap& heap) const return NumberObject::create(heap.interpreter().global_object(), m_value.as_double); if (is_boolean()) - return heap.allocate(m_value.as_bool); + return BooleanObject::create(heap.interpreter().global_object(), m_value.as_bool); if (is_null() || is_undefined()) { heap.interpreter().throw_exception("ToObject on null or undefined.");