builtins-conversion-gen.cc 2.89 KB
Newer Older
1 2 3 4
// Copyright 2016 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.

5
#include "src/builtins/builtins-utils-gen.h"
6
#include "src/builtins/builtins.h"
7 8
#include "src/codegen/code-factory.h"
#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 14 15

namespace v8 {
namespace internal {

16
// ES6 section 7.1.3 ToNumber ( argument )
17
TF_BUILTIN(ToNumber, CodeStubAssembler) {
18 19
  auto context = Parameter<Context>(Descriptor::kContext);
  auto input = Parameter<Object>(Descriptor::kArgument);
20

21
  Return(ToNumber(context, input));
22 23
}

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
TF_BUILTIN(ToNumber_Baseline, CodeStubAssembler) {
  auto input = Parameter<Object>(Descriptor::kArgument);
  auto slot = UncheckedParameter<UintPtrT>(Descriptor::kSlot);
  auto context = [this] { return LoadContextFromBaseline(); };

  TVARIABLE(Smi, var_type_feedback);
  TNode<Number> result = CAST(ToNumberOrNumeric(
      context, input, &var_type_feedback, Object::Conversion::kToNumber));

  auto feedback_vector = LoadFeedbackVectorFromBaseline();
  UpdateFeedback(var_type_feedback.value(), feedback_vector, slot);
  Return(result);
}

TF_BUILTIN(ToNumeric_Baseline, CodeStubAssembler) {
  auto input = Parameter<Object>(Descriptor::kArgument);
  auto slot = UncheckedParameter<UintPtrT>(Descriptor::kSlot);
  auto context = [this] { return LoadContextFromBaseline(); };

  TVARIABLE(Smi, var_type_feedback);
44 45
  TNode<Numeric> result = ToNumberOrNumeric(context, input, &var_type_feedback,
                                            Object::Conversion::kToNumeric);
46 47 48 49 50 51

  auto feedback_vector = LoadFeedbackVectorFromBaseline();
  UpdateFeedback(var_type_feedback.value(), feedback_vector, slot);
  Return(result);
}

52
TF_BUILTIN(PlainPrimitiveToNumber, CodeStubAssembler) {
53
  auto input = Parameter<Object>(Descriptor::kArgument);
54 55 56 57

  Return(PlainPrimitiveToNumber(input));
}

58 59
// Like ToNumber, but also converts BigInts.
TF_BUILTIN(ToNumberConvertBigInt, CodeStubAssembler) {
60 61
  auto context = Parameter<Context>(Descriptor::kContext);
  auto input = Parameter<Object>(Descriptor::kArgument);
62 63 64 65

  Return(ToNumber(context, input, BigIntHandling::kConvertToNumber));
}

66 67 68 69
// ES6 section 7.1.2 ToBoolean ( argument )
// Requires parameter on stack so that it can be used as a continuation from a
// LAZY deopt.
TF_BUILTIN(ToBooleanLazyDeoptContinuation, CodeStubAssembler) {
70
  auto value = Parameter<Object>(Descriptor::kArgument);
71 72 73 74 75

  Label return_true(this), return_false(this);
  BranchIfToBooleanIsTrue(value, &return_true, &return_false);

  BIND(&return_true);
76
  Return(TrueConstant());
77 78

  BIND(&return_false);
79
  Return(FalseConstant());
80 81
}

82
// ES6 section 12.5.5 typeof operator
83
TF_BUILTIN(Typeof, CodeStubAssembler) {
84
  auto object = Parameter<Object>(Descriptor::kObject);
85

86
  Return(Typeof(object));
87 88
}

89 90
}  // namespace internal
}  // namespace v8