Chromium Code Reviews| 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 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1004 if (m_object) | 1004 if (m_object) |
| 1005 m_object->dispose(); | 1005 m_object->dispose(); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 void clear() { m_object.clear(); } | 1008 void clear() { m_object.clear(); } |
| 1009 | 1009 |
| 1010 private: | 1010 private: |
| 1011 Member<T> m_object; | 1011 Member<T> m_object; |
| 1012 }; | 1012 }; |
| 1013 | 1013 |
| 1014 // SelfKeepAlive<Object> is the idiom to use for objects that have to keep | |
| 1015 // themselves temporarily alive and cannot rely on there being some | |
| 1016 // external reference in that interval: | |
| 1017 // | |
| 1018 // class Opener { | |
| 1019 // public: | |
| 1020 // ... | |
| 1021 // void open() | |
| 1022 // { | |
| 1023 // // Retain a self-reference while in an open()ed state: | |
| 1024 // m_keepAlive = this; | |
| 1025 // .... | |
| 1026 // } | |
| 1027 // | |
| 1028 // void close() | |
| 1029 // { | |
| 1030 // // Clear self-reference that ensured we were kept alive while opened. | |
| 1031 // m_keepAlive.clear(); | |
| 1032 // .... | |
| 1033 // } | |
| 1034 // | |
| 1035 // private: | |
| 1036 // ... | |
| 1037 // SelfKeepAlive m_keepAlive; | |
| 1038 // }; | |
| 1039 // | |
| 1040 // The responsibility to call clear() in a timely fashion resides with the imple mentation | |
| 1041 // of the object. | |
| 1042 // | |
| 1043 // | |
| 1044 template<typename Self> | |
| 1045 class SelfKeepAlive { | |
|
haraken
2015/07/30 11:41:21
Can we land this (with some HeapTests) ahead of th
| |
| 1046 public: | |
| 1047 SelfKeepAlive& operator=(Self* self) | |
| 1048 { | |
| 1049 ASSERT(!m_keepAlive || m_keepAlive.get() == self); | |
| 1050 m_keepAlive = self; | |
| 1051 return *this; | |
| 1052 } | |
| 1053 | |
| 1054 void clear() | |
| 1055 { | |
| 1056 m_keepAlive = nullptr; | |
| 1057 } | |
| 1058 | |
| 1059 typedef Persistent<Self> (SelfKeepAlive::*UnspecifiedBoolType); | |
| 1060 operator UnspecifiedBoolType() const { return m_keepAlive ? &SelfKeepAlive:: m_keepAlive : 0; } | |
| 1061 | |
| 1062 private: | |
| 1063 GC_PLUGIN_IGNORE("420515") | |
| 1064 Persistent<Self> m_keepAlive; | |
| 1065 }; | |
| 1066 | |
| 1014 } // namespace blink | 1067 } // namespace blink |
| 1015 | 1068 |
| 1016 namespace WTF { | 1069 namespace WTF { |
| 1017 | 1070 |
| 1018 template <typename T> struct VectorTraits<blink::Member<T>> : VectorTraitsBase<b link::Member<T>> { | 1071 template <typename T> struct VectorTraits<blink::Member<T>> : VectorTraitsBase<b link::Member<T>> { |
| 1019 static const bool needsDestruction = false; | 1072 static const bool needsDestruction = false; |
| 1020 static const bool canInitializeWithMemset = true; | 1073 static const bool canInitializeWithMemset = true; |
| 1021 static const bool canClearUnusedSlotsWithMemset = true; | 1074 static const bool canClearUnusedSlotsWithMemset = true; |
| 1022 static const bool canMoveWithMemcpy = true; | 1075 static const bool canMoveWithMemcpy = true; |
| 1023 }; | 1076 }; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1213 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin k::IsGarbageCollectedType<T>::value> { | 1266 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin k::IsGarbageCollectedType<T>::value> { |
| 1214 static_assert(sizeof(T), "T must be fully defined"); | 1267 static_assert(sizeof(T), "T must be fully defined"); |
| 1215 }; | 1268 }; |
| 1216 | 1269 |
| 1217 template<typename T> | 1270 template<typename T> |
| 1218 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1271 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
| 1219 | 1272 |
| 1220 } // namespace WTF | 1273 } // namespace WTF |
| 1221 | 1274 |
| 1222 #endif | 1275 #endif |
| OLD | NEW |