OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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/code-stub-assembler.h" |
| 8 |
| 9 namespace v8 { |
| 10 namespace internal { |
| 11 |
| 12 // ES6 section 18.2.2 isFinite ( number ) |
| 13 TF_BUILTIN(GlobalIsFinite, CodeStubAssembler) { |
| 14 Node* context = Parameter(4); |
| 15 |
| 16 Label return_true(this), return_false(this); |
| 17 |
| 18 // We might need to loop once for ToNumber conversion. |
| 19 Variable var_num(this, MachineRepresentation::kTagged); |
| 20 Label loop(this, &var_num); |
| 21 var_num.Bind(Parameter(1)); |
| 22 Goto(&loop); |
| 23 Bind(&loop); |
| 24 { |
| 25 Node* num = var_num.value(); |
| 26 |
| 27 // Check if {num} is a Smi or a HeapObject. |
| 28 GotoIf(TaggedIsSmi(num), &return_true); |
| 29 |
| 30 // Check if {num} is a HeapNumber. |
| 31 Label if_numisheapnumber(this), |
| 32 if_numisnotheapnumber(this, Label::kDeferred); |
| 33 Branch(IsHeapNumberMap(LoadMap(num)), &if_numisheapnumber, |
| 34 &if_numisnotheapnumber); |
| 35 |
| 36 Bind(&if_numisheapnumber); |
| 37 { |
| 38 // Check if {num} contains a finite, non-NaN value. |
| 39 Node* num_value = LoadHeapNumberValue(num); |
| 40 BranchIfFloat64IsNaN(Float64Sub(num_value, num_value), &return_false, |
| 41 &return_true); |
| 42 } |
| 43 |
| 44 Bind(&if_numisnotheapnumber); |
| 45 { |
| 46 // Need to convert {num} to a Number first. |
| 47 Callable callable = CodeFactory::NonNumberToNumber(isolate()); |
| 48 var_num.Bind(CallStub(callable, context, num)); |
| 49 Goto(&loop); |
| 50 } |
| 51 } |
| 52 |
| 53 Bind(&return_true); |
| 54 Return(BooleanConstant(true)); |
| 55 |
| 56 Bind(&return_false); |
| 57 Return(BooleanConstant(false)); |
| 58 } |
| 59 |
| 60 // ES6 section 18.2.3 isNaN ( number ) |
| 61 TF_BUILTIN(GlobalIsNaN, CodeStubAssembler) { |
| 62 Node* context = Parameter(4); |
| 63 |
| 64 Label return_true(this), return_false(this); |
| 65 |
| 66 // We might need to loop once for ToNumber conversion. |
| 67 Variable var_num(this, MachineRepresentation::kTagged); |
| 68 Label loop(this, &var_num); |
| 69 var_num.Bind(Parameter(1)); |
| 70 Goto(&loop); |
| 71 Bind(&loop); |
| 72 { |
| 73 Node* num = var_num.value(); |
| 74 |
| 75 // Check if {num} is a Smi or a HeapObject. |
| 76 GotoIf(TaggedIsSmi(num), &return_false); |
| 77 |
| 78 // Check if {num} is a HeapNumber. |
| 79 Label if_numisheapnumber(this), |
| 80 if_numisnotheapnumber(this, Label::kDeferred); |
| 81 Branch(IsHeapNumberMap(LoadMap(num)), &if_numisheapnumber, |
| 82 &if_numisnotheapnumber); |
| 83 |
| 84 Bind(&if_numisheapnumber); |
| 85 { |
| 86 // Check if {num} contains a NaN. |
| 87 Node* num_value = LoadHeapNumberValue(num); |
| 88 BranchIfFloat64IsNaN(num_value, &return_true, &return_false); |
| 89 } |
| 90 |
| 91 Bind(&if_numisnotheapnumber); |
| 92 { |
| 93 // Need to convert {num} to a Number first. |
| 94 Callable callable = CodeFactory::NonNumberToNumber(isolate()); |
| 95 var_num.Bind(CallStub(callable, context, num)); |
| 96 Goto(&loop); |
| 97 } |
| 98 } |
| 99 |
| 100 Bind(&return_true); |
| 101 Return(BooleanConstant(true)); |
| 102 |
| 103 Bind(&return_false); |
| 104 Return(BooleanConstant(false)); |
| 105 } |
| 106 |
| 107 } // namespace internal |
| 108 } // namespace v8 |
OLD | NEW |