boolean.tq 1.5 KB
Newer Older
1 2 3 4 5
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

namespace boolean {
6 7 8 9 10
transitioning macro ThisBooleanValue(implicit context: Context)(
    receiver: JSAny, method: constexpr string): Boolean {
  return UnsafeCast<Boolean>(
      ToThisValue(receiver, PrimitiveType::kBoolean, method));
}
11

12 13 14 15 16
javascript builtin
BooleanConstructor(
    js-implicit context: NativeContext, receiver: JSAny, newTarget: JSAny,
    target: JSFunction)(...arguments): JSAny {
  const value = SelectBooleanConstant(ToBoolean(arguments[0]));
17

18 19 20
  if (newTarget == Undefined) {
    return value;
  }
21

22
  const map = GetDerivedMap(target, UnsafeCast<JSReceiver>(newTarget));
23

24 25 26 27 28
  const obj =
      UnsafeCast<JSPrimitiveWrapper>(AllocateFastOrSlowJSObjectFromMap(map));
  obj.value = value;
  return obj;
}
29

30 31 32 33 34 35 36 37
// ES #sec-boolean.prototype.tostring
transitioning javascript builtin BooleanPrototypeToString(
    js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
  // 1. Let b be ? thisBooleanValue(this value).
  const b = ThisBooleanValue(receiver, 'Boolean.prototype.toString');
  // 2. If b is true, return "true"; else return "false".
  return b.to_string;
}
38

39 40 41 42 43 44
// ES #sec-boolean.prototype.valueof
transitioning javascript builtin BooleanPrototypeValueOf(
    js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
  // 1. Return ? thisBooleanValue(this value).
  return ThisBooleanValue(receiver, 'Boolean.prototype.valueOf');
}
45
}