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-gen.h"
6 #include "src/builtins/builtins.h"
7 #include "src/codegen/code-factory.h"
8 #include "src/codegen/code-stub-assembler.h"
9 #include "src/codegen/tnode.h"
10 #include "src/objects/objects-inl.h"
11 #include "src/objects/oddball.h"
12
13 namespace v8 {
14 namespace internal {
15
16 // ES6 section 7.1.3 ToNumber ( argument )
TF_BUILTIN(ToNumber,CodeStubAssembler)17 TF_BUILTIN(ToNumber, CodeStubAssembler) {
18 auto context = Parameter<Context>(Descriptor::kContext);
19 auto input = Parameter<Object>(Descriptor::kArgument);
20
21 Return(ToNumber(context, input));
22 }
23
TF_BUILTIN(ToNumber_Baseline,CodeStubAssembler)24 TF_BUILTIN(ToNumber_Baseline, CodeStubAssembler) {
25 auto input = Parameter<Object>(Descriptor::kArgument);
26 auto slot = UncheckedParameter<UintPtrT>(Descriptor::kSlot);
27 auto context = [this] { return LoadContextFromBaseline(); };
28
29 TVARIABLE(Smi, var_type_feedback);
30 TNode<Number> result = CAST(ToNumberOrNumeric(
31 context, input, &var_type_feedback, Object::Conversion::kToNumber));
32
33 auto feedback_vector = LoadFeedbackVectorFromBaseline();
34 UpdateFeedback(var_type_feedback.value(), feedback_vector, slot);
35 Return(result);
36 }
37
TF_BUILTIN(ToNumeric_Baseline,CodeStubAssembler)38 TF_BUILTIN(ToNumeric_Baseline, CodeStubAssembler) {
39 auto input = Parameter<Object>(Descriptor::kArgument);
40 auto slot = UncheckedParameter<UintPtrT>(Descriptor::kSlot);
41 auto context = [this] { return LoadContextFromBaseline(); };
42
43 TVARIABLE(Smi, var_type_feedback);
44 TNode<Numeric> result = ToNumberOrNumeric(context, input, &var_type_feedback,
45 Object::Conversion::kToNumeric);
46
47 auto feedback_vector = LoadFeedbackVectorFromBaseline();
48 UpdateFeedback(var_type_feedback.value(), feedback_vector, slot);
49 Return(result);
50 }
51
TF_BUILTIN(PlainPrimitiveToNumber,CodeStubAssembler)52 TF_BUILTIN(PlainPrimitiveToNumber, CodeStubAssembler) {
53 auto input = Parameter<Object>(Descriptor::kArgument);
54
55 Return(PlainPrimitiveToNumber(input));
56 }
57
58 // Like ToNumber, but also converts BigInts.
TF_BUILTIN(ToNumberConvertBigInt,CodeStubAssembler)59 TF_BUILTIN(ToNumberConvertBigInt, CodeStubAssembler) {
60 auto context = Parameter<Context>(Descriptor::kContext);
61 auto input = Parameter<Object>(Descriptor::kArgument);
62
63 Return(ToNumber(context, input, BigIntHandling::kConvertToNumber));
64 }
65
66 // ES6 section 7.1.2 ToBoolean ( argument )
67 // Requires parameter on stack so that it can be used as a continuation from a
68 // LAZY deopt.
TF_BUILTIN(ToBooleanLazyDeoptContinuation,CodeStubAssembler)69 TF_BUILTIN(ToBooleanLazyDeoptContinuation, CodeStubAssembler) {
70 auto value = Parameter<Object>(Descriptor::kArgument);
71
72 Label return_true(this), return_false(this);
73 BranchIfToBooleanIsTrue(value, &return_true, &return_false);
74
75 BIND(&return_true);
76 Return(TrueConstant());
77
78 BIND(&return_false);
79 Return(FalseConstant());
80 }
81
82 // ES6 section 12.5.5 typeof operator
TF_BUILTIN(Typeof,CodeStubAssembler)83 TF_BUILTIN(Typeof, CodeStubAssembler) {
84 auto object = Parameter<Object>(Descriptor::kObject);
85
86 Return(Typeof(object));
87 }
88
89 } // namespace internal
90 } // namespace v8
91