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

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

Issue 1568213002: DEFINE_STATIC_LOCAL(): assert against illegal use of GCed types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 | « third_party/WebKit/Source/platform/heap/Handle.h ('k') | 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 623fd15af0436effed7eef24c8d001d64a5e7de6..824c579a358dad705caacc8e528fe0d1ba322fe0 100644
--- a/third_party/WebKit/Source/wtf/StdLibExtras.h
+++ b/third_party/WebKit/Source/wtf/StdLibExtras.h
@@ -59,6 +59,14 @@ private:
};
#endif
+// A direct static local to a Blink garbage collected objects isn't allowed;
+// must be wrapped up with a persistent reference.
+#define STATIC_ASSERT_FOR_LOCAL_WITH_GARBAGE_COLLECTED_TYPE(Name, Type) \
+ using Name##NoConstType = std::remove_const<Type>::type; \
+ using Name##NoPointerType = std::remove_pointer<Name##NoConstType>::type; \
+ using Name##NoReferenceType = std::remove_reference<Name##NoPointerType>::type; \
+ static_assert(!WTF::IsGarbageCollectedType<Name##NoReferenceType>::value || WTF::IsPersistentReferenceType<Name##NoReferenceType>::value, "Garbage collected static local needs to be wrapped up with a persistent reference")
+
// Use DEFINE_STATIC_LOCAL() to declare and define a static local variable (static T;)
// so that it is leaked and its destructors are not called at exit.
//
@@ -68,13 +76,15 @@ private:
// LEAK_SANITIZER_REGISTER_STATIC_LOCAL() takes care of the details.
//
#if ENABLE(ASSERT)
-#define DEFINE_STATIC_LOCAL(type, name, arguments) \
- static StaticLocalVerifier name##StaticLocalVerifier; \
- ASSERT(name##StaticLocalVerifier.isNotRacy()); \
- static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arguments)
+#define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \
+ STATIC_ASSERT_FOR_LOCAL_WITH_GARBAGE_COLLECTED_TYPE(Name, Type); \
+ static StaticLocalVerifier Name##StaticLocalVerifier; \
+ ASSERT(Name##StaticLocalVerifier.isNotRacy()); \
+ static Type& Name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(Type, new Type Arguments)
#else
-#define DEFINE_STATIC_LOCAL(type, name, arguments) \
- static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arguments)
+#define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \
+ STATIC_ASSERT_FOR_LOCAL_WITH_GARBAGE_COLLECTED_TYPE(Name, Type); \
+ static Type& Name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(Type, new Type Arguments)
#endif
// Use this to declare and define a static local pointer to a ref-counted object so that
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Handle.h ('k') | third_party/WebKit/Source/wtf/TypeTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698