Index: third_party/WebKit/Source/platform/heap/HeapTest.cpp |
diff --git a/third_party/WebKit/Source/platform/heap/HeapTest.cpp b/third_party/WebKit/Source/platform/heap/HeapTest.cpp |
index 37e9aaef365e79ab770e66f8da9db5098621eab5..1d9e62cb1162d22aed21f7cd5bd350ec8832414a 100644 |
--- a/third_party/WebKit/Source/platform/heap/HeapTest.cpp |
+++ b/third_party/WebKit/Source/platform/heap/HeapTest.cpp |
@@ -1499,6 +1499,48 @@ class PreFinalizationAllocator |
Persistent<IntWrapper>* wrapper_; |
}; |
+class PreFinalizerBackingReallocationForbiddenCheck |
+ : public GarbageCollectedFinalized< |
+ PreFinalizerBackingReallocationForbiddenCheck> { |
+ USING_PRE_FINALIZER(PreFinalizerBackingReallocationForbiddenCheck, Dispose); |
+ |
+ public: |
+ PreFinalizerBackingReallocationForbiddenCheck() { |
+ vector_.push_back(nullptr); |
+ EXPECT_LT(0ul, vector_.Capacity()); |
+ for (int i = 1; i <= 32; ++i) { |
+ map_.insert(i, nullptr); |
+ } |
+ EXPECT_LT(32ul, map_.Capacity()); |
+ } |
+ |
+ void Dispose() { |
+ vector_.Clear(); |
+ EXPECT_LT(0ul, vector_.Capacity()); |
+ for (int i = 1; i <= 32; ++i) { |
+ map_.erase(i); |
+ } |
+ EXPECT_LT(32ul, map_.Capacity()); |
+ // Clearing is OK inside a pre finalizer. |
+ map_.Clear(); |
+ EXPECT_EQ(0ul, map_.Capacity()); |
+ } |
+ |
+ DEFINE_INLINE_TRACE() { |
+ visitor->Trace(vector_); |
+ visitor->Trace(map_); |
+ } |
+ |
+ private: |
+ HeapVector<Member<IntWrapper>> vector_; |
+ HeapHashMap<int, Member<IntWrapper>> map_; |
+}; |
+ |
+TEST(HeapTest, BackingReallocationForbidden) { |
+ new PreFinalizerBackingReallocationForbiddenCheck(); |
+ PreciselyCollectGarbage(); |
+} |
+ |
TEST(HeapTest, Transition) { |
{ |
RefCountedAndGarbageCollected::destructor_calls_ = 0; |