[turbofan] Add unit tests for ReduceJSCreateArguments.

R=jarin@chromium.org
TEST=unittests/JSTypedLoweringTest.JSCreateArguments

Review URL: https://codereview.chromium.org/1417983004

Cr-Commit-Position: refs/heads/master@{#31653}
This commit is contained in:
mstarzinger 2015-10-29 06:37:27 -07:00 committed by Commit bot
parent d3c4adfd78
commit 747ff0ebf8

View File

@ -89,6 +89,18 @@ class JSTypedLoweringTest : public TypedGraphTest {
return reducer.Reduce(node);
}
Node* FrameState(Handle<SharedFunctionInfo> shared, Node* outer_frame_state) {
Node* state_values = graph()->NewNode(common()->StateValues(0));
return graph()->NewNode(
common()->FrameState(BailoutId::None(),
OutputFrameStateCombine::Ignore(),
common()->CreateFrameStateFunctionInfo(
FrameStateType::kJavaScriptFunction, 1, 0,
shared, CALL_MAINTAINS_NATIVE_CONTEXT)),
state_values, state_values, state_values, NumberConstant(0),
UndefinedConstant(), outer_frame_state);
}
Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) {
Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer();
JSArrayBuffer::Setup(buffer, isolate(), true, bytes, byte_length);
@ -982,6 +994,72 @@ TEST_F(JSTypedLoweringTest, JSAddWithString) {
}
// -----------------------------------------------------------------------------
// JSCreateArguments
TEST_F(JSTypedLoweringTest, JSCreateArgumentsViaStub) {
Node* const closure = Parameter(Type::Any());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
Node* const frame_state = FrameState(shared, graph()->start());
Reduction r = Reduce(
graph()->NewNode(javascript()->CreateArguments(
CreateArgumentsParameters::kMappedArguments, 0),
closure, context, frame_state, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsCall(_, IsHeapConstant(CodeFactory::ArgumentsAccess(
isolate(), false, false)
.code()),
closure, IsNumberConstant(0), _, effect, control));
}
TEST_F(JSTypedLoweringTest, JSCreateArgumentsInlinedMapped) {
Node* const closure = Parameter(Type::Any());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
Node* const frame_state_outer = FrameState(shared, graph()->start());
Node* const frame_state_inner = FrameState(shared, frame_state_outer);
Reduction r = Reduce(
graph()->NewNode(javascript()->CreateArguments(
CreateArgumentsParameters::kMappedArguments, 0),
closure, context, frame_state_inner, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsFinishRegion(
IsAllocate(IsNumberConstant(Heap::kSloppyArgumentsObjectSize),
IsBeginRegion(effect), control),
_));
}
TEST_F(JSTypedLoweringTest, JSCreateArgumentsInlinedUnmapped) {
Node* const closure = Parameter(Type::Any());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
Node* const frame_state_outer = FrameState(shared, graph()->start());
Node* const frame_state_inner = FrameState(shared, frame_state_outer);
Reduction r = Reduce(
graph()->NewNode(javascript()->CreateArguments(
CreateArgumentsParameters::kUnmappedArguments, 0),
closure, context, frame_state_inner, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsFinishRegion(
IsAllocate(IsNumberConstant(Heap::kStrictArgumentsObjectSize),
IsBeginRegion(effect), control),
_));
}
// -----------------------------------------------------------------------------
// JSCreateClosure