diff --git a/src/objects-debug.cc b/src/objects-debug.cc index afad51d0cc..6f959757a4 100644 --- a/src/objects-debug.cc +++ b/src/objects-debug.cc @@ -1298,13 +1298,30 @@ void WeakCell::WeakCellVerify(Isolate* isolate) { CHECK(IsWeakCell()); CHECK(target()->IsJSReceiver() || target()->IsUndefined(isolate)); + + CHECK(prev()->IsWeakCell() || prev()->IsUndefined(isolate)); + if (prev()->IsWeakCell()) { + CHECK_EQ(WeakCell::cast(prev())->next(), *this); + } + CHECK(next()->IsWeakCell() || next()->IsUndefined(isolate)); if (next()->IsWeakCell()) { CHECK_EQ(WeakCell::cast(next())->prev(), *this); } - CHECK(prev()->IsWeakCell() || prev()->IsUndefined(isolate)); - if (prev()->IsWeakCell()) { - CHECK_EQ(WeakCell::cast(prev())->next(), *this); + + CHECK_IMPLIES(key()->IsUndefined(isolate), + key_list_prev()->IsUndefined(isolate)); + CHECK_IMPLIES(key()->IsUndefined(isolate), + key_list_next()->IsUndefined(isolate)); + + CHECK(key_list_prev()->IsWeakCell() || key_list_prev()->IsUndefined(isolate)); + if (key_list_prev()->IsWeakCell()) { + CHECK_EQ(WeakCell::cast(key_list_prev())->key_list_next(), *this); + } + + CHECK(key_list_next()->IsWeakCell() || key_list_next()->IsUndefined(isolate)); + if (key_list_next()->IsWeakCell()) { + CHECK_EQ(WeakCell::cast(key_list_next())->key_list_prev(), *this); } CHECK(finalization_group()->IsUndefined(isolate) || diff --git a/src/objects/js-weak-refs-inl.h b/src/objects/js-weak-refs-inl.h index bba9974ae5..a08cb08fcf 100644 --- a/src/objects/js-weak-refs-inl.h +++ b/src/objects/js-weak-refs-inl.h @@ -172,7 +172,9 @@ Object JSFinalizationGroup::PopClearedCellHoldings( Handle key = handle(weak_cell->key(), isolate); Handle next = handle(WeakCell::cast(weak_cell->key_list_next()), isolate); - next->set_key_list_prev(weak_cell->key_list_prev()); + DCHECK_EQ(next->key_list_prev(), *weak_cell); + next->set_key_list_prev(ReadOnlyRoots(isolate).undefined_value()); + weak_cell->set_key_list_next(ReadOnlyRoots(isolate).undefined_value()); key_map = ObjectHashTable::Put(key_map, key, next); finalization_group->set_key_map(*key_map); } else { diff --git a/test/cctest/test-js-weak-refs.cc b/test/cctest/test-js-weak-refs.cc index 0ca8eaf09e..e529c7cac9 100644 --- a/test/cctest/test-js-weak-refs.cc +++ b/test/cctest/test-js-weak-refs.cc @@ -406,9 +406,9 @@ TEST(TestJSFinalizationGroupPopClearedCellHoldings2) { *weak_cell1); } - Object cleared2 = + Object cleared1 = JSFinalizationGroup::PopClearedCellHoldings(finalization_group, isolate); - CHECK_EQ(cleared2, *holdings2); + CHECK_EQ(cleared1, *holdings2); { Handle key_map = @@ -416,9 +416,9 @@ TEST(TestJSFinalizationGroupPopClearedCellHoldings2) { VerifyWeakCellKeyChain(isolate, key_map->Lookup(key1), 1, *weak_cell1); } - Object cleared3 = + Object cleared2 = JSFinalizationGroup::PopClearedCellHoldings(finalization_group, isolate); - CHECK_EQ(cleared3, *holdings1); + CHECK_EQ(cleared2, *holdings1); { Handle key_map =