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 30 matching lines...) Expand all Loading... | |
41 #include "wtf/Functional.h" | 41 #include "wtf/Functional.h" |
42 #include "wtf/HashFunctions.h" | 42 #include "wtf/HashFunctions.h" |
43 #include "wtf/Locker.h" | 43 #include "wtf/Locker.h" |
44 #include "wtf/MainThread.h" | 44 #include "wtf/MainThread.h" |
45 #include "wtf/RawPtr.h" | 45 #include "wtf/RawPtr.h" |
46 #include "wtf/RefCounted.h" | 46 #include "wtf/RefCounted.h" |
47 #include "wtf/TypeTraits.h" | 47 #include "wtf/TypeTraits.h" |
48 | 48 |
49 namespace blink { | 49 namespace blink { |
50 | 50 |
51 template<typename T> class Member; | |
52 template<typename T> class UntracedMember; | |
53 | |
51 enum WeaknessPersistentConfiguration { | 54 enum WeaknessPersistentConfiguration { |
52 NonWeakPersistentConfiguration, | 55 NonWeakPersistentConfiguration, |
53 WeakPersistentConfiguration | 56 WeakPersistentConfiguration |
54 }; | 57 }; |
55 | 58 |
56 enum CrossThreadnessPersistentConfiguration { | 59 enum CrossThreadnessPersistentConfiguration { |
57 SingleThreadPersistentConfiguration, | 60 SingleThreadPersistentConfiguration, |
58 CrossThreadPersistentConfiguration | 61 CrossThreadPersistentConfiguration |
59 }; | 62 }; |
60 | 63 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 | 97 |
95 template<typename U> | 98 template<typename U> |
96 PersistentBase(const PersistentBase<U, weaknessConfiguration, crossThreadnes sConfiguration>& other) : m_raw(other) | 99 PersistentBase(const PersistentBase<U, weaknessConfiguration, crossThreadnes sConfiguration>& other) : m_raw(other) |
97 { | 100 { |
98 initialize(); | 101 initialize(); |
99 checkPointer(); | 102 checkPointer(); |
100 recordBacktrace(); | 103 recordBacktrace(); |
101 } | 104 } |
102 | 105 |
103 template<typename U> | 106 template<typename U> |
107 PersistentBase(const UntracedMember<U>& other) : m_raw(other) | |
108 { | |
109 initialize(); | |
110 checkPointer(); | |
111 recordBacktrace(); | |
112 } | |
113 | |
114 template<typename U> | |
104 PersistentBase(const Member<U>& other) : m_raw(other) | 115 PersistentBase(const Member<U>& other) : m_raw(other) |
105 { | 116 { |
106 initialize(); | 117 initialize(); |
107 checkPointer(); | 118 checkPointer(); |
108 recordBacktrace(); | 119 recordBacktrace(); |
109 } | 120 } |
110 | 121 |
111 template<typename U> | 122 template<typename U> |
112 PersistentBase(const RawPtr<U>& other) : m_raw(other.get()) | 123 PersistentBase(const RawPtr<U>& other) : m_raw(other.get()) |
113 { | 124 { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 } | 180 } |
170 | 181 |
171 template<typename U> | 182 template<typename U> |
172 PersistentBase& operator=(const PersistentBase<U, weaknessConfiguration, cro ssThreadnessConfiguration>& other) | 183 PersistentBase& operator=(const PersistentBase<U, weaknessConfiguration, cro ssThreadnessConfiguration>& other) |
173 { | 184 { |
174 assign(other); | 185 assign(other); |
175 return *this; | 186 return *this; |
176 } | 187 } |
177 | 188 |
178 template<typename U> | 189 template<typename U> |
190 PersistentBase& operator=(const UntracedMember<U>& other) | |
191 { | |
192 assign(other); | |
193 return *this; | |
194 } | |
195 | |
196 template<typename U> | |
179 PersistentBase& operator=(const Member<U>& other) | 197 PersistentBase& operator=(const Member<U>& other) |
180 { | 198 { |
181 assign(other); | 199 assign(other); |
182 return *this; | 200 return *this; |
183 } | 201 } |
184 | 202 |
185 template<typename U> | 203 template<typename U> |
186 PersistentBase& operator=(const RawPtr<U>& other) | 204 PersistentBase& operator=(const RawPtr<U>& other) |
187 { | 205 { |
188 assign(other); | 206 assign(other); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 typedef PersistentBase<T, NonWeakPersistentConfiguration, SingleThreadPersis tentConfiguration> Parent; | 309 typedef PersistentBase<T, NonWeakPersistentConfiguration, SingleThreadPersis tentConfiguration> Parent; |
292 public: | 310 public: |
293 Persistent() : Parent() { } | 311 Persistent() : Parent() { } |
294 Persistent(std::nullptr_t) : Parent(nullptr) { } | 312 Persistent(std::nullptr_t) : Parent(nullptr) { } |
295 Persistent(T* raw) : Parent(raw) { } | 313 Persistent(T* raw) : Parent(raw) { } |
296 Persistent(T& raw) : Parent(raw) { } | 314 Persistent(T& raw) : Parent(raw) { } |
297 Persistent(const Persistent& other) : Parent(other) { } | 315 Persistent(const Persistent& other) : Parent(other) { } |
298 template<typename U> | 316 template<typename U> |
299 Persistent(const Persistent<U>& other) : Parent(other) { } | 317 Persistent(const Persistent<U>& other) : Parent(other) { } |
300 template<typename U> | 318 template<typename U> |
319 Persistent(const UntracedMember<U>& other) : Parent(other) { } | |
320 template<typename U> | |
301 Persistent(const Member<U>& other) : Parent(other) { } | 321 Persistent(const Member<U>& other) : Parent(other) { } |
302 template<typename U> | 322 template<typename U> |
303 Persistent(const RawPtr<U>& other) : Parent(other.get()) { } | 323 Persistent(const RawPtr<U>& other) : Parent(other.get()) { } |
304 | 324 |
305 template<typename U> | 325 template<typename U> |
306 Persistent& operator=(U* other) | 326 Persistent& operator=(U* other) |
307 { | 327 { |
308 Parent::operator=(other); | 328 Parent::operator=(other); |
309 return *this; | 329 return *this; |
310 } | 330 } |
(...skipping 11 matching lines...) Expand all Loading... | |
322 } | 342 } |
323 | 343 |
324 template<typename U> | 344 template<typename U> |
325 Persistent& operator=(const Persistent<U>& other) | 345 Persistent& operator=(const Persistent<U>& other) |
326 { | 346 { |
327 Parent::operator=(other); | 347 Parent::operator=(other); |
328 return *this; | 348 return *this; |
329 } | 349 } |
330 | 350 |
331 template<typename U> | 351 template<typename U> |
352 Persistent& operator=(const UntracedMember<U>& other) | |
353 { | |
354 Parent::operator=(other); | |
355 return *this; | |
356 } | |
357 | |
358 template<typename U> | |
332 Persistent& operator=(const Member<U>& other) | 359 Persistent& operator=(const Member<U>& other) |
333 { | 360 { |
334 Parent::operator=(other); | 361 Parent::operator=(other); |
335 return *this; | 362 return *this; |
336 } | 363 } |
337 | 364 |
338 template<typename U> | 365 template<typename U> |
339 Persistent& operator=(const RawPtr<U>& other) | 366 Persistent& operator=(const RawPtr<U>& other) |
340 { | 367 { |
341 Parent::operator=(other); | 368 Parent::operator=(other); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist entConfiguration> Parent; | 445 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist entConfiguration> Parent; |
419 public: | 446 public: |
420 CrossThreadPersistent() : Parent() { } | 447 CrossThreadPersistent() : Parent() { } |
421 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { } | 448 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { } |
422 CrossThreadPersistent(T* raw) : Parent(raw) { } | 449 CrossThreadPersistent(T* raw) : Parent(raw) { } |
423 CrossThreadPersistent(T& raw) : Parent(raw) { } | 450 CrossThreadPersistent(T& raw) : Parent(raw) { } |
424 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) { } | 451 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) { } |
425 template<typename U> | 452 template<typename U> |
426 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other) { } | 453 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other) { } |
427 template<typename U> | 454 template<typename U> |
455 CrossThreadPersistent(const UntracedMember<U>& other) : Parent(other) { } | |
456 template<typename U> | |
428 CrossThreadPersistent(const Member<U>& other) : Parent(other) { } | 457 CrossThreadPersistent(const Member<U>& other) : Parent(other) { } |
429 template<typename U> | 458 template<typename U> |
430 CrossThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { } | 459 CrossThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { } |
431 | 460 |
432 template<typename U> | 461 template<typename U> |
433 CrossThreadPersistent& operator=(U* other) | 462 CrossThreadPersistent& operator=(U* other) |
434 { | 463 { |
435 Parent::operator=(other); | 464 Parent::operator=(other); |
436 return *this; | 465 return *this; |
437 } | 466 } |
(...skipping 11 matching lines...) Expand all Loading... | |
449 } | 478 } |
450 | 479 |
451 template<typename U> | 480 template<typename U> |
452 CrossThreadPersistent& operator=(const CrossThreadPersistent<U>& other) | 481 CrossThreadPersistent& operator=(const CrossThreadPersistent<U>& other) |
453 { | 482 { |
454 Parent::operator=(other); | 483 Parent::operator=(other); |
455 return *this; | 484 return *this; |
456 } | 485 } |
457 | 486 |
458 template<typename U> | 487 template<typename U> |
488 CrossThreadPersistent& operator=(const UntracedMember<U>& other) | |
489 { | |
490 Parent::operator=(other); | |
491 return *this; | |
492 } | |
493 | |
494 template<typename U> | |
459 CrossThreadPersistent& operator=(const Member<U>& other) | 495 CrossThreadPersistent& operator=(const Member<U>& other) |
460 { | 496 { |
461 Parent::operator=(other); | 497 Parent::operator=(other); |
462 return *this; | 498 return *this; |
463 } | 499 } |
464 | 500 |
465 template<typename U> | 501 template<typename U> |
466 CrossThreadPersistent& operator=(const RawPtr<U>& other) | 502 CrossThreadPersistent& operator=(const RawPtr<U>& other) |
467 { | 503 { |
468 Parent::operator=(other); | 504 Parent::operator=(other); |
469 return *this; | 505 return *this; |
470 } | 506 } |
471 }; | 507 }; |
472 | 508 |
473 // Combines the behavior of CrossThreadPersistent and WeakPersistent. | 509 // Combines the behavior of CrossThreadPersistent and WeakPersistent. |
474 template<typename T> | 510 template<typename T> |
475 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu ration, CrossThreadPersistentConfiguration> { | 511 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu ration, CrossThreadPersistentConfiguration> { |
476 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent Configuration> Parent; | 512 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent Configuration> Parent; |
477 public: | 513 public: |
478 CrossThreadWeakPersistent() : Parent() { } | 514 CrossThreadWeakPersistent() : Parent() { } |
479 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } | 515 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } |
480 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } | 516 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } |
481 CrossThreadWeakPersistent(T& raw) : Parent(raw) { } | 517 CrossThreadWeakPersistent(T& raw) : Parent(raw) { } |
482 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o ther) { } | 518 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o ther) { } |
483 template<typename U> | 519 template<typename U> |
484 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren t(other) { } | 520 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren t(other) { } |
485 template<typename U> | 521 template<typename U> |
522 CrossThreadWeakPersistent(const UntracedMember<U>& other) : Parent(other) { } | |
523 template<typename U> | |
486 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { } | 524 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { } |
487 template<typename U> | 525 template<typename U> |
488 CrossThreadWeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } | 526 CrossThreadWeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } |
489 | 527 |
490 template<typename U> | 528 template<typename U> |
491 CrossThreadWeakPersistent& operator=(U* other) | 529 CrossThreadWeakPersistent& operator=(U* other) |
492 { | 530 { |
493 Parent::operator=(other); | 531 Parent::operator=(other); |
494 return *this; | 532 return *this; |
495 } | 533 } |
(...skipping 11 matching lines...) Expand all Loading... | |
507 } | 545 } |
508 | 546 |
509 template<typename U> | 547 template<typename U> |
510 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent<U>& oth er) | 548 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent<U>& oth er) |
511 { | 549 { |
512 Parent::operator=(other); | 550 Parent::operator=(other); |
513 return *this; | 551 return *this; |
514 } | 552 } |
515 | 553 |
516 template<typename U> | 554 template<typename U> |
555 CrossThreadWeakPersistent& operator=(const UntracedMember<U>& other) | |
556 { | |
557 Parent::operator=(other); | |
558 return *this; | |
559 } | |
560 | |
561 template<typename U> | |
517 CrossThreadWeakPersistent& operator=(const Member<U>& other) | 562 CrossThreadWeakPersistent& operator=(const Member<U>& other) |
518 { | 563 { |
519 Parent::operator=(other); | 564 Parent::operator=(other); |
520 return *this; | 565 return *this; |
521 } | 566 } |
522 | 567 |
523 template<typename U> | 568 template<typename U> |
524 CrossThreadWeakPersistent& operator=(const RawPtr<U>& other) | 569 CrossThreadWeakPersistent& operator=(const RawPtr<U>& other) |
525 { | 570 { |
526 Parent::operator=(other); | 571 Parent::operator=(other); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 } | 729 } |
685 | 730 |
686 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>( -1); } | 731 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>( -1); } |
687 | 732 |
688 template<typename U> | 733 template<typename U> |
689 Member(const Persistent<U>& other) : m_raw(other) | 734 Member(const Persistent<U>& other) : m_raw(other) |
690 { | 735 { |
691 checkPointer(); | 736 checkPointer(); |
692 } | 737 } |
693 | 738 |
739 template<typename U> | |
740 Member(const UntracedMember<U>& other) : m_raw(other) | |
741 { | |
742 checkPointer(); | |
743 } | |
744 | |
694 Member(const Member& other) : m_raw(other) | 745 Member(const Member& other) : m_raw(other) |
695 { | 746 { |
696 checkPointer(); | 747 checkPointer(); |
697 } | 748 } |
698 | 749 |
699 template<typename U> | 750 template<typename U> |
700 Member(const Member<U>& other) : m_raw(other) | 751 Member(const Member<U>& other) : m_raw(other) |
701 { | 752 { |
702 checkPointer(); | 753 checkPointer(); |
703 } | 754 } |
(...skipping 24 matching lines...) Expand all Loading... | |
728 | 779 |
729 template<typename U> | 780 template<typename U> |
730 Member& operator=(const Member<U>& other) | 781 Member& operator=(const Member<U>& other) |
731 { | 782 { |
732 m_raw = other; | 783 m_raw = other; |
733 checkPointer(); | 784 checkPointer(); |
734 return *this; | 785 return *this; |
735 } | 786 } |
736 | 787 |
737 template<typename U> | 788 template<typename U> |
789 Member& operator=(const UntracedMember<U>& other) | |
790 { | |
791 m_raw = other; | |
792 checkPointer(); | |
793 return *this; | |
794 } | |
795 | |
796 template<typename U> | |
738 Member& operator=(U* other) | 797 Member& operator=(U* other) |
739 { | 798 { |
740 m_raw = other; | 799 m_raw = other; |
741 checkPointer(); | 800 checkPointer(); |
742 return *this; | 801 return *this; |
743 } | 802 } |
744 | 803 |
745 template<typename U> | 804 template<typename U> |
746 Member& operator=(RawPtr<U> other) | 805 Member& operator=(RawPtr<U> other) |
747 { | 806 { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 WeakMember(std::nullptr_t) : Member<T>(nullptr) { } | 875 WeakMember(std::nullptr_t) : Member<T>(nullptr) { } |
817 | 876 |
818 WeakMember(T* raw) : Member<T>(raw) { } | 877 WeakMember(T* raw) : Member<T>(raw) { } |
819 | 878 |
820 WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } | 879 WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } |
821 | 880 |
822 template<typename U> | 881 template<typename U> |
823 WeakMember(const Persistent<U>& other) : Member<T>(other) { } | 882 WeakMember(const Persistent<U>& other) : Member<T>(other) { } |
824 | 883 |
825 template<typename U> | 884 template<typename U> |
885 WeakMember(const UntracedMember<U>& other) : Member<T>(other) { } | |
886 | |
887 template<typename U> | |
826 WeakMember(const Member<U>& other) : Member<T>(other) { } | 888 WeakMember(const Member<U>& other) : Member<T>(other) { } |
827 | 889 |
828 template<typename U> | 890 template<typename U> |
829 WeakMember& operator=(const Persistent<U>& other) | 891 WeakMember& operator=(const Persistent<U>& other) |
830 { | 892 { |
831 this->m_raw = other; | 893 this->m_raw = other; |
832 this->checkPointer(); | 894 this->checkPointer(); |
833 return *this; | 895 return *this; |
834 } | 896 } |
835 | 897 |
836 template<typename U> | 898 template<typename U> |
837 WeakMember& operator=(const Member<U>& other) | 899 WeakMember& operator=(const Member<U>& other) |
838 { | 900 { |
839 this->m_raw = other; | 901 this->m_raw = other; |
840 this->checkPointer(); | 902 this->checkPointer(); |
841 return *this; | 903 return *this; |
842 } | 904 } |
843 | 905 |
844 template<typename U> | 906 template<typename U> |
907 WeakMember& operator=(const UntracedMember<U>& other) | |
908 { | |
909 this->m_raw = other; | |
910 this->checkPointer(); | |
911 return *this; | |
912 } | |
913 | |
914 template<typename U> | |
845 WeakMember& operator=(U* other) | 915 WeakMember& operator=(U* other) |
846 { | 916 { |
847 this->m_raw = other; | 917 this->m_raw = other; |
848 this->checkPointer(); | 918 this->checkPointer(); |
849 return *this; | 919 return *this; |
850 } | 920 } |
851 | 921 |
852 template<typename U> | 922 template<typename U> |
853 WeakMember& operator=(const RawPtr<U>& other) | 923 WeakMember& operator=(const RawPtr<U>& other) |
854 { | 924 { |
855 this->m_raw = other; | 925 this->m_raw = other; |
856 this->checkPointer(); | 926 this->checkPointer(); |
857 return *this; | 927 return *this; |
858 } | 928 } |
859 | 929 |
860 WeakMember& operator=(std::nullptr_t) | 930 WeakMember& operator=(std::nullptr_t) |
861 { | 931 { |
862 this->m_raw = nullptr; | 932 this->m_raw = nullptr; |
863 return *this; | 933 return *this; |
864 } | 934 } |
865 | 935 |
866 private: | 936 private: |
867 T** cell() const { return const_cast<T**>(&this->m_raw); } | 937 T** cell() const { return const_cast<T**>(&this->m_raw); } |
868 | 938 |
869 template<typename Derived> friend class VisitorHelper; | 939 template<typename Derived> friend class VisitorHelper; |
870 }; | 940 }; |
871 | 941 |
872 // Comparison operators between (Weak)Members and Persistents | 942 // UntracedMember is actually a raw pointer. |
943 // It is allowed to store a pointer to an object on oilpan heap, | |
944 // and it is also allowed to store UntracedMember in off heap Vector. | |
945 // UntracedMember does not keep the pointee object alive, so if you use | |
946 // UntracedMember, you must guarantee that the pointee object is alive in | |
947 // some reason. | |
948 // TODO(peria): Enable to store UntracedMember in hash collections. (i.e. HashSe t) | |
949 template<typename T> | |
950 class UntracedMember { | |
haraken
2015/10/14 09:39:53
I'm just curious but would it be possible to make
peria
2015/10/15 02:13:15
Done.
| |
951 public: | |
952 UntracedMember() : m_raw(nullptr) | |
953 { | |
954 } | |
955 | |
956 UntracedMember(std::nullptr_t) : m_raw(nullptr) | |
957 { | |
958 } | |
959 | |
960 UntracedMember(const UntracedMember& other) : m_raw(other) | |
961 { | |
962 checkPointer(); | |
963 } | |
964 | |
965 template<typename U> | |
966 UntracedMember(const UntracedMember<U>& other) : m_raw(other) | |
967 { | |
968 checkPointer(); | |
969 } | |
970 | |
971 UntracedMember(T* raw) : m_raw(raw) | |
972 { | |
973 checkPointer(); | |
974 } | |
975 | |
976 template<typename U> | |
977 UntracedMember(const RawPtr<U>& other) : m_raw(other.get()) | |
978 { | |
979 checkPointer(); | |
980 } | |
981 | |
982 template<typename U> | |
983 UntracedMember(const Persistent<U>& other) : m_raw(other) | |
984 { | |
985 checkPointer(); | |
986 } | |
987 | |
988 template<typename U> | |
989 UntracedMember(const Member<U>& other) : m_raw(other) | |
990 { | |
991 checkPointer(); | |
992 } | |
993 | |
994 UntracedMember(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>( -1)) | |
995 { | |
996 } | |
997 | |
998 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>( -1); } | |
999 | |
1000 T* release() | |
1001 { | |
1002 T* result = m_raw; | |
1003 m_raw = nullptr; | |
1004 return result; | |
1005 } | |
1006 | |
1007 bool operator!() const { return !m_raw; } | |
1008 | |
1009 operator T*() const { return m_raw; } | |
1010 | |
1011 T* operator->() const { return m_raw; } | |
1012 T& operator*() const { return *m_raw; } | |
1013 template<typename U> | |
1014 operator RawPtr<U>() const { return m_raw; } | |
1015 | |
1016 template<typename U> | |
1017 UntracedMember& operator=(const UntracedMember<U>& other) | |
1018 { | |
1019 m_raw = other; | |
1020 checkPointer(); | |
1021 return *this; | |
1022 } | |
1023 | |
1024 template<typename U> | |
1025 UntracedMember& operator=(const Persistent<U>& other) | |
1026 { | |
1027 m_raw = other; | |
1028 checkPointer(); | |
1029 return *this; | |
1030 } | |
1031 | |
1032 template<typename U> | |
1033 UntracedMember& operator=(const Member<U>& other) | |
1034 { | |
1035 m_raw = other; | |
1036 checkPointer(); | |
1037 return *this; | |
1038 } | |
1039 | |
1040 template<typename U> | |
1041 UntracedMember& operator=(RawPtr<U> other) | |
1042 { | |
1043 m_raw = other; | |
1044 checkPointer(); | |
1045 return *this; | |
1046 } | |
1047 | |
1048 template<typename U> | |
1049 UntracedMember& operator=(U* other) | |
1050 { | |
1051 m_raw = other; | |
1052 checkPointer(); | |
1053 return *this; | |
1054 } | |
1055 | |
1056 UntracedMember& operator=(std::nullptr_t) | |
1057 { | |
1058 m_raw = nullptr; | |
1059 return *this; | |
1060 } | |
1061 | |
1062 void swap(UntracedMember<T>& other) | |
1063 { | |
1064 std::swap(m_raw, other.m_raw); | |
1065 checkPointer(); | |
1066 } | |
1067 | |
1068 T* get() const { return m_raw; } | |
1069 | |
1070 void clear() { m_raw = nullptr; } | |
1071 | |
1072 | |
1073 protected: | |
1074 void checkPointer() | |
1075 { | |
1076 #if ENABLE(ASSERT) | |
1077 if (!m_raw) | |
1078 return; | |
1079 | |
1080 // TODO(haraken): What we really want to check here is that the pointer | |
1081 // is a traceable object. In other words, the pointer is either of: | |
1082 // | |
1083 // (a) a pointer to the head of an on-heap object. | |
1084 // (b) a pointer to the head of an on-heap mixin object. | |
1085 // | |
1086 // We can check it by calling Heap::isHeapObjectAlive(m_raw), | |
1087 // but we cannot call it here because it requires to include T.h. | |
1088 // So we currently only try to implement the check for (a), but do | |
1089 // not insist that T's definition is in scope. | |
1090 if (IsFullyDefined<T>::value && !IsGarbageCollectedMixin<T>::value) | |
1091 ASSERT(HeapObjectHeader::fromPayload(m_raw)->checkHeader()); | |
1092 #endif | |
1093 } | |
1094 | |
1095 T* m_raw; | |
1096 }; | |
1097 | |
1098 // Comparison operators between (Weak)Members, Persistents, and UntracedMembers. | |
873 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } | 1099 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } |
874 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } | 1100 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } |
1101 template<typename T, typename U> inline bool operator==(const UntracedMember<T>& a, const UntracedMember<U>& b) { return a.get() == b.get(); } | |
1102 template<typename T, typename U> inline bool operator!=(const UntracedMember<T>& a, const UntracedMember<U>& b) { return a.get() != b.get(); } | |
1103 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } | |
1104 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } | |
1105 | |
875 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } | 1106 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } |
876 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); } | 1107 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); } |
877 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } | 1108 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } |
878 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); } | 1109 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); } |
879 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } | 1110 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t UntracedMember<U>& b) { return a.get() == b.get(); } |
880 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } | 1111 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t UntracedMember<U>& b) { return a.get() != b.get(); } |
1112 template<typename T, typename U> inline bool operator==(const UntracedMember<T>& a, const Member<U>& b) { return a.get() == b.get(); } | |
1113 template<typename T, typename U> inline bool operator!=(const UntracedMember<T>& a, const Member<U>& b) { return a.get() != b.get(); } | |
1114 template<typename T, typename U> inline bool operator==(const UntracedMember<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } | |
1115 template<typename T, typename U> inline bool operator!=(const UntracedMember<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } | |
1116 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const UntracedMember<U>& b) { return a.get() == b.get(); } | |
1117 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const UntracedMember<U>& b) { return a.get() != b.get(); } | |
881 | 1118 |
882 template<typename T> | 1119 template<typename T> |
883 class DummyBase { | 1120 class DummyBase { |
884 public: | 1121 public: |
885 DummyBase() { } | 1122 DummyBase() { } |
886 ~DummyBase() { } | 1123 ~DummyBase() { } |
887 }; | 1124 }; |
888 | 1125 |
889 // CPP-defined type names for the transition period where we want to | 1126 // CPP-defined type names for the transition period where we want to |
890 // support both reference counting and garbage collection based on a | 1127 // support both reference counting and garbage collection based on a |
(...skipping 27 matching lines...) Expand all Loading... | |
918 #define RefPtrWillBePersistent blink::Persistent | 1155 #define RefPtrWillBePersistent blink::Persistent |
919 #define RefPtrWillBeRawPtr WTF::RawPtr | 1156 #define RefPtrWillBeRawPtr WTF::RawPtr |
920 #define RefPtrWillBeMember blink::Member | 1157 #define RefPtrWillBeMember blink::Member |
921 #define RefPtrWillBeWeakMember blink::WeakMember | 1158 #define RefPtrWillBeWeakMember blink::WeakMember |
922 #define RefPtrWillBeWeakPersistent blink::WeakPersistent | 1159 #define RefPtrWillBeWeakPersistent blink::WeakPersistent |
923 #define RefPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent | 1160 #define RefPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent |
924 #define RawPtrWillBeMember blink::Member | 1161 #define RawPtrWillBeMember blink::Member |
925 #define RawPtrWillBePersistent blink::Persistent | 1162 #define RawPtrWillBePersistent blink::Persistent |
926 #define RawPtrWillBeWeakMember blink::WeakMember | 1163 #define RawPtrWillBeWeakMember blink::WeakMember |
927 #define RawPtrWillBeWeakPersistent blink::WeakPersistent | 1164 #define RawPtrWillBeWeakPersistent blink::WeakPersistent |
1165 #define RawPtrWillBeUntracedMember blink::UntracedMember | |
928 #define OwnPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent | 1166 #define OwnPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent |
929 #define OwnPtrWillBeMember blink::Member | 1167 #define OwnPtrWillBeMember blink::Member |
930 #define OwnPtrWillBePersistent blink::Persistent | 1168 #define OwnPtrWillBePersistent blink::Persistent |
931 #define OwnPtrWillBeRawPtr WTF::RawPtr | 1169 #define OwnPtrWillBeRawPtr WTF::RawPtr |
932 #define PassOwnPtrWillBeRawPtr WTF::RawPtr | 1170 #define PassOwnPtrWillBeRawPtr WTF::RawPtr |
933 #define WeakPtrWillBeCrossThreadWeakPersistent blink::CrossThreadWeakPersistent | 1171 #define WeakPtrWillBeCrossThreadWeakPersistent blink::CrossThreadWeakPersistent |
934 #define WeakPtrWillBeMember blink::Member | 1172 #define WeakPtrWillBeMember blink::Member |
935 #define WeakPtrWillBeRawPtr WTF::RawPtr | 1173 #define WeakPtrWillBeRawPtr WTF::RawPtr |
936 #define WeakPtrWillBeWeakMember blink::WeakMember | 1174 #define WeakPtrWillBeWeakMember blink::WeakMember |
937 #define WeakPtrWillBeWeakPersistent blink::WeakPersistent | 1175 #define WeakPtrWillBeWeakPersistent blink::WeakPersistent |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1001 #define RefPtrWillBePersistent WTF::RefPtr | 1239 #define RefPtrWillBePersistent WTF::RefPtr |
1002 #define RefPtrWillBeRawPtr WTF::RefPtr | 1240 #define RefPtrWillBeRawPtr WTF::RefPtr |
1003 #define RefPtrWillBeMember WTF::RefPtr | 1241 #define RefPtrWillBeMember WTF::RefPtr |
1004 #define RefPtrWillBeWeakMember WTF::RefPtr | 1242 #define RefPtrWillBeWeakMember WTF::RefPtr |
1005 #define RefPtrWillBeWeakPersistent WTF::RefPtr | 1243 #define RefPtrWillBeWeakPersistent WTF::RefPtr |
1006 #define RefPtrWillBeCrossThreadPersistent WTF::RefPtr | 1244 #define RefPtrWillBeCrossThreadPersistent WTF::RefPtr |
1007 #define RawPtrWillBeMember WTF::RawPtr | 1245 #define RawPtrWillBeMember WTF::RawPtr |
1008 #define RawPtrWillBePersistent WTF::RawPtr | 1246 #define RawPtrWillBePersistent WTF::RawPtr |
1009 #define RawPtrWillBeWeakMember WTF::RawPtr | 1247 #define RawPtrWillBeWeakMember WTF::RawPtr |
1010 #define RawPtrWillBeWeakPersistent WTF::RawPtr | 1248 #define RawPtrWillBeWeakPersistent WTF::RawPtr |
1249 #define RawPtrWillBeUntracedMember WTF::RawPtr | |
1011 #define OwnPtrWillBeCrossThreadPersistent WTF::OwnPtr | 1250 #define OwnPtrWillBeCrossThreadPersistent WTF::OwnPtr |
1012 #define OwnPtrWillBeMember WTF::OwnPtr | 1251 #define OwnPtrWillBeMember WTF::OwnPtr |
1013 #define OwnPtrWillBePersistent WTF::OwnPtr | 1252 #define OwnPtrWillBePersistent WTF::OwnPtr |
1014 #define OwnPtrWillBeRawPtr WTF::OwnPtr | 1253 #define OwnPtrWillBeRawPtr WTF::OwnPtr |
1015 #define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr | 1254 #define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr |
1016 #define WeakPtrWillBeCrossThreadWeakPersistent WTF::WeakPtr | 1255 #define WeakPtrWillBeCrossThreadWeakPersistent WTF::WeakPtr |
1017 #define WeakPtrWillBeMember WTF::WeakPtr | 1256 #define WeakPtrWillBeMember WTF::WeakPtr |
1018 #define WeakPtrWillBeRawPtr WTF::WeakPtr | 1257 #define WeakPtrWillBeRawPtr WTF::WeakPtr |
1019 #define WeakPtrWillBeWeakMember WTF::WeakPtr | 1258 #define WeakPtrWillBeWeakMember WTF::WeakPtr |
1020 #define WeakPtrWillBeWeakPersistent WTF::WeakPtr | 1259 #define WeakPtrWillBeWeakPersistent WTF::WeakPtr |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 static const bool canMoveWithMemcpy = true; | 1430 static const bool canMoveWithMemcpy = true; |
1192 }; | 1431 }; |
1193 | 1432 |
1194 template <typename T> struct VectorTraits<blink::WeakMember<T>> : VectorTraitsBa se<blink::WeakMember<T>> { | 1433 template <typename T> struct VectorTraits<blink::WeakMember<T>> : VectorTraitsBa se<blink::WeakMember<T>> { |
1195 static const bool needsDestruction = false; | 1434 static const bool needsDestruction = false; |
1196 static const bool canInitializeWithMemset = true; | 1435 static const bool canInitializeWithMemset = true; |
1197 static const bool canClearUnusedSlotsWithMemset = true; | 1436 static const bool canClearUnusedSlotsWithMemset = true; |
1198 static const bool canMoveWithMemcpy = true; | 1437 static const bool canMoveWithMemcpy = true; |
1199 }; | 1438 }; |
1200 | 1439 |
1440 template <typename T> struct VectorTraits<blink::UntracedMember<T>> : VectorTrai tsBase<blink::UntracedMember<T>> { | |
1441 static const bool needsDestruction = false; | |
1442 static const bool canInitializeWithMemset = true; | |
1443 static const bool canClearUnusedSlotsWithMemset = true; | |
1444 static const bool canMoveWithMemcpy = true; | |
1445 }; | |
1446 | |
1201 template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTrait sBase<blink::HeapVector<T, 0>> { | 1447 template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTrait sBase<blink::HeapVector<T, 0>> { |
1202 static const bool needsDestruction = false; | 1448 static const bool needsDestruction = false; |
1203 static const bool canInitializeWithMemset = true; | 1449 static const bool canInitializeWithMemset = true; |
1204 static const bool canClearUnusedSlotsWithMemset = true; | 1450 static const bool canClearUnusedSlotsWithMemset = true; |
1205 static const bool canMoveWithMemcpy = true; | 1451 static const bool canMoveWithMemcpy = true; |
1206 }; | 1452 }; |
1207 | 1453 |
1208 template <typename T> struct VectorTraits<blink::HeapDeque<T, 0>> : VectorTraits Base<blink::HeapDeque<T, 0>> { | 1454 template <typename T> struct VectorTraits<blink::HeapDeque<T, 0>> : VectorTraits Base<blink::HeapDeque<T, 0>> { |
1209 static const bool needsDestruction = false; | 1455 static const bool needsDestruction = false; |
1210 static const bool canInitializeWithMemset = true; | 1456 static const bool canInitializeWithMemset = true; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1282 static bool traceInCollection(VisitorDispatcher visitor, blink::WeakMember<T >& weakMember, ShouldWeakPointersBeMarkedStrongly strongify) | 1528 static bool traceInCollection(VisitorDispatcher visitor, blink::WeakMember<T >& weakMember, ShouldWeakPointersBeMarkedStrongly strongify) |
1283 { | 1529 { |
1284 if (strongify == WeakPointersActStrong) { | 1530 if (strongify == WeakPointersActStrong) { |
1285 visitor->trace(weakMember.get()); // Strongified visit. | 1531 visitor->trace(weakMember.get()); // Strongified visit. |
1286 return false; | 1532 return false; |
1287 } | 1533 } |
1288 return !blink::Heap::isHeapObjectAlive(weakMember); | 1534 return !blink::Heap::isHeapObjectAlive(weakMember); |
1289 } | 1535 } |
1290 }; | 1536 }; |
1291 | 1537 |
1538 template<typename T> struct HashTraits<blink::UntracedMember<T>> : SimpleClassHa shTraits<blink::UntracedMember<T>> { | |
1539 static const bool needsDestruction = false; | |
1540 // FIXME: The distinction between PeekInType and PassInType is there for | |
1541 // the sake of the reference counting handles. When they are gone the two | |
1542 // types can be merged into PassInType. | |
1543 // FIXME: Implement proper const'ness for iterator types. | |
1544 using PeekInType = RawPtr<T>; | |
1545 using PassInType = RawPtr<T>; | |
1546 using IteratorGetType = blink::UntracedMember<T>*; | |
1547 using IteratorConstGetType = const blink::UntracedMember<T>*; | |
1548 using IteratorReferenceType = blink::UntracedMember<T>&; | |
1549 using IteratorConstReferenceType = const blink::UntracedMember<T>&; | |
1550 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; } | |
1551 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; } | |
1552 // FIXME: Similarly, there is no need for a distinction between PeekOutType | |
1553 // and PassOutType without reference counting. | |
1554 using PeekOutType = T*; | |
1555 using PassOutType = T*; | |
1556 | |
1557 template<typename U> | |
1558 static void store(const U& value, blink::UntracedMember<T>& storage) { stora ge = value; } | |
1559 | |
1560 static PeekOutType peek(const blink::UntracedMember<T>& value) { return valu e; } | |
1561 static PassOutType passOut(const blink::UntracedMember<T>& value) { return v alue; } | |
1562 }; | |
1563 | |
1292 template<typename T> struct PtrHash<blink::Member<T>> : PtrHash<T*> { | 1564 template<typename T> struct PtrHash<blink::Member<T>> : PtrHash<T*> { |
1293 template<typename U> | 1565 template<typename U> |
1294 static unsigned hash(const U& key) { return PtrHash<T*>::hash(key); } | 1566 static unsigned hash(const U& key) { return PtrHash<T*>::hash(key); } |
1295 static bool equal(T* a, const blink::Member<T>& b) { return a == b; } | 1567 static bool equal(T* a, const blink::Member<T>& b) { return a == b; } |
1296 static bool equal(const blink::Member<T>& a, T* b) { return a == b; } | 1568 static bool equal(const blink::Member<T>& a, T* b) { return a == b; } |
1297 template<typename U, typename V> | 1569 template<typename U, typename V> |
1298 static bool equal(const U& a, const V& b) { return a == b; } | 1570 static bool equal(const U& a, const V& b) { return a == b; } |
1299 }; | 1571 }; |
1300 | 1572 |
1301 template<typename T> struct PtrHash<blink::WeakMember<T>> : PtrHash<blink::Membe r<T>> { | 1573 template<typename T> struct PtrHash<blink::WeakMember<T>> : PtrHash<blink::Membe r<T>> { |
1302 }; | 1574 }; |
1303 | 1575 |
1304 // PtrHash is the default hash for hash tables with members. | 1576 // PtrHash is the default hash for hash tables with members. |
1305 template<typename T> struct DefaultHash<blink::Member<T>> { | 1577 template<typename T> struct DefaultHash<blink::Member<T>> { |
1306 using Hash = PtrHash<blink::Member<T>>; | 1578 using Hash = PtrHash<blink::Member<T>>; |
1307 }; | 1579 }; |
1308 | 1580 |
1309 template<typename T> struct DefaultHash<blink::WeakMember<T>> { | 1581 template<typename T> struct DefaultHash<blink::WeakMember<T>> { |
1310 using Hash = PtrHash<blink::WeakMember<T>>; | 1582 using Hash = PtrHash<blink::WeakMember<T>>; |
1311 }; | 1583 }; |
1312 | 1584 |
1585 template<typename T> struct DefaultHash<blink::UntracedMember<T>> { | |
1586 using Hash = PtrHash<blink::UntracedMember<T>>; | |
1587 }; | |
1588 | |
1313 template<typename T> | 1589 template<typename T> |
1314 struct NeedsTracing<blink::Member<T>> { | 1590 struct NeedsTracing<blink::Member<T>> { |
1315 static const bool value = true; | 1591 static const bool value = true; |
1316 }; | 1592 }; |
1317 | 1593 |
1318 template<typename T> | 1594 template<typename T> |
1319 struct IsWeak<blink::WeakMember<T>> { | 1595 struct IsWeak<blink::WeakMember<T>> { |
1320 static const bool value = true; | 1596 static const bool value = true; |
1321 }; | 1597 }; |
1322 | 1598 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. | 1657 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. |
1382 static T* unwrap(const StorageType& value) { return value.get(); } | 1658 static T* unwrap(const StorageType& value) { return value.get(); } |
1383 }; | 1659 }; |
1384 | 1660 |
1385 template<typename T> | 1661 template<typename T> |
1386 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1662 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
1387 | 1663 |
1388 } // namespace WTF | 1664 } // namespace WTF |
1389 | 1665 |
1390 #endif | 1666 #endif |
OLD | NEW |