Index: test/cctest/test-weaktypedarrays.cc |
diff --git a/test/cctest/test-weaktypedarrays.cc b/test/cctest/test-weaktypedarrays.cc |
index c1f59de45aa3c669da0c8e1e1ff2578234c77312..aa3e432ca80de9df16da677248905c9edd3af942 100644 |
--- a/test/cctest/test-weaktypedarrays.cc |
+++ b/test/cctest/test-weaktypedarrays.cc |
@@ -62,87 +62,6 @@ static bool HasArrayBufferInWeakList(Heap* heap, JSArrayBuffer* ab) { |
} |
-static int CountViewsInNewSpaceList(Heap* heap, JSArrayBuffer* array_buffer) { |
- int count = 0; |
- for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined();) { |
- JSArrayBufferView* view = JSArrayBufferView::cast(o); |
- if (array_buffer == view->buffer()) { |
- count++; |
- } |
- o = view->weak_next(); |
- } |
- return count; |
-} |
- |
- |
-static int CountViews(Heap* heap, JSArrayBuffer* array_buffer) { |
- int count = 0; |
- for (Object* o = array_buffer->weak_first_view(); |
- !o->IsUndefined(); |
- o = JSArrayBufferView::cast(o)->weak_next()) { |
- count++; |
- } |
- |
- return count + CountViewsInNewSpaceList(heap, array_buffer); |
-} |
- |
- |
-static bool HasViewInNewSpaceList(Heap* heap, JSArrayBufferView* ta) { |
- for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined(); |
- o = JSArrayBufferView::cast(o)->weak_next()) { |
- if (ta == o) return true; |
- } |
- return false; |
-} |
- |
- |
-static bool HasViewInWeakList(Heap* heap, JSArrayBuffer* array_buffer, |
- JSArrayBufferView* ta) { |
- for (Object* o = array_buffer->weak_first_view(); |
- !o->IsUndefined(); |
- o = JSArrayBufferView::cast(o)->weak_next()) { |
- if (ta == o) return true; |
- } |
- return HasViewInNewSpaceList(heap, ta); |
-} |
- |
- |
-TEST(WeakArrayBuffersFromApi) { |
- v8::V8::Initialize(); |
- LocalContext context; |
- Isolate* isolate = GetIsolateFrom(&context); |
- |
- int start = CountArrayBuffersInWeakList(isolate->heap()); |
- { |
- v8::HandleScope s1(context->GetIsolate()); |
- v8::Handle<v8::ArrayBuffer> ab1 = |
- v8::ArrayBuffer::New(context->GetIsolate(), 256); |
- { |
- v8::HandleScope s2(context->GetIsolate()); |
- v8::Handle<v8::ArrayBuffer> ab2 = |
- v8::ArrayBuffer::New(context->GetIsolate(), 128); |
- |
- Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); |
- Handle<JSArrayBuffer> iab2 = v8::Utils::OpenHandle(*ab2); |
- CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap()) - start); |
- CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); |
- CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab2)); |
- } |
- isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); |
- { |
- HandleScope scope2(isolate); |
- Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); |
- |
- CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); |
- } |
- } |
- |
- isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
- CHECK_EQ(start, CountArrayBuffersInWeakList(isolate->heap())); |
-} |
- |
- |
TEST(WeakArrayBuffersFromScript) { |
v8::V8::Initialize(); |
LocalContext context; |
@@ -203,217 +122,3 @@ TEST(WeakArrayBuffersFromScript) { |
CHECK_EQ(start, CountArrayBuffersInWeakList(isolate->heap())); |
} |
} |
- |
-template <typename View> |
-void TestViewFromApi() { |
- v8::V8::Initialize(); |
- LocalContext context; |
- Isolate* isolate = GetIsolateFrom(&context); |
- |
- v8::HandleScope s1(context->GetIsolate()); |
- v8::Handle<v8::ArrayBuffer> ab = |
- v8::ArrayBuffer::New(context->GetIsolate(), 2048); |
- Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
- { |
- v8::HandleScope s2(context->GetIsolate()); |
- v8::Handle<View> ta1 = View::New(ab, 0, 256); |
- { |
- v8::HandleScope s3(context->GetIsolate()); |
- v8::Handle<View> ta2 = View::New(ab, 0, 128); |
- |
- Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); |
- Handle<JSArrayBufferView> ita2 = v8::Utils::OpenHandle(*ta2); |
- CHECK_EQ(2, CountViews(isolate->heap(), *iab)); |
- CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1)); |
- CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita2)); |
- } |
- isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
- CHECK_EQ(1, CountViews(isolate->heap(), *iab)); |
- Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); |
- CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1)); |
- } |
- isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
- |
- CHECK_EQ(0, CountViews(isolate->heap(), *iab)); |
-} |
- |
- |
-TEST(Uint8ArrayFromApi) { |
- TestViewFromApi<v8::Uint8Array>(); |
-} |
- |
- |
-TEST(Int8ArrayFromApi) { |
- TestViewFromApi<v8::Int8Array>(); |
-} |
- |
- |
-TEST(Uint16ArrayFromApi) { |
- TestViewFromApi<v8::Uint16Array>(); |
-} |
- |
- |
-TEST(Int16ArrayFromApi) { |
- TestViewFromApi<v8::Int16Array>(); |
-} |
- |
- |
-TEST(Uint32ArrayFromApi) { |
- TestViewFromApi<v8::Uint32Array>(); |
-} |
- |
- |
-TEST(Int32ArrayFromApi) { |
- TestViewFromApi<v8::Int32Array>(); |
-} |
- |
- |
-TEST(Float32ArrayFromApi) { |
- TestViewFromApi<v8::Float32Array>(); |
-} |
- |
- |
-TEST(Float64ArrayFromApi) { |
- TestViewFromApi<v8::Float64Array>(); |
-} |
- |
- |
-TEST(Uint8ClampedArrayFromApi) { |
- TestViewFromApi<v8::Uint8ClampedArray>(); |
-} |
- |
- |
-TEST(DataViewFromApi) { |
- TestViewFromApi<v8::DataView>(); |
-} |
- |
-template <typename TypedArray> |
-static void TestTypedArrayFromScript(const char* constructor) { |
- v8::V8::Initialize(); |
- LocalContext context; |
- Isolate* isolate = GetIsolateFrom(&context); |
- v8::HandleScope scope(context->GetIsolate()); |
- int start = CountArrayBuffersInWeakList(isolate->heap()); |
- CompileRun("var ab = new ArrayBuffer(2048);"); |
- for (int i = 1; i <= 3; i++) { |
- // Create 3 typed arrays, make i-th of them garbage, |
- // validate correct state of typed array weak list. |
- v8::HandleScope s0(context->GetIsolate()); |
- i::ScopedVector<char> source(2048); |
- |
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); |
- |
- { |
- v8::HandleScope s1(context->GetIsolate()); |
- i::SNPrintF(source, |
- "var ta1 = new %s(ab);" |
- "var ta2 = new %s(ab);" |
- "var ta3 = new %s(ab)", |
- constructor, constructor, constructor); |
- |
- CompileRun(source.start()); |
- v8::Handle<v8::ArrayBuffer> ab = |
- v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
- v8::Handle<TypedArray> ta1 = |
- v8::Handle<TypedArray>::Cast(CompileRun("ta1")); |
- v8::Handle<TypedArray> ta2 = |
- v8::Handle<TypedArray>::Cast(CompileRun("ta2")); |
- v8::Handle<TypedArray> ta3 = |
- v8::Handle<TypedArray>::Cast(CompileRun("ta3")); |
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); |
- Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
- CHECK_EQ(3, CountViews(isolate->heap(), *iab)); |
- CHECK(HasViewInWeakList(isolate->heap(), *iab, |
- *v8::Utils::OpenHandle(*ta1))); |
- CHECK(HasViewInWeakList(isolate->heap(), *iab, |
- *v8::Utils::OpenHandle(*ta2))); |
- CHECK(HasViewInWeakList(isolate->heap(), *iab, |
- *v8::Utils::OpenHandle(*ta3))); |
- } |
- |
- i::SNPrintF(source, "ta%d = null;", i); |
- CompileRun(source.start()); |
- isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
- |
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); |
- |
- { |
- v8::HandleScope s2(context->GetIsolate()); |
- v8::Handle<v8::ArrayBuffer> ab = |
- v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
- Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
- CHECK_EQ(2, CountViews(isolate->heap(), *iab)); |
- for (int j = 1; j <= 3; j++) { |
- if (j == i) continue; |
- i::SNPrintF(source, "ta%d", j); |
- v8::Handle<TypedArray> ta = |
- v8::Handle<TypedArray>::Cast(CompileRun(source.start())); |
- CHECK(HasViewInWeakList(isolate->heap(), *iab, |
- *v8::Utils::OpenHandle(*ta))); |
- } |
- } |
- |
- CompileRun("ta1 = null; ta2 = null; ta3 = null;"); |
- isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
- |
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); |
- |
- { |
- v8::HandleScope s3(context->GetIsolate()); |
- v8::Handle<v8::ArrayBuffer> ab = |
- v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
- Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
- CHECK_EQ(0, CountViews(isolate->heap(), *iab)); |
- } |
- } |
-} |
- |
- |
-TEST(Uint8ArrayFromScript) { |
- TestTypedArrayFromScript<v8::Uint8Array>("Uint8Array"); |
-} |
- |
- |
-TEST(Int8ArrayFromScript) { |
- TestTypedArrayFromScript<v8::Int8Array>("Int8Array"); |
-} |
- |
- |
-TEST(Uint16ArrayFromScript) { |
- TestTypedArrayFromScript<v8::Uint16Array>("Uint16Array"); |
-} |
- |
- |
-TEST(Int16ArrayFromScript) { |
- TestTypedArrayFromScript<v8::Int16Array>("Int16Array"); |
-} |
- |
- |
-TEST(Uint32ArrayFromScript) { |
- TestTypedArrayFromScript<v8::Uint32Array>("Uint32Array"); |
-} |
- |
- |
-TEST(Int32ArrayFromScript) { |
- TestTypedArrayFromScript<v8::Int32Array>("Int32Array"); |
-} |
- |
- |
-TEST(Float32ArrayFromScript) { |
- TestTypedArrayFromScript<v8::Float32Array>("Float32Array"); |
-} |
- |
- |
-TEST(Float64ArrayFromScript) { |
- TestTypedArrayFromScript<v8::Float64Array>("Float64Array"); |
-} |
- |
- |
-TEST(Uint8ClampedArrayFromScript) { |
- TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); |
-} |
- |
- |
-TEST(DataViewFromScript) { |
- TestTypedArrayFromScript<v8::DataView>("DataView"); |
-} |