Index: Source/heap/tests/HeapTest.cpp |
diff --git a/Source/heap/tests/HeapTest.cpp b/Source/heap/tests/HeapTest.cpp |
index c1bd56f8db226ecb9217606d9af3223584053420..c7776ee5438f151f38e4966f70df4a061ce64ec0 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,56 @@ 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. |
+ void* objects[] = { }; |
+ RefCountedHeapAllocatedHandleVisitor visitor(0, objects); |
+ PersistentBase::visitRoots(&visitor); |
+ ASSERT_TRUE(visitor.validate()); |
+ |
+ { |
+ RefPtr<RefCountedAndHeapAllocated> object1(handle1.raw()); |
+ RefPtr<RefCountedAndHeapAllocated> object2(handle2.raw()); |
+ 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); |
+ } |
+ Heap::collectGarbage(); |
+ ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls); |
+ } |
+ |
static void markTest(); |
static void deepTest(); |
static void wideTest(); |
@@ -584,6 +636,11 @@ TEST(heap, RefCountedHeapAllocated) |
HeapTester::refCountedHeapAllocatedTest(); |
} |
+TEST(heap, RefCountedHeapAllocatedWithHandles) |
+{ |
+ HeapTester::refCountedHeapAllocatedWithHandlesTest(); |
+} |
+ |
TEST(heap, Mark) |
{ |
HeapTester::markTest(); |