summaryrefslogtreecommitdiff
path: root/deps/v8/src/builtins/builtins-global-gen.cc
blob: 43d30cc6b1a59fb593a744d890626db3a56e4e3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2017 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.

#include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h"
#include "src/codegen/code-stub-assembler.h"

namespace v8 {
namespace internal {

// ES #sec-isfinite-number
TF_BUILTIN(GlobalIsFinite, CodeStubAssembler) {
  TNode<Context> context = CAST(Parameter(Descriptor::kContext));

  Label return_true(this), return_false(this);

  // We might need to loop once for ToNumber conversion.
  TVARIABLE(Object, var_num);
  Label loop(this, &var_num);
  var_num = CAST(Parameter(Descriptor::kNumber));
  Goto(&loop);
  BIND(&loop);
  {
    TNode<Object> num = var_num.value();

    // Check if {num} is a Smi or a HeapObject.
    GotoIf(TaggedIsSmi(num), &return_true);
    TNode<HeapObject> num_heap_object = CAST(num);

    // Check if {num_heap_object} is a HeapNumber.
    Label if_numisheapnumber(this),
        if_numisnotheapnumber(this, Label::kDeferred);
    Branch(IsHeapNumber(num_heap_object), &if_numisheapnumber,
           &if_numisnotheapnumber);

    BIND(&if_numisheapnumber);
    {
      // Check if {num_heap_object} contains a finite, non-NaN value.
      TNode<Float64T> num_value = LoadHeapNumberValue(num_heap_object);
      BranchIfFloat64IsNaN(Float64Sub(num_value, num_value), &return_false,
                           &return_true);
    }

    BIND(&if_numisnotheapnumber);
    {
      // Need to convert {num_heap_object} to a Number first.
      var_num =
          CallBuiltin(Builtins::kNonNumberToNumber, context, num_heap_object);
      Goto(&loop);
    }
  }

  BIND(&return_true);
  Return(TrueConstant());

  BIND(&return_false);
  Return(FalseConstant());
}

// ES6 #sec-isnan-number
TF_BUILTIN(GlobalIsNaN, CodeStubAssembler) {
  TNode<Context> context = CAST(Parameter(Descriptor::kContext));

  Label return_true(this), return_false(this);

  // We might need to loop once for ToNumber conversion.
  TVARIABLE(Object, var_num);
  Label loop(this, &var_num);
  var_num = CAST(Parameter(Descriptor::kNumber));
  Goto(&loop);
  BIND(&loop);
  {
    TNode<Object> num = var_num.value();

    // Check if {num} is a Smi or a HeapObject.
    GotoIf(TaggedIsSmi(num), &return_false);
    TNode<HeapObject> num_heap_object = CAST(num);

    // Check if {num_heap_object} is a HeapNumber.
    Label if_numisheapnumber(this),
        if_numisnotheapnumber(this, Label::kDeferred);
    Branch(IsHeapNumber(num_heap_object), &if_numisheapnumber,
           &if_numisnotheapnumber);

    BIND(&if_numisheapnumber);
    {
      // Check if {num_heap_object} contains a NaN.
      TNode<Float64T> num_value = LoadHeapNumberValue(num_heap_object);
      BranchIfFloat64IsNaN(num_value, &return_true, &return_false);
    }

    BIND(&if_numisnotheapnumber);
    {
      // Need to convert {num_heap_object} to a Number first.
      var_num =
          CallBuiltin(Builtins::kNonNumberToNumber, context, num_heap_object);
      Goto(&loop);
    }
  }

  BIND(&return_true);
  Return(TrueConstant());

  BIND(&return_false);
  Return(FalseConstant());
}

}  // namespace internal
}  // namespace v8