| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 25 matching lines...) Expand all Loading... |
| 36 #include "platform/heap/InlinedGlobalMarkingVisitor.h" | 36 #include "platform/heap/InlinedGlobalMarkingVisitor.h" |
| 37 #include "platform/heap/PersistentNode.h" | 37 #include "platform/heap/PersistentNode.h" |
| 38 #include "platform/heap/ThreadState.h" | 38 #include "platform/heap/ThreadState.h" |
| 39 #include "platform/heap/TraceTraits.h" | 39 #include "platform/heap/TraceTraits.h" |
| 40 #include "platform/heap/Visitor.h" | 40 #include "platform/heap/Visitor.h" |
| 41 #include "wtf/Allocator.h" | 41 #include "wtf/Allocator.h" |
| 42 #include "wtf/Atomics.h" | 42 #include "wtf/Atomics.h" |
| 43 #include "wtf/Functional.h" | 43 #include "wtf/Functional.h" |
| 44 #include "wtf/HashFunctions.h" | 44 #include "wtf/HashFunctions.h" |
| 45 #include "wtf/Locker.h" | 45 #include "wtf/Locker.h" |
| 46 #include "wtf/RawPtr.h" | |
| 47 #include "wtf/RefCounted.h" | 46 #include "wtf/RefCounted.h" |
| 48 #include "wtf/TypeTraits.h" | 47 #include "wtf/TypeTraits.h" |
| 49 | 48 |
| 50 #if defined(LEAK_SANITIZER) | 49 #if defined(LEAK_SANITIZER) |
| 51 #include "wtf/LeakAnnotations.h" | 50 #include "wtf/LeakAnnotations.h" |
| 52 #endif | 51 #endif |
| 53 | 52 |
| 54 namespace blink { | 53 namespace blink { |
| 55 | 54 |
| 56 // Marker used to annotate persistent objects and collections with, | 55 // Marker used to annotate persistent objects and collections with, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 checkPointer(); | 110 checkPointer(); |
| 112 } | 111 } |
| 113 | 112 |
| 114 template<typename U> | 113 template<typename U> |
| 115 PersistentBase(const Member<U>& other) : m_raw(other) | 114 PersistentBase(const Member<U>& other) : m_raw(other) |
| 116 { | 115 { |
| 117 initialize(); | 116 initialize(); |
| 118 checkPointer(); | 117 checkPointer(); |
| 119 } | 118 } |
| 120 | 119 |
| 121 template<typename U> | |
| 122 PersistentBase(const RawPtr<U>& other) : m_raw(other.get()) | |
| 123 { | |
| 124 initialize(); | |
| 125 checkPointer(); | |
| 126 } | |
| 127 | |
| 128 ~PersistentBase() | 120 ~PersistentBase() |
| 129 { | 121 { |
| 130 uninitialize(); | 122 uninitialize(); |
| 131 m_raw = nullptr; | 123 m_raw = nullptr; |
| 132 } | 124 } |
| 133 | 125 |
| 134 template<typename VisitorDispatcher> | 126 template<typename VisitorDispatcher> |
| 135 void trace(VisitorDispatcher visitor) | 127 void trace(VisitorDispatcher visitor) |
| 136 { | 128 { |
| 137 static_assert(sizeof(T), "T must be fully defined"); | 129 static_assert(sizeof(T), "T must be fully defined"); |
| 138 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage
collected object"); | 130 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage
collected object"); |
| 139 if (weaknessConfiguration == WeakPersistentConfiguration) { | 131 if (weaknessConfiguration == WeakPersistentConfiguration) { |
| 140 visitor->registerWeakCell(&m_raw); | 132 visitor->registerWeakCell(&m_raw); |
| 141 } else { | 133 } else { |
| 142 visitor->mark(m_raw); | 134 visitor->mark(m_raw); |
| 143 } | 135 } |
| 144 } | 136 } |
| 145 | 137 |
| 146 T* release() | 138 T* release() |
| 147 { | 139 { |
| 148 T* result = m_raw; | 140 T* result = m_raw; |
| 149 assign(nullptr); | 141 assign(nullptr); |
| 150 return result; | 142 return result; |
| 151 } | 143 } |
| 152 | 144 |
| 153 void clear() { assign(nullptr); } | 145 void clear() { assign(nullptr); } |
| 154 T& operator*() const { return *m_raw; } | 146 T& operator*() const { return *m_raw; } |
| 155 bool operator!() const { return !m_raw; } | 147 bool operator!() const { return !m_raw; } |
| 156 operator T*() const { return m_raw; } | 148 operator T*() const { return m_raw; } |
| 157 operator RawPtr<T>() const { return m_raw; } | |
| 158 T* operator->() const { return *this; } | 149 T* operator->() const { return *this; } |
| 159 T* get() const { return m_raw; } | 150 T* get() const { return m_raw; } |
| 160 | 151 |
| 161 template<typename U> | 152 template<typename U> |
| 162 PersistentBase& operator=(U* other) | 153 PersistentBase& operator=(U* other) |
| 163 { | 154 { |
| 164 assign(other); | 155 assign(other); |
| 165 return *this; | 156 return *this; |
| 166 } | 157 } |
| 167 | 158 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 184 return *this; | 175 return *this; |
| 185 } | 176 } |
| 186 | 177 |
| 187 template<typename U> | 178 template<typename U> |
| 188 PersistentBase& operator=(const Member<U>& other) | 179 PersistentBase& operator=(const Member<U>& other) |
| 189 { | 180 { |
| 190 assign(other); | 181 assign(other); |
| 191 return *this; | 182 return *this; |
| 192 } | 183 } |
| 193 | 184 |
| 194 template<typename U> | |
| 195 PersistentBase& operator=(const RawPtr<U>& other) | |
| 196 { | |
| 197 assign(other); | |
| 198 return *this; | |
| 199 } | |
| 200 | |
| 201 #if defined(LEAK_SANITIZER) | 185 #if defined(LEAK_SANITIZER) |
| 202 PersistentBase* registerAsStaticReference() | 186 PersistentBase* registerAsStaticReference() |
| 203 { | 187 { |
| 204 if (m_persistentNode) { | 188 if (m_persistentNode) { |
| 205 ASSERT(ThreadState::current()); | 189 ASSERT(ThreadState::current()); |
| 206 ThreadState::current()->registerStaticPersistentNode(m_persistentNod
e); | 190 ThreadState::current()->registerStaticPersistentNode(m_persistentNod
e); |
| 207 LEAK_SANITIZER_IGNORE_OBJECT(this); | 191 LEAK_SANITIZER_IGNORE_OBJECT(this); |
| 208 } | 192 } |
| 209 return this; | 193 return this; |
| 210 } | 194 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 public: | 290 public: |
| 307 Persistent() : Parent() { } | 291 Persistent() : Parent() { } |
| 308 Persistent(std::nullptr_t) : Parent(nullptr) { } | 292 Persistent(std::nullptr_t) : Parent(nullptr) { } |
| 309 Persistent(T* raw) : Parent(raw) { } | 293 Persistent(T* raw) : Parent(raw) { } |
| 310 Persistent(T& raw) : Parent(raw) { } | 294 Persistent(T& raw) : Parent(raw) { } |
| 311 Persistent(const Persistent& other) : Parent(other) { } | 295 Persistent(const Persistent& other) : Parent(other) { } |
| 312 template<typename U> | 296 template<typename U> |
| 313 Persistent(const Persistent<U>& other) : Parent(other) { } | 297 Persistent(const Persistent<U>& other) : Parent(other) { } |
| 314 template<typename U> | 298 template<typename U> |
| 315 Persistent(const Member<U>& other) : Parent(other) { } | 299 Persistent(const Member<U>& other) : Parent(other) { } |
| 316 template<typename U> | |
| 317 Persistent(const RawPtr<U>& other) : Parent(other.get()) { } | |
| 318 | 300 |
| 319 template<typename U> | 301 template<typename U> |
| 320 Persistent& operator=(U* other) | 302 Persistent& operator=(U* other) |
| 321 { | 303 { |
| 322 Parent::operator=(other); | 304 Parent::operator=(other); |
| 323 return *this; | 305 return *this; |
| 324 } | 306 } |
| 325 | 307 |
| 326 Persistent& operator=(std::nullptr_t) | 308 Persistent& operator=(std::nullptr_t) |
| 327 { | 309 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 341 Parent::operator=(other); | 323 Parent::operator=(other); |
| 342 return *this; | 324 return *this; |
| 343 } | 325 } |
| 344 | 326 |
| 345 template<typename U> | 327 template<typename U> |
| 346 Persistent& operator=(const Member<U>& other) | 328 Persistent& operator=(const Member<U>& other) |
| 347 { | 329 { |
| 348 Parent::operator=(other); | 330 Parent::operator=(other); |
| 349 return *this; | 331 return *this; |
| 350 } | 332 } |
| 351 | |
| 352 template<typename U> | |
| 353 Persistent& operator=(const RawPtr<U>& other) | |
| 354 { | |
| 355 Parent::operator=(other); | |
| 356 return *this; | |
| 357 } | |
| 358 }; | 333 }; |
| 359 | 334 |
| 360 // WeakPersistent is a way to create a weak pointer from an off-heap object | 335 // WeakPersistent is a way to create a weak pointer from an off-heap object |
| 361 // to an on-heap object. The m_raw is automatically cleared when the pointee | 336 // to an on-heap object. The m_raw is automatically cleared when the pointee |
| 362 // gets collected. | 337 // gets collected. |
| 363 // | 338 // |
| 364 // We have to construct and destruct WeakPersistent in the same thread. | 339 // We have to construct and destruct WeakPersistent in the same thread. |
| 365 // | 340 // |
| 366 // Note that collections of WeakPersistents are not supported. Use a persistent | 341 // Note that collections of WeakPersistents are not supported. Use a persistent |
| 367 // collection of WeakMembers instead. | 342 // collection of WeakMembers instead. |
| 368 // | 343 // |
| 369 // HashSet<WeakPersistent<T>> m_set; // wrong | 344 // HashSet<WeakPersistent<T>> m_set; // wrong |
| 370 // PersistentHeapHashSet<WeakMember<T>> m_set; // correct | 345 // PersistentHeapHashSet<WeakMember<T>> m_set; // correct |
| 371 template<typename T> | 346 template<typename T> |
| 372 class WeakPersistent : public PersistentBase<T, WeakPersistentConfiguration, Sin
gleThreadPersistentConfiguration> { | 347 class WeakPersistent : public PersistentBase<T, WeakPersistentConfiguration, Sin
gleThreadPersistentConfiguration> { |
| 373 typedef PersistentBase<T, WeakPersistentConfiguration, SingleThreadPersisten
tConfiguration> Parent; | 348 typedef PersistentBase<T, WeakPersistentConfiguration, SingleThreadPersisten
tConfiguration> Parent; |
| 374 public: | 349 public: |
| 375 WeakPersistent() : Parent() { } | 350 WeakPersistent() : Parent() { } |
| 376 WeakPersistent(std::nullptr_t) : Parent(nullptr) { } | 351 WeakPersistent(std::nullptr_t) : Parent(nullptr) { } |
| 377 WeakPersistent(T* raw) : Parent(raw) { } | 352 WeakPersistent(T* raw) : Parent(raw) { } |
| 378 WeakPersistent(T& raw) : Parent(raw) { } | 353 WeakPersistent(T& raw) : Parent(raw) { } |
| 379 WeakPersistent(const WeakPersistent& other) : Parent(other) { } | 354 WeakPersistent(const WeakPersistent& other) : Parent(other) { } |
| 380 template<typename U> | 355 template<typename U> |
| 381 WeakPersistent(const WeakPersistent<U>& other) : Parent(other) { } | 356 WeakPersistent(const WeakPersistent<U>& other) : Parent(other) { } |
| 382 template<typename U> | 357 template<typename U> |
| 383 WeakPersistent(const Member<U>& other) : Parent(other) { } | 358 WeakPersistent(const Member<U>& other) : Parent(other) { } |
| 384 template<typename U> | |
| 385 WeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } | |
| 386 | 359 |
| 387 template<typename U> | 360 template<typename U> |
| 388 WeakPersistent& operator=(U* other) | 361 WeakPersistent& operator=(U* other) |
| 389 { | 362 { |
| 390 Parent::operator=(other); | 363 Parent::operator=(other); |
| 391 return *this; | 364 return *this; |
| 392 } | 365 } |
| 393 | 366 |
| 394 WeakPersistent& operator=(std::nullptr_t) | 367 WeakPersistent& operator=(std::nullptr_t) |
| 395 { | 368 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 409 Parent::operator=(other); | 382 Parent::operator=(other); |
| 410 return *this; | 383 return *this; |
| 411 } | 384 } |
| 412 | 385 |
| 413 template<typename U> | 386 template<typename U> |
| 414 WeakPersistent& operator=(const Member<U>& other) | 387 WeakPersistent& operator=(const Member<U>& other) |
| 415 { | 388 { |
| 416 Parent::operator=(other); | 389 Parent::operator=(other); |
| 417 return *this; | 390 return *this; |
| 418 } | 391 } |
| 419 | |
| 420 template<typename U> | |
| 421 WeakPersistent& operator=(const RawPtr<U>& other) | |
| 422 { | |
| 423 Parent::operator=(other); | |
| 424 return *this; | |
| 425 } | |
| 426 }; | 392 }; |
| 427 | 393 |
| 428 // Unlike Persistent, we can destruct a CrossThreadPersistent in a thread | 394 // Unlike Persistent, we can destruct a CrossThreadPersistent in a thread |
| 429 // different from the construction thread. | 395 // different from the construction thread. |
| 430 template<typename T> | 396 template<typename T> |
| 431 class CrossThreadPersistent : public PersistentBase<T, NonWeakPersistentConfigur
ation, CrossThreadPersistentConfiguration> { | 397 class CrossThreadPersistent : public PersistentBase<T, NonWeakPersistentConfigur
ation, CrossThreadPersistentConfiguration> { |
| 432 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist
entConfiguration> Parent; | 398 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist
entConfiguration> Parent; |
| 433 public: | 399 public: |
| 434 CrossThreadPersistent() : Parent() { } | 400 CrossThreadPersistent() : Parent() { } |
| 435 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { } | 401 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { } |
| 436 CrossThreadPersistent(T* raw) : Parent(raw) { } | 402 CrossThreadPersistent(T* raw) : Parent(raw) { } |
| 437 CrossThreadPersistent(T& raw) : Parent(raw) { } | 403 CrossThreadPersistent(T& raw) : Parent(raw) { } |
| 438 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) {
} | 404 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) {
} |
| 439 template<typename U> | 405 template<typename U> |
| 440 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other)
{ } | 406 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other)
{ } |
| 441 template<typename U> | 407 template<typename U> |
| 442 CrossThreadPersistent(const Member<U>& other) : Parent(other) { } | 408 CrossThreadPersistent(const Member<U>& other) : Parent(other) { } |
| 443 template<typename U> | |
| 444 CrossThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { } | |
| 445 | 409 |
| 446 T* atomicGet() { return Parent::atomicGet(); } | 410 T* atomicGet() { return Parent::atomicGet(); } |
| 447 | 411 |
| 448 template<typename U> | 412 template<typename U> |
| 449 CrossThreadPersistent& operator=(U* other) | 413 CrossThreadPersistent& operator=(U* other) |
| 450 { | 414 { |
| 451 Parent::operator=(other); | 415 Parent::operator=(other); |
| 452 return *this; | 416 return *this; |
| 453 } | 417 } |
| 454 | 418 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 470 Parent::operator=(other); | 434 Parent::operator=(other); |
| 471 return *this; | 435 return *this; |
| 472 } | 436 } |
| 473 | 437 |
| 474 template<typename U> | 438 template<typename U> |
| 475 CrossThreadPersistent& operator=(const Member<U>& other) | 439 CrossThreadPersistent& operator=(const Member<U>& other) |
| 476 { | 440 { |
| 477 Parent::operator=(other); | 441 Parent::operator=(other); |
| 478 return *this; | 442 return *this; |
| 479 } | 443 } |
| 480 | |
| 481 template<typename U> | |
| 482 CrossThreadPersistent& operator=(const RawPtr<U>& other) | |
| 483 { | |
| 484 Parent::operator=(other); | |
| 485 return *this; | |
| 486 } | |
| 487 }; | 444 }; |
| 488 | 445 |
| 489 // Combines the behavior of CrossThreadPersistent and WeakPersistent. | 446 // Combines the behavior of CrossThreadPersistent and WeakPersistent. |
| 490 template<typename T> | 447 template<typename T> |
| 491 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu
ration, CrossThreadPersistentConfiguration> { | 448 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu
ration, CrossThreadPersistentConfiguration> { |
| 492 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent
Configuration> Parent; | 449 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent
Configuration> Parent; |
| 493 public: | 450 public: |
| 494 CrossThreadWeakPersistent() : Parent() { } | 451 CrossThreadWeakPersistent() : Parent() { } |
| 495 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } | 452 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } |
| 496 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } | 453 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } |
| 497 CrossThreadWeakPersistent(T& raw) : Parent(raw) { } | 454 CrossThreadWeakPersistent(T& raw) : Parent(raw) { } |
| 498 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o
ther) { } | 455 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o
ther) { } |
| 499 template<typename U> | 456 template<typename U> |
| 500 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren
t(other) { } | 457 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren
t(other) { } |
| 501 template<typename U> | 458 template<typename U> |
| 502 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { } | 459 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { } |
| 503 template<typename U> | |
| 504 CrossThreadWeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } | |
| 505 | 460 |
| 506 template<typename U> | 461 template<typename U> |
| 507 CrossThreadWeakPersistent& operator=(U* other) | 462 CrossThreadWeakPersistent& operator=(U* other) |
| 508 { | 463 { |
| 509 Parent::operator=(other); | 464 Parent::operator=(other); |
| 510 return *this; | 465 return *this; |
| 511 } | 466 } |
| 512 | 467 |
| 513 CrossThreadWeakPersistent& operator=(std::nullptr_t) | 468 CrossThreadWeakPersistent& operator=(std::nullptr_t) |
| 514 { | 469 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 528 Parent::operator=(other); | 483 Parent::operator=(other); |
| 529 return *this; | 484 return *this; |
| 530 } | 485 } |
| 531 | 486 |
| 532 template<typename U> | 487 template<typename U> |
| 533 CrossThreadWeakPersistent& operator=(const Member<U>& other) | 488 CrossThreadWeakPersistent& operator=(const Member<U>& other) |
| 534 { | 489 { |
| 535 Parent::operator=(other); | 490 Parent::operator=(other); |
| 536 return *this; | 491 return *this; |
| 537 } | 492 } |
| 538 | |
| 539 template<typename U> | |
| 540 CrossThreadWeakPersistent& operator=(const RawPtr<U>& other) | |
| 541 { | |
| 542 Parent::operator=(other); | |
| 543 return *this; | |
| 544 } | |
| 545 }; | 493 }; |
| 546 | 494 |
| 547 template<typename Collection> | 495 template<typename Collection> |
| 548 class PersistentHeapCollectionBase : public Collection { | 496 class PersistentHeapCollectionBase : public Collection { |
| 549 // We overload the various new and delete operators with using the WTF Parti
tionAllocator to ensure persistent | 497 // We overload the various new and delete operators with using the WTF Parti
tionAllocator to ensure persistent |
| 550 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in | 498 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in |
| 551 // DEFINE_STATIC_LOCAL et. al. | 499 // DEFINE_STATIC_LOCAL et. al. |
| 552 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); | 500 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); |
| 553 IS_PERSISTENT_REFERENCE_TYPE(); | 501 IS_PERSISTENT_REFERENCE_TYPE(); |
| 554 public: | 502 public: |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 Member(T* raw) : m_raw(raw) | 672 Member(T* raw) : m_raw(raw) |
| 725 { | 673 { |
| 726 checkPointer(); | 674 checkPointer(); |
| 727 } | 675 } |
| 728 | 676 |
| 729 explicit Member(T& raw) : m_raw(&raw) | 677 explicit Member(T& raw) : m_raw(&raw) |
| 730 { | 678 { |
| 731 checkPointer(); | 679 checkPointer(); |
| 732 } | 680 } |
| 733 | 681 |
| 734 template<typename U> | |
| 735 Member(const RawPtr<U>& other) : m_raw(other.get()) | |
| 736 { | |
| 737 checkPointer(); | |
| 738 } | |
| 739 | |
| 740 Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) | 682 Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) |
| 741 { | 683 { |
| 742 } | 684 } |
| 743 | 685 |
| 744 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>(
-1); } | 686 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>(
-1); } |
| 745 | 687 |
| 746 template<typename U> | 688 template<typename U> |
| 747 Member(const Persistent<U>& other) : m_raw(other) | 689 Member(const Persistent<U>& other) : m_raw(other) |
| 748 { | 690 { |
| 749 checkPointer(); | 691 checkPointer(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 766 m_raw = nullptr; | 708 m_raw = nullptr; |
| 767 return result; | 709 return result; |
| 768 } | 710 } |
| 769 | 711 |
| 770 bool operator!() const { return !m_raw; } | 712 bool operator!() const { return !m_raw; } |
| 771 | 713 |
| 772 operator T*() const { return m_raw; } | 714 operator T*() const { return m_raw; } |
| 773 | 715 |
| 774 T* operator->() const { return m_raw; } | 716 T* operator->() const { return m_raw; } |
| 775 T& operator*() const { return *m_raw; } | 717 T& operator*() const { return *m_raw; } |
| 776 template<typename U> | |
| 777 operator RawPtr<U>() const { return m_raw; } | |
| 778 | 718 |
| 779 template<typename U> | 719 template<typename U> |
| 780 Member& operator=(const Persistent<U>& other) | 720 Member& operator=(const Persistent<U>& other) |
| 781 { | 721 { |
| 782 m_raw = other; | 722 m_raw = other; |
| 783 checkPointer(); | 723 checkPointer(); |
| 784 return *this; | 724 return *this; |
| 785 } | 725 } |
| 786 | 726 |
| 787 template<typename U> | 727 template<typename U> |
| 788 Member& operator=(const Member<U>& other) | 728 Member& operator=(const Member<U>& other) |
| 789 { | 729 { |
| 790 m_raw = other; | 730 m_raw = other; |
| 791 checkPointer(); | 731 checkPointer(); |
| 792 return *this; | 732 return *this; |
| 793 } | 733 } |
| 794 | 734 |
| 795 template<typename U> | 735 template<typename U> |
| 796 Member& operator=(U* other) | 736 Member& operator=(U* other) |
| 797 { | 737 { |
| 798 m_raw = other; | 738 m_raw = other; |
| 799 checkPointer(); | 739 checkPointer(); |
| 800 return *this; | 740 return *this; |
| 801 } | 741 } |
| 802 | 742 |
| 803 template<typename U> | |
| 804 Member& operator=(RawPtr<U> other) | |
| 805 { | |
| 806 m_raw = other; | |
| 807 checkPointer(); | |
| 808 return *this; | |
| 809 } | |
| 810 | |
| 811 Member& operator=(std::nullptr_t) | 743 Member& operator=(std::nullptr_t) |
| 812 { | 744 { |
| 813 m_raw = nullptr; | 745 m_raw = nullptr; |
| 814 return *this; | 746 return *this; |
| 815 } | 747 } |
| 816 | 748 |
| 817 void swap(Member<T>& other) | 749 void swap(Member<T>& other) |
| 818 { | 750 { |
| 819 std::swap(m_raw, other.m_raw); | 751 std::swap(m_raw, other.m_raw); |
| 820 checkPointer(); | 752 checkPointer(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 } | 832 } |
| 901 | 833 |
| 902 template<typename U> | 834 template<typename U> |
| 903 WeakMember& operator=(U* other) | 835 WeakMember& operator=(U* other) |
| 904 { | 836 { |
| 905 this->m_raw = other; | 837 this->m_raw = other; |
| 906 this->checkPointer(); | 838 this->checkPointer(); |
| 907 return *this; | 839 return *this; |
| 908 } | 840 } |
| 909 | 841 |
| 910 template<typename U> | |
| 911 WeakMember& operator=(const RawPtr<U>& other) | |
| 912 { | |
| 913 this->m_raw = other; | |
| 914 this->checkPointer(); | |
| 915 return *this; | |
| 916 } | |
| 917 | |
| 918 WeakMember& operator=(std::nullptr_t) | 842 WeakMember& operator=(std::nullptr_t) |
| 919 { | 843 { |
| 920 this->m_raw = nullptr; | 844 this->m_raw = nullptr; |
| 921 return *this; | 845 return *this; |
| 922 } | 846 } |
| 923 | 847 |
| 924 private: | 848 private: |
| 925 T** cell() const { return const_cast<T**>(&this->m_raw); } | 849 T** cell() const { return const_cast<T**>(&this->m_raw); } |
| 926 | 850 |
| 927 template<typename Derived> friend class VisitorHelper; | 851 template<typename Derived> friend class VisitorHelper; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 938 template<typename T> | 862 template<typename T> |
| 939 class UntracedMember final : public Member<T> { | 863 class UntracedMember final : public Member<T> { |
| 940 public: | 864 public: |
| 941 UntracedMember() : Member<T>() { } | 865 UntracedMember() : Member<T>() { } |
| 942 | 866 |
| 943 UntracedMember(std::nullptr_t) : Member<T>(nullptr) { } | 867 UntracedMember(std::nullptr_t) : Member<T>(nullptr) { } |
| 944 | 868 |
| 945 UntracedMember(T* raw) : Member<T>(raw) { } | 869 UntracedMember(T* raw) : Member<T>(raw) { } |
| 946 | 870 |
| 947 template<typename U> | 871 template<typename U> |
| 948 UntracedMember(const RawPtr<U>& other) : Member<T>(other) { } | |
| 949 | |
| 950 template<typename U> | |
| 951 UntracedMember(const Persistent<U>& other) : Member<T>(other) { } | 872 UntracedMember(const Persistent<U>& other) : Member<T>(other) { } |
| 952 | 873 |
| 953 template<typename U> | 874 template<typename U> |
| 954 UntracedMember(const Member<U>& other) : Member<T>(other) { } | 875 UntracedMember(const Member<U>& other) : Member<T>(other) { } |
| 955 | 876 |
| 956 UntracedMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } | 877 UntracedMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } |
| 957 | 878 |
| 958 template<typename U> | 879 template<typename U> |
| 959 UntracedMember& operator=(const Persistent<U>& other) | 880 UntracedMember& operator=(const Persistent<U>& other) |
| 960 { | 881 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 972 } | 893 } |
| 973 | 894 |
| 974 template<typename U> | 895 template<typename U> |
| 975 UntracedMember& operator=(U* other) | 896 UntracedMember& operator=(U* other) |
| 976 { | 897 { |
| 977 this->m_raw = other; | 898 this->m_raw = other; |
| 978 this->checkPointer(); | 899 this->checkPointer(); |
| 979 return *this; | 900 return *this; |
| 980 } | 901 } |
| 981 | 902 |
| 982 template<typename U> | |
| 983 UntracedMember& operator=(const RawPtr<U>& other) | |
| 984 { | |
| 985 this->m_raw = other; | |
| 986 this->checkPointer(); | |
| 987 return *this; | |
| 988 } | |
| 989 | |
| 990 UntracedMember& operator=(std::nullptr_t) | 903 UntracedMember& operator=(std::nullptr_t) |
| 991 { | 904 { |
| 992 this->m_raw = nullptr; | 905 this->m_raw = nullptr; |
| 993 return *this; | 906 return *this; |
| 994 } | 907 } |
| 995 }; | 908 }; |
| 996 | 909 |
| 997 // Comparison operators between (Weak)Members, Persistents, and UntracedMembers. | 910 // Comparison operators between (Weak)Members, Persistents, and UntracedMembers. |
| 998 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Member<U>& b) { return a.get() == b.get(); } | 911 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Member<U>& b) { return a.get() == b.get(); } |
| 999 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Member<U>& b) { return a.get() != b.get(); } | 912 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Member<U>& b) { return a.get() != b.get(); } |
| 1000 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() == b.get(); } | 913 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() == b.get(); } |
| 1001 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() != b.get(); } | 914 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() != b.get(); } |
| 1002 | 915 |
| 1003 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() == b.get(); } | 916 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() == b.get(); } |
| 1004 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() != b.get(); } | 917 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() != b.get(); } |
| 1005 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Member<U>& b) { return a.get() == b.get(); } | 918 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Member<U>& b) { return a.get() == b.get(); } |
| 1006 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Member<U>& b) { return a.get() != b.get(); } | 919 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Member<U>& b) { return a.get() != b.get(); } |
| 1007 | 920 |
| 1008 template<typename T, bool = IsGarbageCollectedType<T>::value> | 921 template<typename T, bool = IsGarbageCollectedType<T>::value> |
| 1009 class RawPtrOrMemberTrait { | 922 class RawPtrOrMemberTrait { |
| 1010 STATIC_ONLY(RawPtrOrMemberTrait) | 923 STATIC_ONLY(RawPtrOrMemberTrait) |
| 1011 public: | 924 public: |
| 1012 using Type = RawPtr<T>; | 925 using Type = T*; |
| 1013 }; | 926 }; |
| 1014 | 927 |
| 1015 template<typename T> | 928 template<typename T> |
| 1016 class RawPtrOrMemberTrait<T, true> { | 929 class RawPtrOrMemberTrait<T, true> { |
| 1017 STATIC_ONLY(RawPtrOrMemberTrait) | 930 STATIC_ONLY(RawPtrOrMemberTrait) |
| 1018 public: | 931 public: |
| 1019 using Type = Member<T>; | 932 using Type = Member<T>; |
| 1020 }; | 933 }; |
| 1021 | 934 |
| 1022 // Abstraction for injecting calls to an object's 'dispose()' method | 935 // Abstraction for injecting calls to an object's 'dispose()' method |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 static T* unwrap(const StorageType& value) { return value.get(); } | 1166 static T* unwrap(const StorageType& value) { return value.get(); } |
| 1254 }; | 1167 }; |
| 1255 | 1168 |
| 1256 template<typename T> | 1169 template<typename T> |
| 1257 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa
rbageCollectedType<T>::value> { | 1170 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa
rbageCollectedType<T>::value> { |
| 1258 STATIC_ONLY(ParamStorageTraits); | 1171 STATIC_ONLY(ParamStorageTraits); |
| 1259 static_assert(sizeof(T), "T must be fully defined"); | 1172 static_assert(sizeof(T), "T must be fully defined"); |
| 1260 }; | 1173 }; |
| 1261 | 1174 |
| 1262 template<typename T> | 1175 template<typename T> |
| 1263 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin
k::IsGarbageCollectedType<T>::value> { | |
| 1264 STATIC_ONLY(ParamStorageTraits); | |
| 1265 static_assert(sizeof(T), "T must be fully defined"); | |
| 1266 }; | |
| 1267 | |
| 1268 template<typename T> | |
| 1269 struct ParamStorageTraits<blink::WeakPersistentThisPointer<T>> { | 1176 struct ParamStorageTraits<blink::WeakPersistentThisPointer<T>> { |
| 1270 STATIC_ONLY(ParamStorageTraits); | 1177 STATIC_ONLY(ParamStorageTraits); |
| 1271 static_assert(sizeof(T), "T must be fully defined"); | 1178 static_assert(sizeof(T), "T must be fully defined"); |
| 1272 using StorageType = blink::WeakPersistent<T>; | 1179 using StorageType = blink::WeakPersistent<T>; |
| 1273 | 1180 |
| 1274 static StorageType wrap(const blink::WeakPersistentThisPointer<T>& value) {
return value.value(); } | 1181 static StorageType wrap(const blink::WeakPersistentThisPointer<T>& value) {
return value.value(); } |
| 1275 | 1182 |
| 1276 // WTF::FunctionWrapper<> handles WeakPtr<>, so recast this weak persistent | 1183 // WTF::FunctionWrapper<> handles WeakPtr<>, so recast this weak persistent |
| 1277 // into it. | 1184 // into it. |
| 1278 // | 1185 // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1293 // into it. | 1200 // into it. |
| 1294 // | 1201 // |
| 1295 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty
pe like | 1202 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty
pe like |
| 1296 // CrossThreadWeakPersistent<>. | 1203 // CrossThreadWeakPersistent<>. |
| 1297 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR
eference<T>::create(value.get())); } | 1204 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR
eference<T>::create(value.get())); } |
| 1298 }; | 1205 }; |
| 1299 | 1206 |
| 1300 } // namespace WTF | 1207 } // namespace WTF |
| 1301 | 1208 |
| 1302 #endif | 1209 #endif |
| OLD | NEW |