summaryrefslogtreecommitdiff
path: root/deps/v8/src/builtins/builtins-number.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/builtins/builtins-number.cc')
-rw-r--r--deps/v8/src/builtins/builtins-number.cc138
1 files changed, 138 insertions, 0 deletions
diff --git a/deps/v8/src/builtins/builtins-number.cc b/deps/v8/src/builtins/builtins-number.cc
index c2af0fdecf..17628445d1 100644
--- a/deps/v8/src/builtins/builtins-number.cc
+++ b/deps/v8/src/builtins/builtins-number.cc
@@ -11,6 +11,144 @@ namespace internal {
// -----------------------------------------------------------------------------
// ES6 section 20.1 Number Objects
+// ES6 section 20.1.2.2 Number.isFinite ( number )
+void Builtins::Generate_NumberIsFinite(CodeStubAssembler* assembler) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* number = assembler->Parameter(1);
+
+ Label return_true(assembler), return_false(assembler);
+
+ // Check if {number} is a Smi.
+ assembler->GotoIf(assembler->WordIsSmi(number), &return_true);
+
+ // Check if {number} is a HeapNumber.
+ assembler->GotoUnless(
+ assembler->WordEqual(assembler->LoadMap(number),
+ assembler->HeapNumberMapConstant()),
+ &return_false);
+
+ // Check if {number} contains a finite, non-NaN value.
+ Node* number_value = assembler->LoadHeapNumberValue(number);
+ assembler->BranchIfFloat64IsNaN(
+ assembler->Float64Sub(number_value, number_value), &return_false,
+ &return_true);
+
+ assembler->Bind(&return_true);
+ assembler->Return(assembler->BooleanConstant(true));
+
+ assembler->Bind(&return_false);
+ assembler->Return(assembler->BooleanConstant(false));
+}
+
+// ES6 section 20.1.2.3 Number.isInteger ( number )
+void Builtins::Generate_NumberIsInteger(CodeStubAssembler* assembler) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* number = assembler->Parameter(1);
+
+ Label return_true(assembler), return_false(assembler);
+
+ // Check if {number} is a Smi.
+ assembler->GotoIf(assembler->WordIsSmi(number), &return_true);
+
+ // Check if {number} is a HeapNumber.
+ assembler->GotoUnless(
+ assembler->WordEqual(assembler->LoadMap(number),
+ assembler->HeapNumberMapConstant()),
+ &return_false);
+
+ // Load the actual value of {number}.
+ Node* number_value = assembler->LoadHeapNumberValue(number);
+
+ // Truncate the value of {number} to an integer (or an infinity).
+ Node* integer = assembler->Float64Trunc(number_value);
+
+ // Check if {number}s value matches the integer (ruling out the infinities).
+ assembler->BranchIfFloat64Equal(assembler->Float64Sub(number_value, integer),
+ assembler->Float64Constant(0.0), &return_true,
+ &return_false);
+
+ assembler->Bind(&return_true);
+ assembler->Return(assembler->BooleanConstant(true));
+
+ assembler->Bind(&return_false);
+ assembler->Return(assembler->BooleanConstant(false));
+}
+
+// ES6 section 20.1.2.4 Number.isNaN ( number )
+void Builtins::Generate_NumberIsNaN(CodeStubAssembler* assembler) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* number = assembler->Parameter(1);
+
+ Label return_true(assembler), return_false(assembler);
+
+ // Check if {number} is a Smi.
+ assembler->GotoIf(assembler->WordIsSmi(number), &return_false);
+
+ // Check if {number} is a HeapNumber.
+ assembler->GotoUnless(
+ assembler->WordEqual(assembler->LoadMap(number),
+ assembler->HeapNumberMapConstant()),
+ &return_false);
+
+ // Check if {number} contains a NaN value.
+ Node* number_value = assembler->LoadHeapNumberValue(number);
+ assembler->BranchIfFloat64IsNaN(number_value, &return_true, &return_false);
+
+ assembler->Bind(&return_true);
+ assembler->Return(assembler->BooleanConstant(true));
+
+ assembler->Bind(&return_false);
+ assembler->Return(assembler->BooleanConstant(false));
+}
+
+// ES6 section 20.1.2.5 Number.isSafeInteger ( number )
+void Builtins::Generate_NumberIsSafeInteger(CodeStubAssembler* assembler) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* number = assembler->Parameter(1);
+
+ Label return_true(assembler), return_false(assembler);
+
+ // Check if {number} is a Smi.
+ assembler->GotoIf(assembler->WordIsSmi(number), &return_true);
+
+ // Check if {number} is a HeapNumber.
+ assembler->GotoUnless(
+ assembler->WordEqual(assembler->LoadMap(number),
+ assembler->HeapNumberMapConstant()),
+ &return_false);
+
+ // Load the actual value of {number}.
+ Node* number_value = assembler->LoadHeapNumberValue(number);
+
+ // Truncate the value of {number} to an integer (or an infinity).
+ Node* integer = assembler->Float64Trunc(number_value);
+
+ // Check if {number}s value matches the integer (ruling out the infinities).
+ assembler->GotoUnless(
+ assembler->Float64Equal(assembler->Float64Sub(number_value, integer),
+ assembler->Float64Constant(0.0)),
+ &return_false);
+
+ // Check if the {integer} value is in safe integer range.
+ assembler->BranchIfFloat64LessThanOrEqual(
+ assembler->Float64Abs(integer),
+ assembler->Float64Constant(kMaxSafeInteger), &return_true, &return_false);
+
+ assembler->Bind(&return_true);
+ assembler->Return(assembler->BooleanConstant(true));
+
+ assembler->Bind(&return_false);
+ assembler->Return(assembler->BooleanConstant(false));
+}
+
// ES6 section 20.1.3.2 Number.prototype.toExponential ( fractionDigits )
BUILTIN(NumberPrototypeToExponential) {
HandleScope scope(isolate);