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 d40954ab5ec79ce888bde39352ce7e89906476d0..4170111cdb404184f49dcdb32e035fcfc1bb5afb 100644 |
--- a/test/unittests/compiler/js-builtin-reducer-unittest.cc |
+++ b/test/unittests/compiler/js-builtin-reducer-unittest.cc |
@@ -49,6 +49,19 @@ class JSBuiltinReducerTest : public TypedGraphTest { |
return HeapConstant(f); |
} |
+ Node* NumberFunction(const char* name) { |
+ Handle<Object> m = |
+ JSObject::GetProperty( |
+ isolate()->global_object(), |
+ isolate()->factory()->NewStringFromAsciiChecked("Number")) |
+ .ToHandleChecked(); |
+ Handle<JSFunction> f = Handle<JSFunction>::cast( |
+ Object::GetProperty( |
+ m, isolate()->factory()->NewStringFromAsciiChecked(name)) |
+ .ToHandleChecked()); |
+ return HeapConstant(f); |
+ } |
+ |
Node* StringFunction(const char* name) { |
Handle<Object> m = |
JSObject::GetProperty( |
@@ -1343,6 +1356,48 @@ TEST_F(JSBuiltinReducerTest, MathTruncWithPlainPrimitive) { |
} |
// ----------------------------------------------------------------------------- |
+// Number.parseInt |
+ |
+TEST_F(JSBuiltinReducerTest, NumberParseIntWithIntegral32) { |
+ Node* function = NumberFunction("parseInt"); |
+ |
+ 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(), IsNumberToInt32(p0)); |
+ } |
+} |
+ |
+TEST_F(JSBuiltinReducerTest, NumberParseIntWithIntegral32AndUndefined) { |
+ Node* function = NumberFunction("parseInt"); |
+ |
+ 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* p1 = Parameter(Type::Undefined(), 1); |
+ Node* call = graph()->NewNode(javascript()->CallFunction(4), function, |
+ UndefinedConstant(), p0, p1, context, |
+ frame_state, effect, control); |
+ Reduction r = Reduce(call); |
+ |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsNumberToInt32(p0)); |
+ } |
+} |
+ |
+// ----------------------------------------------------------------------------- |
// String.fromCharCode |
TEST_F(JSBuiltinReducerTest, StringFromCharCodeWithNumber) { |