Commit 72ab46bd authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[in-place weak refs] Add test for WeakArrayList::RemoveOne.

BUG=v8:7308

Change-Id: Ibf87a807202d8f1e0e7c095bf6b3790b0f0954bf
Reviewed-on: https://chromium-review.googlesource.com/1154907Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54784}
parent b45fdb34
......@@ -535,6 +535,62 @@ TEST(WeakArrayListBasic) {
CHECK_EQ(Smi::ToInt(array->Get(7)->ToSmi()), 7);
}
TEST(WeakArrayListRemove) {
ManualGCScope manual_gc_scope;
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
HandleScope outer_scope(isolate);
Handle<WeakArrayList> array(ReadOnlyRoots(heap).empty_weak_array_list(),
isolate);
Handle<FixedArray> elem0 = factory->NewFixedArray(1);
Handle<FixedArray> elem1 = factory->NewFixedArray(1);
Handle<FixedArray> elem2 = factory->NewFixedArray(1);
array =
WeakArrayList::AddToEnd(isolate, array, MaybeObjectHandle::Weak(elem0));
array =
WeakArrayList::AddToEnd(isolate, array, MaybeObjectHandle::Weak(elem1));
array =
WeakArrayList::AddToEnd(isolate, array, MaybeObjectHandle::Weak(elem2));
CHECK_EQ(array->length(), 3);
CHECK_EQ(array->Get(0), HeapObjectReference::Weak(*elem0));
CHECK_EQ(array->Get(1), HeapObjectReference::Weak(*elem1));
CHECK_EQ(array->Get(2), HeapObjectReference::Weak(*elem2));
CHECK(array->RemoveOne(MaybeObjectHandle::Weak(elem1)));
CHECK_EQ(array->length(), 3);
CHECK_EQ(array->Get(0), HeapObjectReference::Weak(*elem0));
CHECK(array->Get(1)->IsClearedWeakHeapObject());
CHECK_EQ(array->Get(2), HeapObjectReference::Weak(*elem2));
CHECK(!array->RemoveOne(MaybeObjectHandle::Weak(elem1)));
CHECK_EQ(array->length(), 3);
CHECK_EQ(array->Get(0), HeapObjectReference::Weak(*elem0));
CHECK(array->Get(1)->IsClearedWeakHeapObject());
CHECK_EQ(array->Get(2), HeapObjectReference::Weak(*elem2));
CHECK(array->RemoveOne(MaybeObjectHandle::Weak(elem0)));
CHECK_EQ(array->length(), 3);
CHECK(array->Get(0)->IsClearedWeakHeapObject());
CHECK(array->Get(1)->IsClearedWeakHeapObject());
CHECK_EQ(array->Get(2), HeapObjectReference::Weak(*elem2));
CHECK(array->RemoveOne(MaybeObjectHandle::Weak(elem2)));
// Removing the last element decreases the array length.
CHECK_EQ(array->length(), 2);
CHECK(array->Get(0)->IsClearedWeakHeapObject());
CHECK(array->Get(1)->IsClearedWeakHeapObject());
}
TEST(Regress7768) {
i::FLAG_allow_natives_syntax = true;
i::FLAG_turbo_inlining = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment