1// Copyright 2019 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5namespace boolean { 6transitioning macro ThisBooleanValue(implicit context: Context)( 7 receiver: JSAny, method: constexpr string): Boolean { 8 return UnsafeCast<Boolean>( 9 ToThisValue(receiver, PrimitiveType::kBoolean, method)); 10} 11 12javascript builtin 13BooleanConstructor( 14 js-implicit context: NativeContext, receiver: JSAny, newTarget: JSAny, 15 target: JSFunction)(...arguments): JSAny { 16 const value = SelectBooleanConstant(ToBoolean(arguments[0])); 17 18 if (newTarget == Undefined) { 19 return value; 20 } 21 22 const map = GetDerivedMap(target, UnsafeCast<JSReceiver>(newTarget)); 23 24 const obj = 25 UnsafeCast<JSPrimitiveWrapper>(AllocateFastOrSlowJSObjectFromMap(map)); 26 obj.value = value; 27 return obj; 28} 29 30// ES #sec-boolean.prototype.tostring 31transitioning javascript builtin BooleanPrototypeToString( 32 js-implicit context: NativeContext, receiver: JSAny)(): JSAny { 33 // 1. Let b be ? thisBooleanValue(this value). 34 const b = ThisBooleanValue(receiver, 'Boolean.prototype.toString'); 35 // 2. If b is true, return "true"; else return "false". 36 return b.to_string; 37} 38 39// ES #sec-boolean.prototype.valueof 40transitioning javascript builtin BooleanPrototypeValueOf( 41 js-implicit context: NativeContext, receiver: JSAny)(): JSAny { 42 // 1. Return ? thisBooleanValue(this value). 43 return ThisBooleanValue(receiver, 'Boolean.prototype.valueOf'); 44} 45} 46