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.h"
6 #include "src/builtins/builtins-utils.h"
7
8 namespace v8 {
9 namespace internal {
10
11 // -----------------------------------------------------------------------------
12 // ES6 section 19.3 Boolean Objects
13
14 // ES6 section 19.3.1.1 Boolean ( value ) for the [[Call]] case.
BUILTIN(BooleanConstructor)15 BUILTIN(BooleanConstructor) {
16 HandleScope scope(isolate);
17 Handle<Object> value = args.atOrUndefined(isolate, 1);
18 return isolate->heap()->ToBoolean(value->BooleanValue());
19 }
20
21 // ES6 section 19.3.1.1 Boolean ( value ) for the [[Construct]] case.
BUILTIN(BooleanConstructor_ConstructStub)22 BUILTIN(BooleanConstructor_ConstructStub) {
23 HandleScope scope(isolate);
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()));
33 return *result;
34 }
35
36 // ES6 section 19.3.3.2 Boolean.prototype.toString ( )
Generate_BooleanPrototypeToString(CodeStubAssembler * assembler)37 void Builtins::Generate_BooleanPrototypeToString(CodeStubAssembler* assembler) {
38 typedef compiler::Node Node;
39
40 Node* receiver = assembler->Parameter(0);
41 Node* context = assembler->Parameter(3);
42
43 Node* value = assembler->ToThisValue(
44 context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.toString");
45 Node* result = assembler->LoadObjectField(value, Oddball::kToStringOffset);
46 assembler->Return(result);
47 }
48
49 // ES6 section 19.3.3.3 Boolean.prototype.valueOf ( )
Generate_BooleanPrototypeValueOf(CodeStubAssembler * assembler)50 void Builtins::Generate_BooleanPrototypeValueOf(CodeStubAssembler* assembler) {
51 typedef compiler::Node Node;
52
53 Node* receiver = assembler->Parameter(0);
54 Node* context = assembler->Parameter(3);
55
56 Node* result = assembler->ToThisValue(
57 context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.valueOf");
58 assembler->Return(result);
59 }
60
61 } // namespace internal
62 } // namespace v8
63