| 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 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 explicit FinalizationObserverWithHashMap(Observable& target) | 1284 explicit FinalizationObserverWithHashMap(Observable& target) |
| 1285 : m_target(target) {} | 1285 : m_target(target) {} |
| 1286 ~FinalizationObserverWithHashMap() { | 1286 ~FinalizationObserverWithHashMap() { |
| 1287 m_target.willFinalize(); | 1287 m_target.willFinalize(); |
| 1288 s_didCallWillFinalize = true; | 1288 s_didCallWillFinalize = true; |
| 1289 } | 1289 } |
| 1290 | 1290 |
| 1291 static ObserverMap& observe(Observable& target) { | 1291 static ObserverMap& observe(Observable& target) { |
| 1292 ObserverMap& map = observers(); | 1292 ObserverMap& map = observers(); |
| 1293 ObserverMap::AddResult result = map.add(&target, nullptr); | 1293 ObserverMap::AddResult result = map.add(&target, nullptr); |
| 1294 if (result.isNewEntry) | 1294 if (result.isNewEntry) { |
| 1295 result.storedValue->value = | 1295 result.storedValue->value = |
| 1296 wrapUnique(new FinalizationObserverWithHashMap(target)); | 1296 makeUnique<FinalizationObserverWithHashMap>(target); |
| 1297 else | 1297 } else { |
| 1298 ASSERT(result.storedValue->value); | 1298 ASSERT(result.storedValue->value); |
| 1299 } |
| 1299 return map; | 1300 return map; |
| 1300 } | 1301 } |
| 1301 | 1302 |
| 1302 static void clearObservers() { | 1303 static void clearObservers() { |
| 1303 delete s_observerMap; | 1304 delete s_observerMap; |
| 1304 s_observerMap = nullptr; | 1305 s_observerMap = nullptr; |
| 1305 } | 1306 } |
| 1306 | 1307 |
| 1307 static bool s_didCallWillFinalize; | 1308 static bool s_didCallWillFinalize; |
| 1308 | 1309 |
| (...skipping 5172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6481 explicit WeakPersistentHolder(IntWrapper* object) : m_object(object) {} | 6482 explicit WeakPersistentHolder(IntWrapper* object) : m_object(object) {} |
| 6482 IntWrapper* object() const { return m_object; } | 6483 IntWrapper* object() const { return m_object; } |
| 6483 | 6484 |
| 6484 private: | 6485 private: |
| 6485 WeakPersistent<IntWrapper> m_object; | 6486 WeakPersistent<IntWrapper> m_object; |
| 6486 }; | 6487 }; |
| 6487 | 6488 |
| 6488 TEST(HeapTest, WeakPersistent) { | 6489 TEST(HeapTest, WeakPersistent) { |
| 6489 Persistent<IntWrapper> object = new IntWrapper(20); | 6490 Persistent<IntWrapper> object = new IntWrapper(20); |
| 6490 std::unique_ptr<WeakPersistentHolder> holder = | 6491 std::unique_ptr<WeakPersistentHolder> holder = |
| 6491 wrapUnique(new WeakPersistentHolder(object)); | 6492 makeUnique<WeakPersistentHolder>(object); |
| 6492 preciselyCollectGarbage(); | 6493 preciselyCollectGarbage(); |
| 6493 EXPECT_TRUE(holder->object()); | 6494 EXPECT_TRUE(holder->object()); |
| 6494 object = nullptr; | 6495 object = nullptr; |
| 6495 preciselyCollectGarbage(); | 6496 preciselyCollectGarbage(); |
| 6496 EXPECT_FALSE(holder->object()); | 6497 EXPECT_FALSE(holder->object()); |
| 6497 } | 6498 } |
| 6498 | 6499 |
| 6499 namespace { | 6500 namespace { |
| 6500 | 6501 |
| 6501 void workerThreadMainForCrossThreadWeakPersistentTest( | 6502 void workerThreadMainForCrossThreadWeakPersistentTest( |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6806 "HeapVector"); | 6807 "HeapVector"); |
| 6807 static_assert( | 6808 static_assert( |
| 6808 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value, | 6809 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value, |
| 6809 "HeapDeque"); | 6810 "HeapDeque"); |
| 6810 static_assert(WTF::IsGarbageCollectedType< | 6811 static_assert(WTF::IsGarbageCollectedType< |
| 6811 HeapTerminatedArray<Member<IntWrapper>>>::value, | 6812 HeapTerminatedArray<Member<IntWrapper>>>::value, |
| 6812 "HeapTerminatedArray"); | 6813 "HeapTerminatedArray"); |
| 6813 } | 6814 } |
| 6814 | 6815 |
| 6815 } // namespace blink | 6816 } // namespace blink |
| OLD | NEW |