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

Unified Diff: third_party/WebKit/Source/wtf/StdLibExtras.h

Issue 2674973005: Disallow static locals of ScriptWrappable-derived objects.
Patch Set: Created 3 years, 10 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 | third_party/WebKit/Source/wtf/TypeTraits.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/StdLibExtras.h
diff --git a/third_party/WebKit/Source/wtf/StdLibExtras.h b/third_party/WebKit/Source/wtf/StdLibExtras.h
index 26ba1d8d02958298aacfc73daea5743ccbbce201..3ceeffbfaf57129164c618c89d9e769f31bb77b4 100644
--- a/third_party/WebKit/Source/wtf/StdLibExtras.h
+++ b/third_party/WebKit/Source/wtf/StdLibExtras.h
@@ -63,6 +63,8 @@ class WTF_EXPORT StaticLocalVerifier {
namespace blink {
template <typename T>
class Persistent;
+
+class ScriptWrappable;
};
template <typename T,
@@ -112,12 +114,19 @@ class StaticLocalWrapper<T, true> {
// LEAK_SANITIZER_REGISTER_STATIC_LOCAL() use, it taking care of the grungy
// details.
//
-#define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \
- DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name); \
- using WrappedTypeFor##Name = StaticLocalWrapper<Type>::WrapType; \
- static WrappedTypeFor##Name* WrappedInstanceFor##Name = \
- LEAK_SANITIZER_REGISTER_STATIC_LOCAL( \
- WrappedTypeFor##Name, new WrappedTypeFor##Name Arguments); \
+#define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \
+ DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name); \
+ using WrappedTypeFor##Name = StaticLocalWrapper<Type>::WrapType; \
+ static_assert( \
+ !WTF::IsPersistentReferenceType<WrappedTypeFor##Name>::value || \
+ !WTF::IsSubclass<WTF::RemoveTemplate<WrappedTypeFor##Name, \
+ blink::Persistent>::type, \
+ blink::ScriptWrappable>::value, \
+ "It is unsafe to keep a static local singleton to a " \
+ "ScriptWrappable-derived object"); \
+ static WrappedTypeFor##Name* WrappedInstanceFor##Name = \
+ LEAK_SANITIZER_REGISTER_STATIC_LOCAL( \
+ WrappedTypeFor##Name, new WrappedTypeFor##Name Arguments); \
Type& Name = StaticLocalWrapper<Type>::unwrap(WrappedInstanceFor##Name);
// Use this to declare and define a static local pointer to a ref-counted object
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/TypeTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698