Bug 1153295 - Select StorensRefPtrPassPtr for types with AddRef and Release methods. r=nfroyd

This commit is contained in:
Gerald Squelart 2015-04-26 04:52:00 -04:00
Родитель f330df40d4
Коммит 2b1b8b1729
1 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -521,9 +521,24 @@ struct NonnsISupportsPointerStorageClass
StorePtrPassByPtr<TWithoutPointer>> StorePtrPassByPtr<TWithoutPointer>>
{}; {};
template<typename>
struct SFINAE1True : mozilla::TrueType
{};
template<class T>
static auto HasRefCountMethodsTest(int)
-> SFINAE1True<decltype(mozilla::DeclVal<T>().AddRef(),
mozilla::DeclVal<T>().Release())>;
template<class>
static auto HasRefCountMethodsTest(long) -> mozilla::FalseType;
template<class T>
struct HasRefCountMethods : decltype(HasRefCountMethodsTest<T>(0))
{};
template<typename TWithoutPointer> template<typename TWithoutPointer>
struct PointerStorageClass struct PointerStorageClass
: mozilla::Conditional<mozilla::IsBaseOf<nsISupports, TWithoutPointer>::value, : mozilla::Conditional<HasRefCountMethods<TWithoutPointer>::value,
StorensRefPtrPassByPtr<TWithoutPointer>, StorensRefPtrPassByPtr<TWithoutPointer>,
typename NonnsISupportsPointerStorageClass< typename NonnsISupportsPointerStorageClass<
TWithoutPointer TWithoutPointer
@ -566,7 +581,8 @@ struct NonParameterStorageClass
// Choose storage&passing strategy based on preferred storage type: // Choose storage&passing strategy based on preferred storage type:
// - If IsParameterStorageClass<T>::value is true, use as-is. // - If IsParameterStorageClass<T>::value is true, use as-is.
// - nsISupports* -> StorensRefPtrPassByPtr<T> : Store nsRefPtr<T>, pass T* // - RC* -> StorensRefPtrPassByPtr<RC> : Store nsRefPtr<RC>, pass RC*
// ^^ RC quacks like a ref-counted type (i.e., has AddRef and Release methods)
// - const T* -> StoreConstPtrPassByConstPtr<T> : Store const T*, pass const T* // - const T* -> StoreConstPtrPassByConstPtr<T> : Store const T*, pass const T*
// - T* -> StorePtrPassByPtr<T> : Store T*, pass T*. // - T* -> StorePtrPassByPtr<T> : Store T*, pass T*.
// - const T& -> StoreConstRefPassByConstLRef<T>: Store const T&, pass const T&. // - const T& -> StoreConstRefPassByConstLRef<T>: Store const T&, pass const T&.