Index: test/unittests/compiler/js-builtin-reducer-unittest.cc |
diff --git a/test/unittests/compiler/js-builtin-reducer-unittest.cc b/test/unittests/compiler/js-builtin-reducer-unittest.cc |
index ed20e641942a2f9da0237e3a4ce89c0c95db6701..48debc368c17947f8ef834bb92525e6be77d7e7c 100644 |
--- a/test/unittests/compiler/js-builtin-reducer-unittest.cc |
+++ b/test/unittests/compiler/js-builtin-reducer-unittest.cc |
@@ -38,6 +38,15 @@ class JSBuiltinReducerTest : public TypedGraphTest { |
return reducer.Reduce(node); |
} |
+ Node* GlobalFunction(const char* name) { |
+ Handle<JSFunction> f = Handle<JSFunction>::cast( |
+ Object::GetProperty( |
+ isolate()->global_object(), |
+ isolate()->factory()->NewStringFromAsciiChecked(name)) |
+ .ToHandleChecked()); |
+ return HeapConstant(f); |
+ } |
+ |
Node* MathFunction(const char* name) { |
Handle<Object> m = |
JSObject::GetProperty(isolate()->global_object(), |
@@ -101,6 +110,91 @@ Type* const kNumberTypes[] = { |
// ----------------------------------------------------------------------------- |
+// isFinite |
+ |
+TEST_F(JSBuiltinReducerTest, GlobalIsFiniteWithNumber) { |
+ Node* function = GlobalFunction("isFinite"); |
+ |
+ Node* effect = graph()->start(); |
+ Node* control = graph()->start(); |
+ Node* context = UndefinedConstant(); |
+ Node* frame_state = graph()->start(); |
+ TRACED_FOREACH(Type*, t0, kNumberTypes) { |
+ Node* p0 = Parameter(t0, 0); |
+ Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
+ UndefinedConstant(), p0, context, frame_state, |
+ effect, control); |
+ Reduction r = Reduce(call); |
+ |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsNumberEqual(IsNumberSubtract(p0, p0), |
+ IsNumberSubtract(p0, p0))); |
+ } |
+} |
+ |
+TEST_F(JSBuiltinReducerTest, GlobalIsFiniteWithPlainPrimitive) { |
+ Node* function = GlobalFunction("isFinite"); |
+ |
+ Node* effect = graph()->start(); |
+ Node* control = graph()->start(); |
+ Node* context = UndefinedConstant(); |
+ Node* frame_state = graph()->start(); |
+ Node* p0 = Parameter(Type::PlainPrimitive(), 0); |
+ Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
+ UndefinedConstant(), p0, context, frame_state, |
+ effect, control); |
+ Reduction r = Reduce(call); |
+ |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), |
+ IsNumberEqual(IsNumberSubtract(IsPlainPrimitiveToNumber(p0), |
+ IsPlainPrimitiveToNumber(p0)), |
+ IsNumberSubtract(IsPlainPrimitiveToNumber(p0), |
+ IsPlainPrimitiveToNumber(p0)))); |
+} |
+ |
+// ----------------------------------------------------------------------------- |
+// isNaN |
+ |
+TEST_F(JSBuiltinReducerTest, GlobalIsNaNWithNumber) { |
+ Node* function = GlobalFunction("isNaN"); |
+ |
+ Node* effect = graph()->start(); |
+ Node* control = graph()->start(); |
+ Node* context = UndefinedConstant(); |
+ Node* frame_state = graph()->start(); |
+ TRACED_FOREACH(Type*, t0, kNumberTypes) { |
+ Node* p0 = Parameter(t0, 0); |
+ Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
+ UndefinedConstant(), p0, context, frame_state, |
+ effect, control); |
+ Reduction r = Reduce(call); |
+ |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsBooleanNot(IsNumberEqual(p0, p0))); |
+ } |
+} |
+ |
+TEST_F(JSBuiltinReducerTest, GlobalIsNaNWithPlainPrimitive) { |
+ Node* function = GlobalFunction("isNaN"); |
+ |
+ Node* effect = graph()->start(); |
+ Node* control = graph()->start(); |
+ Node* context = UndefinedConstant(); |
+ Node* frame_state = graph()->start(); |
+ Node* p0 = Parameter(Type::PlainPrimitive(), 0); |
+ Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
+ UndefinedConstant(), p0, context, frame_state, |
+ effect, control); |
+ Reduction r = Reduce(call); |
+ |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), |
+ IsBooleanNot(IsNumberEqual(IsPlainPrimitiveToNumber(p0), |
+ IsPlainPrimitiveToNumber(p0)))); |
+} |
+ |
+// ----------------------------------------------------------------------------- |
// Math.abs |
TEST_F(JSBuiltinReducerTest, MathAbsWithNumber) { |
@@ -1315,6 +1409,97 @@ TEST_F(JSBuiltinReducerTest, MathTruncWithPlainPrimitive) { |
} |
// ----------------------------------------------------------------------------- |
+// Number.isFinite |
+ |
+TEST_F(JSBuiltinReducerTest, NumberIsFiniteWithNumber) { |
+ Node* function = NumberFunction("isFinite"); |
+ |
+ Node* effect = graph()->start(); |
+ Node* control = graph()->start(); |
+ Node* context = UndefinedConstant(); |
+ Node* frame_state = graph()->start(); |
+ TRACED_FOREACH(Type*, t0, kNumberTypes) { |
+ Node* p0 = Parameter(t0, 0); |
+ Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
+ UndefinedConstant(), p0, context, frame_state, |
+ effect, control); |
+ Reduction r = Reduce(call); |
+ |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsNumberEqual(IsNumberSubtract(p0, p0), |
+ IsNumberSubtract(p0, p0))); |
+ } |
+} |
+ |
+// ----------------------------------------------------------------------------- |
+// Number.isInteger |
+ |
+TEST_F(JSBuiltinReducerTest, NumberIsIntegerWithNumber) { |
+ Node* function = NumberFunction("isInteger"); |
+ |
+ Node* effect = graph()->start(); |
+ Node* control = graph()->start(); |
+ Node* context = UndefinedConstant(); |
+ Node* frame_state = graph()->start(); |
+ TRACED_FOREACH(Type*, t0, kNumberTypes) { |
+ Node* p0 = Parameter(t0, 0); |
+ Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
+ UndefinedConstant(), p0, context, frame_state, |
+ effect, control); |
+ Reduction r = Reduce(call); |
+ |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), |
+ IsNumberEqual(IsNumberSubtract(p0, IsNumberTrunc(p0)), |
+ IsNumberConstant(0.0))); |
+ } |
+} |
+ |
+// ----------------------------------------------------------------------------- |
+// Number.isNaN |
+ |
+TEST_F(JSBuiltinReducerTest, NumberIsNaNWithNumber) { |
+ Node* function = NumberFunction("isNaN"); |
+ |
+ Node* effect = graph()->start(); |
+ Node* control = graph()->start(); |
+ Node* context = UndefinedConstant(); |
+ Node* frame_state = graph()->start(); |
+ TRACED_FOREACH(Type*, t0, kNumberTypes) { |
+ Node* p0 = Parameter(t0, 0); |
+ Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
+ UndefinedConstant(), p0, context, frame_state, |
+ effect, control); |
+ Reduction r = Reduce(call); |
+ |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsBooleanNot(IsNumberEqual(p0, p0))); |
+ } |
+} |
+ |
+// ----------------------------------------------------------------------------- |
+// Number.isSafeInteger |
+ |
+TEST_F(JSBuiltinReducerTest, NumberIsSafeIntegerWithIntegral32) { |
+ Node* function = NumberFunction("isSafeInteger"); |
+ |
+ Node* effect = graph()->start(); |
+ Node* control = graph()->start(); |
+ Node* context = UndefinedConstant(); |
+ Node* frame_state = graph()->start(); |
+ TRACED_FOREACH(Type*, t0, kIntegral32Types) { |
+ Node* p0 = Parameter(t0, 0); |
+ Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
+ UndefinedConstant(), p0, context, frame_state, |
+ effect, control); |
+ Reduction r = Reduce(call); |
+ |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsTrueConstant()); |
+ } |
+} |
+ |
+// ----------------------------------------------------------------------------- |
// Number.parseInt |
TEST_F(JSBuiltinReducerTest, NumberParseIntWithIntegral32) { |