--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -353,16 +353,49 @@ struct RemoveSmartPointerHelper<T, nsCOM
} // namespace detail
template<typename T>
struct RemoveSmartPointer
: detail::RemoveSmartPointerHelper<T, typename RemoveCV<T>::Type>
{};
+namespace detail {
+
+template<typename T, typename CVRemoved>
+struct RemoveRawOrSmartPointerHelper
+{
+ typedef T Type;
+};
+
+template<typename T, typename Pointee>
+struct RemoveRawOrSmartPointerHelper<T, Pointee*>
+{
+ typedef Pointee Type;
+};
+
+template<typename T, typename Pointee>
+struct RemoveRawOrSmartPointerHelper<T, RefPtr<Pointee>>
+{
+ typedef Pointee Type;
+};
+
+template<typename T, typename Pointee>
+struct RemoveRawOrSmartPointerHelper<T, nsCOMPtr<Pointee>>
+{
+ typedef Pointee Type;
+};
+
+} // namespace detail
+
+template<typename T>
+struct RemoveRawOrSmartPointer
+ : detail::RemoveRawOrSmartPointerHelper<T, typename RemoveCV<T>::Type>
+{};
+
} // namespace mozilla
inline nsISupports*
ToSupports(mozilla::Runnable *p)
{
return static_cast<nsIRunnable*>(p);
}
--- a/xpcom/glue/tests/gtest/TestThreadUtils.cpp
+++ b/xpcom/glue/tests/gtest/TestThreadUtils.cpp
@@ -2,16 +2,17 @@
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h>
#include <stdlib.h>
#include "nsThreadUtils.h"
+#include "mozilla/UniquePtr.h"
#include "gtest/gtest.h"
// {9e70a320-be02-11d1-8031-006008159b5a}
#define NS_IFOO_IID \
{0x9e70a320, 0xbe02, 0x11d1, \
{0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
TEST(ThreadUtils, TypeTraits)
@@ -32,32 +33,65 @@ TEST(ThreadUtils, TypeTraits)
"IsRefcountedSmartPointer<const nsCOMPtr<...>> should be true");
static_assert(mozilla::IsRefcountedSmartPointer<volatile nsCOMPtr<int>>::value,
"IsRefcountedSmartPointer<volatile nsCOMPtr<...>> should be true");
static_assert(mozilla::IsRefcountedSmartPointer<const volatile nsCOMPtr<int>>::value,
"IsRefcountedSmartPointer<const volatile nsCOMPtr<...>> should be true");
static_assert(mozilla::IsSame<int, mozilla::RemoveSmartPointer<int>::Type>::value,
"RemoveSmartPointer<int>::Type should be int");
+ static_assert(mozilla::IsSame<int*, mozilla::RemoveSmartPointer<int*>::Type>::value,
+ "RemoveSmartPointer<int*>::Type should be int*");
+ static_assert(mozilla::IsSame<UniquePtr<int>, mozilla::RemoveSmartPointer<UniquePtr<int>>::Type>::value,
+ "RemoveSmartPointer<UniquePtr<int>>::Type should be UniquePtr<int>");
static_assert(mozilla::IsSame<int, mozilla::RemoveSmartPointer<RefPtr<int>>::Type>::value,
"RemoveSmartPointer<RefPtr<int>>::Type should be int");
static_assert(mozilla::IsSame<int, mozilla::RemoveSmartPointer<const RefPtr<int>>::Type>::value,
"RemoveSmartPointer<const RefPtr<int>>::Type should be int");
static_assert(mozilla::IsSame<int, mozilla::RemoveSmartPointer<volatile RefPtr<int>>::Type>::value,
"RemoveSmartPointer<volatile RefPtr<int>>::Type should be int");
static_assert(mozilla::IsSame<int, mozilla::RemoveSmartPointer<const volatile RefPtr<int>>::Type>::value,
"RemoveSmartPointer<const volatile RefPtr<int>>::Type should be int");
static_assert(mozilla::IsSame<int, mozilla::RemoveSmartPointer<nsCOMPtr<int>>::Type>::value,
"RemoveSmartPointer<nsCOMPtr<int>>::Type should be int");
static_assert(mozilla::IsSame<int, mozilla::RemoveSmartPointer<const nsCOMPtr<int>>::Type>::value,
"RemoveSmartPointer<const nsCOMPtr<int>>::Type should be int");
static_assert(mozilla::IsSame<int, mozilla::RemoveSmartPointer<volatile nsCOMPtr<int>>::Type>::value,
"RemoveSmartPointer<volatile nsCOMPtr<int>>::Type should be int");
static_assert(mozilla::IsSame<int, mozilla::RemoveSmartPointer<const volatile nsCOMPtr<int>>::Type>::value,
"RemoveSmartPointer<const volatile nsCOMPtr<int>>::Type should be int");
+
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<int>::Type>::value,
+ "RemoveRawOrSmartPointer<int>::Type should be int");
+ static_assert(mozilla::IsSame<UniquePtr<int>, mozilla::RemoveRawOrSmartPointer<UniquePtr<int>>::Type>::value,
+ "RemoveRawOrSmartPointer<UniquePtr<int>>::Type should be UniquePtr<int>");
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<int*>::Type>::value,
+ "RemoveRawOrSmartPointer<int*>::Type should be int");
+ static_assert(mozilla::IsSame<const int, mozilla::RemoveRawOrSmartPointer<const int*>::Type>::value,
+ "RemoveRawOrSmartPointer<const int*>::Type should be const int");
+ static_assert(mozilla::IsSame<volatile int, mozilla::RemoveRawOrSmartPointer<volatile int*>::Type>::value,
+ "RemoveRawOrSmartPointer<volatile int*>::Type should be volatile int");
+ static_assert(mozilla::IsSame<const volatile int, mozilla::RemoveRawOrSmartPointer<const volatile int*>::Type>::value,
+ "RemoveRawOrSmartPointer<const volatile int*>::Type should be const volatile int");
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<RefPtr<int>>::Type>::value,
+ "RemoveRawOrSmartPointer<RefPtr<int>>::Type should be int");
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<const RefPtr<int>>::Type>::value,
+ "RemoveRawOrSmartPointer<const RefPtr<int>>::Type should be int");
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<volatile RefPtr<int>>::Type>::value,
+ "RemoveRawOrSmartPointer<volatile RefPtr<int>>::Type should be int");
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<const volatile RefPtr<int>>::Type>::value,
+ "RemoveRawOrSmartPointer<const volatile RefPtr<int>>::Type should be int");
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<nsCOMPtr<int>>::Type>::value,
+ "RemoveRawOrSmartPointer<nsCOMPtr<int>>::Type should be int");
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<const nsCOMPtr<int>>::Type>::value,
+ "RemoveRawOrSmartPointer<const nsCOMPtr<int>>::Type should be int");
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<volatile nsCOMPtr<int>>::Type>::value,
+ "RemoveRawOrSmartPointer<volatile nsCOMPtr<int>>::Type should be int");
+ static_assert(mozilla::IsSame<int, mozilla::RemoveRawOrSmartPointer<const volatile nsCOMPtr<int>>::Type>::value,
+ "RemoveRawOrSmartPointer<const volatile nsCOMPtr<int>>::Type should be int");
}
namespace TestThreadUtils {
static bool gDebug = false;
static int gAlive, gZombies;
static int gAllConstructions, gConstructions, gCopyConstructions,
gMoveConstructions, gDestructions, gAssignments, gMoves;