xref: /third_party/node/deps/v8/src/builtins/boolean.tq (revision 1cb0ef41)
11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cinamespace boolean {
61cb0ef41Sopenharmony_citransitioning macro ThisBooleanValue(implicit context: Context)(
71cb0ef41Sopenharmony_ci    receiver: JSAny, method: constexpr string): Boolean {
81cb0ef41Sopenharmony_ci  return UnsafeCast<Boolean>(
91cb0ef41Sopenharmony_ci      ToThisValue(receiver, PrimitiveType::kBoolean, method));
101cb0ef41Sopenharmony_ci}
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cijavascript builtin
131cb0ef41Sopenharmony_ciBooleanConstructor(
141cb0ef41Sopenharmony_ci    js-implicit context: NativeContext, receiver: JSAny, newTarget: JSAny,
151cb0ef41Sopenharmony_ci    target: JSFunction)(...arguments): JSAny {
161cb0ef41Sopenharmony_ci  const value = SelectBooleanConstant(ToBoolean(arguments[0]));
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  if (newTarget == Undefined) {
191cb0ef41Sopenharmony_ci    return value;
201cb0ef41Sopenharmony_ci  }
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  const map = GetDerivedMap(target, UnsafeCast<JSReceiver>(newTarget));
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  const obj =
251cb0ef41Sopenharmony_ci      UnsafeCast<JSPrimitiveWrapper>(AllocateFastOrSlowJSObjectFromMap(map));
261cb0ef41Sopenharmony_ci  obj.value = value;
271cb0ef41Sopenharmony_ci  return obj;
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci// ES #sec-boolean.prototype.tostring
311cb0ef41Sopenharmony_citransitioning javascript builtin BooleanPrototypeToString(
321cb0ef41Sopenharmony_ci    js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
331cb0ef41Sopenharmony_ci  // 1. Let b be ? thisBooleanValue(this value).
341cb0ef41Sopenharmony_ci  const b = ThisBooleanValue(receiver, 'Boolean.prototype.toString');
351cb0ef41Sopenharmony_ci  // 2. If b is true, return "true"; else return "false".
361cb0ef41Sopenharmony_ci  return b.to_string;
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci// ES #sec-boolean.prototype.valueof
401cb0ef41Sopenharmony_citransitioning javascript builtin BooleanPrototypeValueOf(
411cb0ef41Sopenharmony_ci    js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
421cb0ef41Sopenharmony_ci  // 1. Return ? thisBooleanValue(this value).
431cb0ef41Sopenharmony_ci  return ThisBooleanValue(receiver, 'Boolean.prototype.valueOf');
441cb0ef41Sopenharmony_ci}
451cb0ef41Sopenharmony_ci}
46