| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 IntWrapper(int x) : x_(x) {} | 81 IntWrapper(int x) : x_(x) {} |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 IntWrapper(); | 84 IntWrapper(); |
| 85 int x_; | 85 int x_; |
| 86 }; | 86 }; |
| 87 static_assert(WTF::IsTraceable<IntWrapper>::value, | 87 static_assert(WTF::IsTraceable<IntWrapper>::value, |
| 88 "IsTraceable<> template failed to recognize trace method."); | 88 "IsTraceable<> template failed to recognize trace method."); |
| 89 | 89 |
| 90 class KeyWithCopyingMoveConstructor final { |
| 91 public: |
| 92 struct Hash final { |
| 93 STATIC_ONLY(Hash); |
| 94 |
| 95 public: |
| 96 static unsigned GetHash(const KeyWithCopyingMoveConstructor& key) { |
| 97 return key.hash_; |
| 98 } |
| 99 |
| 100 static bool Equal(const KeyWithCopyingMoveConstructor& x, |
| 101 const KeyWithCopyingMoveConstructor& y) { |
| 102 return x.hash_ == y.hash_; |
| 103 } |
| 104 |
| 105 static constexpr bool safe_to_compare_to_empty_or_deleted = true; |
| 106 }; |
| 107 |
| 108 KeyWithCopyingMoveConstructor() = default; |
| 109 KeyWithCopyingMoveConstructor(WTF::HashTableDeletedValueType) : hash_(-1) {} |
| 110 ~KeyWithCopyingMoveConstructor() = default; |
| 111 KeyWithCopyingMoveConstructor(unsigned hash, const String& string) |
| 112 : hash_(hash), string_(string) { |
| 113 DCHECK_NE(hash_, 0); |
| 114 DCHECK_NE(hash_, -1); |
| 115 } |
| 116 KeyWithCopyingMoveConstructor(const KeyWithCopyingMoveConstructor&) = default; |
| 117 // The move constructor delegates to the copy constructor intentionally. |
| 118 KeyWithCopyingMoveConstructor(KeyWithCopyingMoveConstructor&& x) |
| 119 : KeyWithCopyingMoveConstructor(x) {} |
| 120 KeyWithCopyingMoveConstructor& operator=( |
| 121 const KeyWithCopyingMoveConstructor&) = default; |
| 122 bool operator==(const KeyWithCopyingMoveConstructor& x) const { |
| 123 return hash_ == x.hash_; |
| 124 } |
| 125 |
| 126 bool IsHashTableDeletedValue() const { return hash_ == -1; } |
| 127 |
| 128 private: |
| 129 int hash_ = 0; |
| 130 String string_; |
| 131 }; |
| 132 |
| 90 struct SameSizeAsPersistent { | 133 struct SameSizeAsPersistent { |
| 91 void* pointer_[4]; | 134 void* pointer_[4]; |
| 92 }; | 135 }; |
| 93 | 136 |
| 94 static_assert(sizeof(Persistent<IntWrapper>) <= sizeof(SameSizeAsPersistent), | 137 static_assert(sizeof(Persistent<IntWrapper>) <= sizeof(SameSizeAsPersistent), |
| 95 "Persistent handle should stay small"); | 138 "Persistent handle should stay small"); |
| 96 | 139 |
| 97 class ThreadMarker { | 140 class ThreadMarker { |
| 98 public: | 141 public: |
| 99 ThreadMarker() | 142 ThreadMarker() |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 static bool IsDeletedValue(const blink::PairWithWeakHandling& value) { | 308 static bool IsDeletedValue(const blink::PairWithWeakHandling& value) { |
| 266 return value.IsHashTableDeletedValue(); | 309 return value.IsHashTableDeletedValue(); |
| 267 } | 310 } |
| 268 }; | 311 }; |
| 269 | 312 |
| 270 template <> | 313 template <> |
| 271 struct IsTraceable<blink::PairWithWeakHandling> { | 314 struct IsTraceable<blink::PairWithWeakHandling> { |
| 272 static const bool value = IsTraceable<blink::StrongWeakPair>::value; | 315 static const bool value = IsTraceable<blink::StrongWeakPair>::value; |
| 273 }; | 316 }; |
| 274 | 317 |
| 318 template <> |
| 319 struct DefaultHash<blink::KeyWithCopyingMoveConstructor> { |
| 320 using Hash = blink::KeyWithCopyingMoveConstructor::Hash; |
| 321 }; |
| 322 |
| 323 template <> |
| 324 struct HashTraits<blink::KeyWithCopyingMoveConstructor> |
| 325 : public SimpleClassHashTraits<blink::KeyWithCopyingMoveConstructor> {}; |
| 326 |
| 275 } // namespace WTF | 327 } // namespace WTF |
| 276 | 328 |
| 277 namespace blink { | 329 namespace blink { |
| 278 | 330 |
| 279 class TestGCScope { | 331 class TestGCScope { |
| 280 public: | 332 public: |
| 281 explicit TestGCScope(BlinkGC::StackState state) | 333 explicit TestGCScope(BlinkGC::StackState state) |
| 282 : state_(ThreadState::Current()), safe_point_scope_(state) { | 334 : state_(ThreadState::Current()), safe_point_scope_(state) { |
| 283 ASSERT(state_->CheckThread()); | 335 ASSERT(state_->CheckThread()); |
| 284 state_->PreGC(); | 336 state_->PreGC(); |
| (...skipping 6199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6484 WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::value, | 6536 WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::value, |
| 6485 "HeapVector"); | 6537 "HeapVector"); |
| 6486 static_assert( | 6538 static_assert( |
| 6487 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value, | 6539 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value, |
| 6488 "HeapDeque"); | 6540 "HeapDeque"); |
| 6489 static_assert(WTF::IsGarbageCollectedType< | 6541 static_assert(WTF::IsGarbageCollectedType< |
| 6490 HeapTerminatedArray<Member<IntWrapper>>>::value, | 6542 HeapTerminatedArray<Member<IntWrapper>>>::value, |
| 6491 "HeapTerminatedArray"); | 6543 "HeapTerminatedArray"); |
| 6492 } | 6544 } |
| 6493 | 6545 |
| 6546 TEST(HeapTest, HeapHashMapCallsDestructor) { |
| 6547 String string = "string"; |
| 6548 EXPECT_TRUE(string.Impl()->HasOneRef()); |
| 6549 |
| 6550 HeapHashMap<KeyWithCopyingMoveConstructor, Member<IntWrapper>> map; |
| 6551 |
| 6552 EXPECT_TRUE(string.Impl()->HasOneRef()); |
| 6553 |
| 6554 for (int i = 1; i <= 100; ++i) { |
| 6555 KeyWithCopyingMoveConstructor key(i, string); |
| 6556 map.insert(key, IntWrapper::Create(i)); |
| 6557 } |
| 6558 |
| 6559 EXPECT_FALSE(string.Impl()->HasOneRef()); |
| 6560 map.Clear(); |
| 6561 |
| 6562 EXPECT_TRUE(string.Impl()->HasOneRef()); |
| 6563 } |
| 6564 |
| 6494 } // namespace blink | 6565 } // namespace blink |
| OLD | NEW |