| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 { | 1107 { |
| 1108 ObserverMap& map = observers(); | 1108 ObserverMap& map = observers(); |
| 1109 ObserverMap::AddResult result = map.add(&target, nullptr); | 1109 ObserverMap::AddResult result = map.add(&target, nullptr); |
| 1110 if (result.isNewEntry) | 1110 if (result.isNewEntry) |
| 1111 result.storedValue->value = adoptPtr(new FinalizationObserverWithHas
hMap(target)); | 1111 result.storedValue->value = adoptPtr(new FinalizationObserverWithHas
hMap(target)); |
| 1112 else | 1112 else |
| 1113 ASSERT(result.storedValue->value); | 1113 ASSERT(result.storedValue->value); |
| 1114 return map; | 1114 return map; |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 static void clearObservers() |
| 1118 { |
| 1119 delete s_observerMap; |
| 1120 s_observerMap = nullptr; |
| 1121 } |
| 1122 |
| 1117 static bool s_didCallWillFinalize; | 1123 static bool s_didCallWillFinalize; |
| 1118 | 1124 |
| 1119 private: | 1125 private: |
| 1120 static ObserverMap& observers() | 1126 static ObserverMap& observers() |
| 1121 { | 1127 { |
| 1122 DEFINE_STATIC_LOCAL(Persistent<ObserverMap>, observerMap, ()); | 1128 if (!s_observerMap) |
| 1123 if (!observerMap) | 1129 s_observerMap = new Persistent<ObserverMap>(new ObserverMap()); |
| 1124 observerMap = new ObserverMap(); | 1130 return **s_observerMap; |
| 1125 return *observerMap; | |
| 1126 } | 1131 } |
| 1127 | 1132 |
| 1128 Observable& m_target; | 1133 Observable& m_target; |
| 1134 static Persistent<ObserverMap>* s_observerMap; |
| 1129 }; | 1135 }; |
| 1130 | 1136 |
| 1131 bool FinalizationObserverWithHashMap::s_didCallWillFinalize = false; | 1137 bool FinalizationObserverWithHashMap::s_didCallWillFinalize = false; |
| 1138 Persistent<FinalizationObserverWithHashMap::ObserverMap>* FinalizationObserverWi
thHashMap::s_observerMap; |
| 1132 | 1139 |
| 1133 class SuperClass; | 1140 class SuperClass; |
| 1134 | 1141 |
| 1135 class PointsBack : public RefCountedWillBeGarbageCollectedFinalized<PointsBack>
{ | 1142 class PointsBack : public RefCountedWillBeGarbageCollectedFinalized<PointsBack>
{ |
| 1136 public: | 1143 public: |
| 1137 static PassRefPtrWillBeRawPtr<PointsBack> create() | 1144 static PassRefPtrWillBeRawPtr<PointsBack> create() |
| 1138 { | 1145 { |
| 1139 return adoptRefWillBeNoop(new PointsBack()); | 1146 return adoptRefWillBeNoop(new PointsBack()); |
| 1140 } | 1147 } |
| 1141 | 1148 |
| (...skipping 2162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3304 Observable* foo = Observable::create(Bar::create()); | 3311 Observable* foo = Observable::create(Bar::create()); |
| 3305 FinalizationObserverWithHashMap::ObserverMap& map = FinalizationObserverWith
HashMap::observe(*foo); | 3312 FinalizationObserverWithHashMap::ObserverMap& map = FinalizationObserverWith
HashMap::observe(*foo); |
| 3306 EXPECT_EQ(1u, map.size()); | 3313 EXPECT_EQ(1u, map.size()); |
| 3307 foo = 0; | 3314 foo = 0; |
| 3308 // FinalizationObserverWithHashMap doesn't have a strong reference to | 3315 // FinalizationObserverWithHashMap doesn't have a strong reference to |
| 3309 // |foo|. So |foo| and its member will be collected. | 3316 // |foo|. So |foo| and its member will be collected. |
| 3310 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3317 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 3311 EXPECT_EQ(0u, Bar::s_live); | 3318 EXPECT_EQ(0u, Bar::s_live); |
| 3312 EXPECT_EQ(0u, map.size()); | 3319 EXPECT_EQ(0u, map.size()); |
| 3313 EXPECT_TRUE(FinalizationObserverWithHashMap::s_didCallWillFinalize); | 3320 EXPECT_TRUE(FinalizationObserverWithHashMap::s_didCallWillFinalize); |
| 3321 |
| 3322 FinalizationObserverWithHashMap::clearObservers(); |
| 3314 } | 3323 } |
| 3315 | 3324 |
| 3316 TEST(HeapTest, PreFinalizer) | 3325 TEST(HeapTest, PreFinalizer) |
| 3317 { | 3326 { |
| 3318 Observable::s_willFinalizeWasCalled = false; | 3327 Observable::s_willFinalizeWasCalled = false; |
| 3319 { | 3328 { |
| 3320 Observable* foo = Observable::create(Bar::create()); | 3329 Observable* foo = Observable::create(Bar::create()); |
| 3321 ThreadState::current()->registerPreFinalizer(*foo); | 3330 ThreadState::current()->registerPreFinalizer(*foo); |
| 3322 } | 3331 } |
| 3323 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3332 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| (...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5397 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) | 5406 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) |
| 5398 { | 5407 { |
| 5399 new NonNodeAllocatingNodeInDestructor(); | 5408 new NonNodeAllocatingNodeInDestructor(); |
| 5400 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 5409 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 5401 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); | 5410 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); |
| 5402 delete NonNodeAllocatingNodeInDestructor::s_node; | 5411 delete NonNodeAllocatingNodeInDestructor::s_node; |
| 5403 NonNodeAllocatingNodeInDestructor::s_node = 0; | 5412 NonNodeAllocatingNodeInDestructor::s_node = 0; |
| 5404 } | 5413 } |
| 5405 | 5414 |
| 5406 } // namespace blink | 5415 } // namespace blink |
| OLD | NEW |