2020-04-06 22:51:16 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Jack Karamanian <karamanian.jack@gmail.com>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-06 22:51:16 -05:00
|
|
|
*/
|
|
|
|
|
2021-06-20 01:09:39 +01:00
|
|
|
#include <LibJS/Runtime/AbstractOperations.h>
|
2020-04-06 22:51:16 -05:00
|
|
|
#include <LibJS/Runtime/BooleanConstructor.h>
|
|
|
|
#include <LibJS/Runtime/BooleanObject.h>
|
2020-04-18 13:18:06 +02:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2020-04-06 22:51:16 -05:00
|
|
|
|
|
|
|
namespace JS {
|
2020-04-07 16:00:44 +01:00
|
|
|
|
2022-08-16 00:20:49 +01:00
|
|
|
BooleanConstructor::BooleanConstructor(Realm& realm)
|
|
|
|
: NativeFunction(vm().names.Boolean.as_string(), *realm.global_object().function_prototype())
|
2020-04-06 22:51:16 -05:00
|
|
|
{
|
2020-06-20 15:40:48 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 00:20:49 +01:00
|
|
|
void BooleanConstructor::initialize(Realm& realm)
|
2020-06-20 15:40:48 +02:00
|
|
|
{
|
2020-10-13 23:49:19 +02:00
|
|
|
auto& vm = this->vm();
|
2022-08-16 00:20:49 +01:00
|
|
|
NativeFunction::initialize(realm);
|
2021-06-19 00:38:41 +01:00
|
|
|
|
|
|
|
// 20.3.2.1 Boolean.prototype, https://tc39.es/ecma262/#sec-boolean.prototype
|
2022-08-16 00:20:49 +01:00
|
|
|
define_direct_property(vm.names.prototype, realm.global_object().boolean_prototype(), 0);
|
2021-06-19 00:38:41 +01:00
|
|
|
|
2021-07-06 02:15:08 +03:00
|
|
|
define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
|
2020-04-06 22:51:16 -05:00
|
|
|
}
|
|
|
|
|
2021-06-19 00:38:41 +01:00
|
|
|
// 20.3.1.1 Boolean ( value ), https://tc39.es/ecma262/#sec-boolean-constructor-boolean-value
|
2021-10-20 21:16:30 +01:00
|
|
|
ThrowCompletionOr<Value> BooleanConstructor::call()
|
2020-04-06 22:51:16 -05:00
|
|
|
{
|
2021-06-20 01:09:39 +01:00
|
|
|
auto& vm = this->vm();
|
|
|
|
|
|
|
|
auto b = vm.argument(0).to_boolean();
|
|
|
|
return Value(b);
|
2020-04-06 22:51:16 -05:00
|
|
|
}
|
|
|
|
|
2021-06-19 00:38:41 +01:00
|
|
|
// 20.3.1.1 Boolean ( value ), https://tc39.es/ecma262/#sec-boolean-constructor-boolean-value
|
2021-10-20 21:16:30 +01:00
|
|
|
ThrowCompletionOr<Object*> BooleanConstructor::construct(FunctionObject& new_target)
|
2020-04-06 22:51:16 -05:00
|
|
|
{
|
2021-06-20 01:09:39 +01:00
|
|
|
auto& vm = this->vm();
|
|
|
|
|
|
|
|
auto b = vm.argument(0).to_boolean();
|
2022-08-21 19:24:32 +01:00
|
|
|
return TRY(ordinary_create_from_constructor<BooleanObject>(vm, new_target, &GlobalObject::boolean_prototype, b));
|
2020-04-06 22:51:16 -05:00
|
|
|
}
|
2020-04-07 16:00:44 +01:00
|
|
|
|
2020-04-06 22:51:16 -05:00
|
|
|
}
|