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

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

Issue 1999343002: Unify and provide one IsGarbageCollectedType<T> implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit test Created 4 years, 7 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/wtf/Functional.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/TypeTraits.h
diff --git a/third_party/WebKit/Source/wtf/TypeTraits.h b/third_party/WebKit/Source/wtf/TypeTraits.h
index e3c91191fe0fa1294d01edba511de1eab30e5758..d1e2c425e6f44c45806cc16b270001a36c6d867f 100644
--- a/third_party/WebKit/Source/wtf/TypeTraits.h
+++ b/third_party/WebKit/Source/wtf/TypeTraits.h
@@ -300,10 +300,33 @@ class IsGarbageCollectedType {
char padding[8];
} NoType;
+ static_assert(sizeof(T), "T must be fully defined");
+
+ using NonConstType = typename std::remove_const<T>::type;
template <typename U> static YesType checkGarbageCollectedType(typename U::IsGarbageCollectedTypeMarker*);
template <typename U> static NoType checkGarbageCollectedType(...);
+
+ // Separately check for GarbageCollectedMixin, which declares a different
+ // marker typedef, to avoid resolution ambiguity for cases like
+ // IsGarbageCollectedType<B> over:
+ //
+ // class A : public GarbageCollected<A>, public GarbageCollectedMixin {
+ // USING_GARBAGE_COLLECTED_MIXIN(A);
+ // ...
+ // };
+ // class B : public A, public GarbageCollectedMixin { ... };
+ //
+ template <typename U> static YesType checkGarbageCollectedMixinType(typename U::IsGarbageCollectedMixinMarker*);
+ template <typename U> static NoType checkGarbageCollectedMixinType(...);
public:
- static const bool value = (sizeof(YesType) == sizeof(checkGarbageCollectedType<T>(nullptr)));
+ static const bool value = (sizeof(YesType) == sizeof(checkGarbageCollectedType<NonConstType>(nullptr)))
+ || (sizeof(YesType) == sizeof(checkGarbageCollectedMixinType<NonConstType>(nullptr)));
+};
+
+template<>
+class IsGarbageCollectedType<void> {
+public:
+ static const bool value = false;
};
template<typename T>
@@ -319,17 +342,20 @@ public:
static const bool value = (sizeof(YesType) == sizeof(checkPersistentReferenceType<T>(nullptr)));
};
-template<typename T>
+template<typename T, bool = std::is_function<typename std::remove_const<typename std::remove_pointer<T>::type>::type>::value || std::is_void<typename std::remove_const<typename std::remove_pointer<T>::type>::type>::value>
class IsPointerToGarbageCollectedType {
public:
static const bool value = false;
};
+
template<typename T>
-class IsPointerToGarbageCollectedType<T*> {
+class IsPointerToGarbageCollectedType<T*, false> {
public:
static const bool value = IsGarbageCollectedType<T>::value;
};
} // namespace WTF
+using WTF::IsGarbageCollectedType;
+
#endif // TypeTraits_h
« no previous file with comments | « third_party/WebKit/Source/wtf/Functional.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698