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 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 private: | 1189 private: |
1190 | 1190 |
1191 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \ | 1191 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \ |
1192 type::~type() { } | 1192 type::~type() { } |
1193 | 1193 |
1194 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \ | 1194 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \ |
1195 DEFINE_STATIC_REF(type, name, arguments) | 1195 DEFINE_STATIC_REF(type, name, arguments) |
1196 | 1196 |
1197 #endif // ENABLE(OILPAN) | 1197 #endif // ENABLE(OILPAN) |
1198 | 1198 |
1199 template<typename T, bool = IsGarbageCollectedType<T>::value> | |
1200 class PointerFieldStorageTrait { | |
1201 public: | |
1202 using Type = RawPtr<T>; | |
1203 }; | |
1204 | |
1205 template<typename T> | |
1206 class PointerFieldStorageTrait<T, true> { | |
1207 public: | |
1208 using Type = Member<T>; | |
1209 }; | |
1210 | |
1211 // Abstraction for injecting calls to an object's 'dispose()' method | 1199 // Abstraction for injecting calls to an object's 'dispose()' method |
1212 // on leaving a stack scope, ensuring earlier release of resources | 1200 // on leaving a stack scope, ensuring earlier release of resources |
1213 // than waiting until the object is eventually GCed. | 1201 // than waiting until the object is eventually GCed. |
1214 template<typename T, void (T::*Disposer)() = (&T::dispose)> | 1202 template<typename T, void (T::*Disposer)() = (&T::dispose)> |
1215 class ScopedDisposal { | 1203 class ScopedDisposal { |
1216 STACK_ALLOCATED(); | 1204 STACK_ALLOCATED(); |
1217 public: | 1205 public: |
1218 ScopedDisposal(T* object) | 1206 ScopedDisposal(T* object) |
1219 : m_object(object) | 1207 : m_object(object) |
1220 { | 1208 { |
1221 } | 1209 } |
1222 | 1210 |
1223 ~ScopedDisposal() | 1211 ~ScopedDisposal() |
1224 { | 1212 { |
1225 if (m_object) | 1213 if (m_object) |
1226 (m_object->*Disposer)(); | 1214 (m_object->*Disposer)(); |
1227 } | 1215 } |
1228 | 1216 |
1229 void clear() { m_object.clear(); } | 1217 void clear() { m_object.clear(); } |
1230 | 1218 |
1231 private: | 1219 private: |
| 1220 template<typename U, bool = IsGarbageCollectedType<U>::value> |
| 1221 class PointerFieldStorageTrait { |
| 1222 public: |
| 1223 using Type = RawPtr<U>; |
| 1224 }; |
| 1225 |
| 1226 template<typename U> |
| 1227 class PointerFieldStorageTrait<U, true> { |
| 1228 public: |
| 1229 using Type = Member<U>; |
| 1230 }; |
| 1231 |
1232 typename PointerFieldStorageTrait<T>::Type m_object; | 1232 typename PointerFieldStorageTrait<T>::Type m_object; |
1233 }; | 1233 }; |
1234 | 1234 |
1235 // SelfKeepAlive<Object> is the idiom to use for objects that have to keep | 1235 // SelfKeepAlive<Object> is the idiom to use for objects that have to keep |
1236 // themselves temporarily alive and cannot rely on there being some | 1236 // themselves temporarily alive and cannot rely on there being some |
1237 // external reference in that interval: | 1237 // external reference in that interval: |
1238 // | 1238 // |
1239 // class Opener { | 1239 // class Opener { |
1240 // public: | 1240 // public: |
1241 // ... | 1241 // ... |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 static_assert(sizeof(T), "T must be fully defined"); | 1573 static_assert(sizeof(T), "T must be fully defined"); |
1574 using StorageType = blink::CrossThreadWeakPersistent<T>; | 1574 using StorageType = blink::CrossThreadWeakPersistent<T>; |
1575 | 1575 |
1576 static StorageType wrap(const blink::AllowCrossThreadWeakPersistent<T>& valu
e) { return value.value(); } | 1576 static StorageType wrap(const blink::AllowCrossThreadWeakPersistent<T>& valu
e) { return value.value(); } |
1577 | 1577 |
1578 // Currently assume that the call sites of this unwrap() account for cleared
weak references also. | 1578 // Currently assume that the call sites of this unwrap() account for cleared
weak references also. |
1579 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C
rossThread)WeakPersistent. | 1579 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C
rossThread)WeakPersistent. |
1580 static T* unwrap(const StorageType& value) { return value.get(); } | 1580 static T* unwrap(const StorageType& value) { return value.get(); } |
1581 }; | 1581 }; |
1582 | 1582 |
| 1583 // Adoption is not needed nor wanted for RefCountedGarbageCollected<>-derived ty
pes. |
1583 template<typename T> | 1584 template<typename T> |
1584 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1585 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
1585 | 1586 |
1586 } // namespace WTF | 1587 } // namespace WTF |
1587 | 1588 |
1588 #endif | 1589 #endif |
OLD | NEW |