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

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

Issue 1233173002: Have ScriptPromiseResolver on the Oilpan heap always. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: keepAliveWhilePending() comment Created 5 years, 5 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 | « Source/platform/exported/WebCryptoResult.cpp ('k') | Source/web/StorageQuotaClientImpl.cpp » ('j') | 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 b25f3bbc0789009772a04ecf8d53943cbcdb9614..d085230a025cd81fc901a90a0eb8eb1f2b608471 100644
--- a/Source/platform/heap/Handle.h
+++ b/Source/platform/heap/Handle.h
@@ -1011,6 +1011,59 @@ private:
Member<T> m_object;
};
+// SelfKeepAlive<Object> is the idiom to use for objects that have to keep
+// themselves temporarily alive and cannot rely on there being some
+// external reference in that interval:
+//
+// class Opener {
+// public:
+// ...
+// void open()
+// {
+// // Retain a self-reference while in an open()ed state:
+// m_keepAlive = this;
+// ....
+// }
+//
+// void close()
+// {
+// // Clear self-reference that ensured we were kept alive while opened.
+// m_keepAlive.clear();
+// ....
+// }
+//
+// private:
+// ...
+// SelfKeepAlive m_keepAlive;
+// };
+//
+// The responsibility to call clear() in a timely fashion resides with the implementation
+// of the object.
+//
+//
+template<typename Self>
+class SelfKeepAlive {
haraken 2015/07/30 11:41:21 Can we land this (with some HeapTests) ahead of th
+public:
+ SelfKeepAlive& operator=(Self* self)
+ {
+ ASSERT(!m_keepAlive || m_keepAlive.get() == self);
+ m_keepAlive = self;
+ return *this;
+ }
+
+ void clear()
+ {
+ m_keepAlive = nullptr;
+ }
+
+ typedef Persistent<Self> (SelfKeepAlive::*UnspecifiedBoolType);
+ operator UnspecifiedBoolType() const { return m_keepAlive ? &SelfKeepAlive::m_keepAlive : 0; }
+
+private:
+ GC_PLUGIN_IGNORE("420515")
+ Persistent<Self> m_keepAlive;
+};
+
} // namespace blink
namespace WTF {
« no previous file with comments | « Source/platform/exported/WebCryptoResult.cpp ('k') | Source/web/StorageQuotaClientImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698