mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibJS: Pass prototype to BooleanObject constructor
This commit is contained in:
parent
298c606200
commit
2a15323029
Notes:
sideshowbarker
2024-07-19 07:31:38 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2a153230299
5 changed files with 15 additions and 8 deletions
|
@ -50,8 +50,7 @@ Value BooleanConstructor::call(Interpreter& interpreter)
|
|||
|
||||
Value BooleanConstructor::construct(Interpreter& interpreter)
|
||||
{
|
||||
auto* bool_object = interpreter.heap().allocate<BooleanObject>(interpreter.argument(0).to_boolean());
|
||||
return Value(bool_object);
|
||||
return BooleanObject::create(interpreter.global_object(), interpreter.argument(0).to_boolean());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,13 +26,20 @@
|
|||
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/BooleanObject.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
BooleanObject::BooleanObject(bool value)
|
||||
BooleanObject* BooleanObject::create(GlobalObject& global_object, bool value)
|
||||
{
|
||||
auto& interpreter = global_object.interpreter();
|
||||
return interpreter.heap().allocate<BooleanObject>(value, *interpreter.boolean_prototype());
|
||||
}
|
||||
|
||||
BooleanObject::BooleanObject(bool value, Object& prototype)
|
||||
: m_value(value)
|
||||
{
|
||||
set_prototype(interpreter().boolean_prototype());
|
||||
set_prototype(&prototype);
|
||||
}
|
||||
|
||||
BooleanObject::~BooleanObject()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<BooleanObject>(m_value.as_bool);
|
||||
return BooleanObject::create(heap.interpreter().global_object(), m_value.as_bool);
|
||||
|
||||
if (is_null() || is_undefined()) {
|
||||
heap.interpreter().throw_exception<TypeError>("ToObject on null or undefined.");
|
||||
|
|
Loading…
Add table
Reference in a new issue