Chromium Code Reviews| Index: Source/heap/tests/HeapTest.cpp |
| diff --git a/Source/heap/tests/HeapTest.cpp b/Source/heap/tests/HeapTest.cpp |
| index c1bd56f8db226ecb9217606d9af3223584053420..76e9b95c7f88a27f048ad451422d65d98973dbd4 100644 |
| --- a/Source/heap/tests/HeapTest.cpp |
| +++ b/Source/heap/tests/HeapTest.cpp |
| @@ -348,6 +348,8 @@ public: |
| static void refCountedHeapAllocatedTest() |
| { |
| + RefCountedAndHeapAllocated::s_destructorCalls = 0; |
| + RefCountedAndHeapAllocated2::s_destructorCalls = 0; |
| { |
| RefPtr<RefCountedAndHeapAllocated> o1 = RefCountedAndHeapAllocated::create(); |
| RefPtr<RefCountedAndHeapAllocated> o2 = RefCountedAndHeapAllocated::create(); |
| @@ -367,6 +369,50 @@ public: |
| ASSERT_EQ(2, RefCountedAndHeapAllocated2::s_destructorCalls); |
| } |
| + static void refCountedHeapAllocatedWithHandlesTest() |
| + { |
| + RefCountedAndHeapAllocated::s_destructorCalls = 0; |
| + RefCountedAndHeapAllocated2::s_destructorCalls = 0; |
| + { |
| + HandleScope scope; |
| + Handle<RefCountedAndHeapAllocated> handle1; |
| + Handle<RefCountedAndHeapAllocated> handle2; |
| + { |
| + RefPtr<RefCountedAndHeapAllocated> object1 = RefCountedAndHeapAllocated::create(); |
| + RefPtr<RefCountedAndHeapAllocated> object2 = RefCountedAndHeapAllocated::create(); |
| + handle1 = Handle<RefCountedAndHeapAllocated>(object1.get()); |
| + handle2 = Handle<RefCountedAndHeapAllocated>(object2.get()); |
| + void* objects[2] = { object1.get(), object2.get() }; |
| + RefCountedHeapAllocatedHandleVisitor visitor(2, objects); |
| + PersistentBase::visitRoots(&visitor); |
| + ASSERT_TRUE(visitor.validate()); |
| + |
| + Heap::collectGarbage(); |
| + ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); |
| + } |
| + Heap::collectGarbage(); |
| + ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); |
| + |
| + // At this point, the reference counts of object1 and object2 are 0. |
| + // Only handle1 and handle2 keep references to object1 and object2. |
|
Mads Ager (google)
2013/05/29 13:47:54
Maybe check that PersistentBase::visitRoots does n
|
| + |
| + { |
| + RefPtr<RefCountedAndHeapAllocated> object1 = adoptRef(handle1.raw()); |
| + RefPtr<RefCountedAndHeapAllocated> object2 = adoptRef(handle2.raw()); |
| + handle1 = Handle<RefCountedAndHeapAllocated>(object1.get()); |
|
Mads Ager (google)
2013/05/29 13:47:54
These lines are just reassigning the same value to
haraken
2013/05/29 14:52:16
Good catch! I verified that PersistentBase::visitR
|
| + handle2 = Handle<RefCountedAndHeapAllocated>(object2.get()); |
| + |
| + Heap::collectGarbage(); |
| + ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); |
| + } |
| + |
| + Heap::collectGarbage(); |
| + ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); |
| + } |
| + Heap::collectGarbage(); |
| + ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls); |
| + } |
| + |
| static void markTest(); |
| static void deepTest(); |
| static void wideTest(); |
| @@ -584,6 +630,11 @@ TEST(heap, RefCountedHeapAllocated) |
| HeapTester::refCountedHeapAllocatedTest(); |
| } |
| +TEST(heap, RefCountedHeapAllocatedWithHandles) |
| +{ |
| + HeapTester::refCountedHeapAllocatedWithHandlesTest(); |
| +} |
| + |
| TEST(heap, Mark) |
| { |
| HeapTester::markTest(); |