Chromium Code Reviews| Index: test/unittests/compiler/js-typed-lowering-unittest.cc |
| diff --git a/test/unittests/compiler/js-typed-lowering-unittest.cc b/test/unittests/compiler/js-typed-lowering-unittest.cc |
| index 7ef1e81d47da427a1e3e3c025aa0975525e438a1..e44ab873476c003c3496ceaa85845f5fdd97b954 100644 |
| --- a/test/unittests/compiler/js-typed-lowering-unittest.cc |
| +++ b/test/unittests/compiler/js-typed-lowering-unittest.cc |
| @@ -74,7 +74,8 @@ const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG}; |
| class JSTypedLoweringTest : public TypedGraphTest { |
| public: |
| - JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} |
| + JSTypedLoweringTest() |
| + : TypedGraphTest(3), javascript_(zone()), deps_(isolate(), zone()) {} |
| ~JSTypedLoweringTest() override {} |
| protected: |
| @@ -85,7 +86,9 @@ class JSTypedLoweringTest : public TypedGraphTest { |
| &machine); |
| // TODO(titzer): mock the GraphReducer here for better unit testing. |
| GraphReducer graph_reducer(zone(), graph()); |
| - JSTypedLowering reducer(&graph_reducer, &jsgraph, zone()); |
| + JSTypedLowering reducer(&graph_reducer, &deps_, |
| + JSTypedLowering::kDeoptimizationEnabled, &jsgraph, |
| + zone()); |
| return reducer.Reduce(node); |
| } |
| @@ -116,6 +119,7 @@ class JSTypedLoweringTest : public TypedGraphTest { |
| private: |
| JSOperatorBuilder javascript_; |
| + CompilationDependencies deps_; |
| }; |
| @@ -1168,6 +1172,54 @@ TEST_F(JSTypedLoweringTest, JSCreateWithContext) { |
| _)); |
| } |
| + |
| +// ----------------------------------------------------------------------------- |
| +// InstanceOf |
|
Michael Starzinger
2015/11/10 09:48:48
nit: s/InstanceOf/JSInstanceOf
sigurds
2015/11/10 10:01:24
Done.
|
| +// Test that instanceOf is reduced if and only if the right-hand side is a |
| +// function constant. Functional correctness is ensured elsewhere. |
| + |
| + |
| +TEST_F(JSTypedLoweringTest, InstanceOfSpecialization) { |
|
Michael Starzinger
2015/11/10 09:48:48
nit: Let's split this into three separate unit tes
Michael Starzinger
2015/11/10 09:49:49
nit: s/InstanceOfSpecialization/JSInstanceOf/ here
sigurds
2015/11/10 10:01:24
Done.
sigurds
2015/11/10 10:01:24
Done.
|
| + Node* const context = Parameter(Type::Any()); |
| + Node* const frame_state = EmptyFrameState(); |
| + Node* const effect = graph()->start(); |
| + Node* const control = graph()->start(); |
| + |
| + // Reduce if left-hand side is known to be an object. |
| + Node* instanceOf = |
| + graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Object(), 0), |
| + HeapConstant(isolate()->object_function()), context, |
| + frame_state, effect, control); |
| + Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
| + frame_state, effect, control); |
| + Reduction r = Reduce(instanceOf); |
| + ASSERT_TRUE(r.Changed()); |
| + ASSERT_EQ(r.replacement(), dummy->InputAt(0)); |
| + ASSERT_NE(instanceOf, dummy->InputAt(0)); |
| + |
| + // Reduce if left-hand side could be a Smi. |
| + instanceOf = |
| + graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Any(), 0), |
| + HeapConstant(isolate()->object_function()), context, |
| + frame_state, effect, control); |
| + dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
| + frame_state, effect, control); |
| + r = Reduce(instanceOf); |
| + ASSERT_TRUE(r.Changed()); |
| + ASSERT_EQ(r.replacement(), dummy->InputAt(0)); |
| + ASSERT_NE(instanceOf, dummy->InputAt(0)); |
| + |
| + // Do not reduce if right-hand side is not a function constant. |
| + instanceOf = graph()->NewNode( |
| + javascript()->InstanceOf(), Parameter(Type::Any(), 0), |
| + Parameter(Type::Any()), context, frame_state, effect, control); |
| + dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
| + frame_state, effect, control); |
| + r = Reduce(instanceOf); |
| + ASSERT_FALSE(r.Changed()); |
| + ASSERT_EQ(instanceOf, dummy->InputAt(0)); |
| +} |
| + |
| } // namespace compiler |
| } // namespace internal |
| } // namespace v8 |