Index: test/cctest/test-heap.cc |
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc |
index ee476db6cdc4729b1a65a560fe03734a65f2bfdb..193b617ee8f44fb01cc800a02b8d352ea52a4d71 100644 |
--- a/test/cctest/test-heap.cc |
+++ b/test/cctest/test-heap.cc |
@@ -4241,6 +4241,61 @@ TEST(WeakMapInMonomorphicCompareNilIC) { |
} |
+TEST(WeakCell) { |
+ CcTest::InitializeVM(); |
+ Isolate* isolate = CcTest::i_isolate(); |
+ v8::internal::Heap* heap = CcTest::heap(); |
+ v8::internal::Factory* factory = isolate->factory(); |
+ |
+ HandleScope outer_scope(isolate); |
+ Handle<WeakCell> weak_cell; |
+ { |
+ HandleScope inner_scope(isolate); |
+ Handle<HeapObject> value = factory->NewFixedArray(1, NOT_TENURED); |
+ weak_cell = inner_scope.CloseAndEscape(factory->NewWeakCell(value)); |
+ } |
+ CHECK(weak_cell->value()->IsFixedArray()); |
+ heap->CollectGarbage(NEW_SPACE); |
+ CHECK(weak_cell->value()->IsFixedArray()); |
+ heap->CollectGarbage(NEW_SPACE); |
+ CHECK(weak_cell->value()->IsFixedArray()); |
+ heap->CollectAllAvailableGarbage(); |
Erik Corry
2014/10/13 15:56:17
The tests should also test that the weak cell is u
ulan
2014/10/14 10:17:22
Done.
|
+ CHECK(weak_cell->value()->IsUndefined()); |
+} |
+ |
+ |
+TEST(WeakCellsWithIncrementalMarking) { |
+ CcTest::InitializeVM(); |
+ Isolate* isolate = CcTest::i_isolate(); |
+ v8::internal::Heap* heap = CcTest::heap(); |
+ v8::internal::Factory* factory = isolate->factory(); |
+ |
+ const int N = 16; |
+ HandleScope outer_scope(isolate); |
+ Handle<FixedArray> survivor = factory->NewFixedArray(1, NOT_TENURED); |
+ Handle<WeakCell> weak_cells[N]; |
+ |
+ for (int i = 0; i < N; i++) { |
+ HandleScope inner_scope(isolate); |
+ Handle<HeapObject> value = |
+ i == 0 ? survivor : factory->NewFixedArray(1, NOT_TENURED); |
+ Handle<WeakCell> weak_cell = factory->NewWeakCell(value); |
+ CHECK(weak_cell->value()->IsFixedArray()); |
+ IncrementalMarking* marking = heap->incremental_marking(); |
+ if (marking->IsStopped()) marking->Start(); |
+ marking->Step(128, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
+ heap->CollectGarbage(NEW_SPACE); |
+ CHECK(weak_cell->value()->IsFixedArray()); |
+ weak_cells[i] = inner_scope.CloseAndEscape(weak_cell); |
+ } |
+ heap->CollectAllGarbage(Heap::kNoGCFlags); |
+ CHECK_EQ(*survivor, weak_cells[0]->value()); |
+ for (int i = 1; i < N; i++) { |
+ CHECK(weak_cells[i]->value()->IsUndefined()); |
+ } |
+} |
+ |
+ |
#ifdef DEBUG |
TEST(AddInstructionChangesNewSpacePromotion) { |
i::FLAG_allow_natives_syntax = true; |