Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2615)

Unified Diff: Source/platform/heap/Handle.h

Issue 1332743002: Generalize ScopedDisposal<T> to handle non-GC types. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/Handle.h
diff --git a/Source/platform/heap/Handle.h b/Source/platform/heap/Handle.h
index fe1c9a6b37b3ea20e7a5ca2242597f239d7d70c3..744e58a4881f0600bedd90850d1b90e47c8937b4 100644
--- a/Source/platform/heap/Handle.h
+++ b/Source/platform/heap/Handle.h
@@ -895,29 +895,40 @@ template<typename T> PassOwnPtrWillBeRawPtr<T> adoptPtrWillBeNoop(T* ptr) { retu
#endif // ENABLE(OILPAN)
+template<typename T, bool = IsGarbageCollectedType<T>::value>
+class PointerFieldStorageTrait {
+public:
+ using Type = RawPtr<T>;
+};
+
+template<typename T>
+class PointerFieldStorageTrait<T, true> {
+public:
+ using Type = Member<T>;
+};
+
// Abstraction for injecting calls to an object's 'dispose()' method
// on leaving a stack scope, ensuring earlier release of resources
// than waiting until the object is eventually GCed.
-template<typename T>
+template<typename T, void (T::*Disposer)() = (&T::dispose)>
class ScopedDisposal {
STACK_ALLOCATED();
public:
ScopedDisposal(T* object)
: m_object(object)
{
- static_assert(IsGarbageCollectedType<T>::value, "can only be used with garbage collected types");
}
~ScopedDisposal()
{
if (m_object)
- m_object->dispose();
+ (m_object->*Disposer)();
}
void clear() { m_object.clear(); }
private:
- Member<T> m_object;
+ typename PointerFieldStorageTrait<T>::Type m_object;
};
// SelfKeepAlive<Object> is the idiom to use for objects that have to keep
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698