Index: test/cctest/test-code-stub-assembler.cc |
diff --git a/test/cctest/test-code-stub-assembler.cc b/test/cctest/test-code-stub-assembler.cc |
index 7035d514fd6e162144af865b1050d60ccd1b880c..a1f733b8488d7f249a65d4ea91b07b7f90822d43 100644 |
--- a/test/cctest/test-code-stub-assembler.cc |
+++ b/test/cctest/test-code-stub-assembler.cc |
@@ -1797,5 +1797,136 @@ TEST(IsDebugActive) { |
*debug_is_active = false; |
} |
+class AppendJSArrayCodeStubAssembler : public CodeStubAssembler { |
+ public: |
+ AppendJSArrayCodeStubAssembler(compiler::CodeAssemblerState* state, |
+ ElementsKind kind) |
+ : CodeStubAssembler(state), kind_(kind) {} |
+ |
+ void TestAppendJSArrayImpl(Isolate* isolate, CodeAssemblerTester* tester, |
+ Object* o1, Object* o2, Object* o3, Object* o4, |
+ int initial_size, int result_size) { |
+ typedef CodeStubAssembler::Variable Variable; |
+ typedef CodeStubAssembler::Label Label; |
+ Handle<JSArray> array = isolate->factory()->NewJSArray( |
+ kind_, 2, initial_size, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
+ JSObject::SetElement(isolate, array, 0, |
+ Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY) |
+ .Check(); |
+ JSObject::SetElement(isolate, array, 1, |
+ Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY) |
+ .Check(); |
+ CodeStubArguments args(this, IntPtrConstant(kNumParams)); |
+ Variable arg_index(this, MachineType::PointerRepresentation()); |
+ Label bailout(this); |
+ arg_index.Bind(IntPtrConstant(0)); |
+ Node* length = BuildAppendJSArray( |
+ kind_, HeapConstant(Handle<HeapObject>(isolate->context(), isolate)), |
+ HeapConstant(array), args, arg_index, &bailout); |
+ Return(length); |
+ |
+ Bind(&bailout); |
+ Return(SmiTag(IntPtrAdd(arg_index.value(), IntPtrConstant(2)))); |
+ |
+ Handle<Code> code = tester->GenerateCode(); |
+ CHECK(!code.is_null()); |
+ |
+ FunctionTester ft(code, kNumParams); |
+ |
+ Handle<Object> result = |
+ ft.Call(Handle<Object>(o1, isolate), Handle<Object>(o2, isolate), |
+ Handle<Object>(o3, isolate), Handle<Object>(o4, isolate)) |
+ .ToHandleChecked(); |
+ |
+ CHECK_EQ(kind_, array->GetElementsKind()); |
+ CHECK_EQ(result_size, Handle<Smi>::cast(result)->value()); |
+ CHECK_EQ(result_size, Smi::cast(array->length())->value()); |
+ Object* obj = *JSObject::GetElement(isolate, array, 2).ToHandleChecked(); |
+ CHECK_EQ(result_size < 3 ? isolate->heap()->undefined_value() : o1, obj); |
+ obj = *JSObject::GetElement(isolate, array, 3).ToHandleChecked(); |
+ CHECK_EQ(result_size < 4 ? isolate->heap()->undefined_value() : o2, obj); |
+ obj = *JSObject::GetElement(isolate, array, 4).ToHandleChecked(); |
+ CHECK_EQ(result_size < 5 ? isolate->heap()->undefined_value() : o3, obj); |
+ obj = *JSObject::GetElement(isolate, array, 5).ToHandleChecked(); |
+ CHECK_EQ(result_size < 6 ? isolate->heap()->undefined_value() : o4, obj); |
+ } |
+ |
+ static void TestAppendJSArray(Isolate* isolate, ElementsKind kind, Object* o1, |
+ Object* o2, Object* o3, Object* o4, |
+ int initial_size, int result_size) { |
+ CodeAssemblerTester data(isolate, kNumParams); |
+ AppendJSArrayCodeStubAssembler m(data.state(), kind); |
+ m.TestAppendJSArrayImpl(isolate, &data, o1, o2, o3, o4, initial_size, |
+ result_size); |
+ } |
+ |
+ private: |
+ static const int kNumParams = 4; |
+ ElementsKind kind_; |
+}; |
+ |
+TEST(BuildAppendJSArrayFastElement) { |
+ Isolate* isolate(CcTest::InitIsolateOnce()); |
+ AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
+ isolate, FAST_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), Smi::FromInt(5), |
+ Smi::FromInt(6), 6, 6); |
+} |
+ |
+TEST(BuildAppendJSArrayFastElementGrow) { |
+ Isolate* isolate(CcTest::InitIsolateOnce()); |
+ AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
+ isolate, FAST_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), Smi::FromInt(5), |
+ Smi::FromInt(6), 2, 6); |
+} |
+ |
+TEST(BuildAppendJSArrayFastSmiElement) { |
+ Isolate* isolate(CcTest::InitIsolateOnce()); |
+ AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
+ isolate, FAST_SMI_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
+ Smi::FromInt(5), Smi::FromInt(6), 6, 6); |
+} |
+ |
+TEST(BuildAppendJSArrayFastSmiElementGrow) { |
+ Isolate* isolate(CcTest::InitIsolateOnce()); |
+ AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
+ isolate, FAST_SMI_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
+ Smi::FromInt(5), Smi::FromInt(6), 2, 6); |
+} |
+ |
+TEST(BuildAppendJSArrayFastSmiElementObject) { |
+ Isolate* isolate(CcTest::InitIsolateOnce()); |
+ AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
+ isolate, FAST_SMI_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
+ isolate->heap()->undefined_value(), Smi::FromInt(6), 6, 4); |
+} |
+ |
+TEST(BuildAppendJSArrayFastSmiElementObjectGrow) { |
+ Isolate* isolate(CcTest::InitIsolateOnce()); |
+ AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
+ isolate, FAST_SMI_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
+ isolate->heap()->undefined_value(), Smi::FromInt(6), 2, 4); |
+} |
+ |
+TEST(BuildAppendJSArrayFastDoubleElements) { |
+ Isolate* isolate(CcTest::InitIsolateOnce()); |
+ AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
+ isolate, FAST_DOUBLE_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
+ Smi::FromInt(5), Smi::FromInt(6), 6, 6); |
+} |
+ |
+TEST(BuildAppendJSArrayFastDoubleElementsGrow) { |
+ Isolate* isolate(CcTest::InitIsolateOnce()); |
+ AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
+ isolate, FAST_DOUBLE_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
+ Smi::FromInt(5), Smi::FromInt(6), 2, 6); |
+} |
+ |
+TEST(BuildAppendJSArrayFastDoubleElementsObject) { |
+ Isolate* isolate(CcTest::InitIsolateOnce()); |
+ AppendJSArrayCodeStubAssembler::TestAppendJSArray( |
+ isolate, FAST_DOUBLE_ELEMENTS, Smi::FromInt(3), Smi::FromInt(4), |
+ isolate->heap()->undefined_value(), Smi::FromInt(6), 6, 4); |
+} |
+ |
} // namespace internal |
} // namespace v8 |