1 // Copyright 2016 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 5 #include "src/builtins/builtins-utils-inl.h" 6 #include "src/builtins/builtins.h" 7 #include "src/counters.h" 8 #include "src/objects-inl.h" 9 10 namespace v8 { 11 namespace internal { 12 13 // ----------------------------------------------------------------------------- 14 // ES #sec-boolean-objects 15 16 // ES #sec-boolean-constructor BUILTIN(BooleanConstructor)17BUILTIN(BooleanConstructor) { 18 HandleScope scope(isolate); 19 if (args.new_target()->IsUndefined(isolate)) { // [[Call]] 20 Handle<Object> value = args.atOrUndefined(isolate, 1); 21 return isolate->heap()->ToBoolean(value->BooleanValue(isolate)); 22 } 23 // [[Construct]] 24 Handle<Object> value = args.atOrUndefined(isolate, 1); 25 Handle<JSFunction> target = args.target(); 26 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); 27 DCHECK(*target == target->native_context()->boolean_function()); 28 Handle<JSObject> result; 29 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, 30 JSObject::New(target, new_target)); 31 Handle<JSValue>::cast(result)->set_value( 32 isolate->heap()->ToBoolean(value->BooleanValue(isolate))); 33 return *result; 34 } 35 36 } // namespace internal 37 } // namespace v8 38