From e32265c896523f75098b1aa51d91508f21e03866 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 27 Jan 2023 21:30:28 +0000 Subject: [PATCH] LibJS: Add spec comments to BooleanConstructor --- .../LibJS/Runtime/BooleanConstructor.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp b/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp index 98fb7dba17..2e577f45a6 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Jack Karamanian + * Copyright (c) 2021-2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -31,8 +32,12 @@ void BooleanConstructor::initialize(Realm& realm) ThrowCompletionOr BooleanConstructor::call() { 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); } @@ -40,8 +45,14 @@ ThrowCompletionOr BooleanConstructor::call() ThrowCompletionOr> BooleanConstructor::construct(FunctionObject& new_target) { 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(vm, new_target, &Intrinsics::boolean_prototype, b)); }