mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
LibJS: Add spec comments to BooleanConstructor
This commit is contained in:
parent
02808948ec
commit
e32265c896
1 changed files with 13 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Jack Karamanian <karamanian.jack@gmail.com>
|
* Copyright (c) 2020, Jack Karamanian <karamanian.jack@gmail.com>
|
||||||
|
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -31,8 +32,12 @@ void BooleanConstructor::initialize(Realm& realm)
|
||||||
ThrowCompletionOr<Value> BooleanConstructor::call()
|
ThrowCompletionOr<Value> BooleanConstructor::call()
|
||||||
{
|
{
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
|
auto value = vm.argument(0);
|
||||||
|
|
||||||
auto b = vm.argument(0).to_boolean();
|
// 1. Let b be ToBoolean(value).
|
||||||
|
auto b = value.to_boolean();
|
||||||
|
|
||||||
|
// 2. If NewTarget is undefined, return b.
|
||||||
return Value(b);
|
return Value(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +45,14 @@ ThrowCompletionOr<Value> BooleanConstructor::call()
|
||||||
ThrowCompletionOr<NonnullGCPtr<Object>> BooleanConstructor::construct(FunctionObject& new_target)
|
ThrowCompletionOr<NonnullGCPtr<Object>> BooleanConstructor::construct(FunctionObject& new_target)
|
||||||
{
|
{
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
|
auto value = vm.argument(0);
|
||||||
|
|
||||||
auto b = vm.argument(0).to_boolean();
|
// 1. Let b be ToBoolean(value).
|
||||||
|
auto b = value.to_boolean();
|
||||||
|
|
||||||
|
// 3. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Boolean.prototype%", « [[BooleanData]] »).
|
||||||
|
// 4. Set O.[[BooleanData]] to b.
|
||||||
|
// 5. Return O.
|
||||||
return TRY(ordinary_create_from_constructor<BooleanObject>(vm, new_target, &Intrinsics::boolean_prototype, b));
|
return TRY(ordinary_create_from_constructor<BooleanObject>(vm, new_target, &Intrinsics::boolean_prototype, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue