Bug 1607796 - Use <type_traits> in dom/bindings. r=bzbarsky

Automatic but manually checked via s/IsBaseOf</std::is_base_of</g and so on.

Differential Revision: https://phabricator.services.mozilla.com/D59145

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2020-01-08 16:40:12 +00:00
Родитель 95e45a637b
Коммит 80322da13a
3 изменённых файлов: 39 добавлений и 30 удалений

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

@ -26,6 +26,8 @@
#include "nsString.h"
#include "nsTArray.h"
#include <type_traits>
class nsIPrincipal;
class nsWrapperCache;
@ -61,13 +63,15 @@ struct DictionaryBase {
};
template <typename T>
inline typename EnableIf<std::is_base_of<DictionaryBase, T>::value, void>::Type
inline typename std::enable_if<std::is_base_of<DictionaryBase, T>::value,
void>::type
ImplCycleCollectionUnlink(T& aDictionary) {
aDictionary.UnlinkForCC();
}
template <typename T>
inline typename EnableIf<std::is_base_of<DictionaryBase, T>::value, void>::Type
inline typename std::enable_if<std::is_base_of<DictionaryBase, T>::value,
void>::type
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
T& aDictionary, const char* aName,
uint32_t aFlags = 0) {
@ -75,8 +79,8 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
}
// Struct that serves as a base class for all typed arrays and array buffers and
// array buffer views. Particularly useful so we can use std::is_base_of to detect
// typed array/buffer/view template arguments.
// array buffer views. Particularly useful so we can use std::is_base_of to
// detect typed array/buffer/view template arguments.
struct AllTypedArraysBase {};
// Struct that serves as a base class for all owning unions.

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

@ -8183,7 +8183,7 @@ class CGPerSignatureCall(CGThing):
self.returnType.isPromise())):
wrapCode += dedent(
"""
static_assert(!IsPointer<decltype(result)>::value,
static_assert(!std::is_pointer_v<decltype(result)>,
"NewObject implies that we need to keep the object alive with a strong reference.");
""")

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

@ -20,6 +20,8 @@
#include "nsWrapperCache.h"
#include "nsAutoPtr.h"
#include <type_traits>
namespace mozilla {
namespace dom {
@ -39,8 +41,8 @@ MOZ_MUST_USE bool ToJSValue(JSContext* aCx, const nsAString& aArgument,
// desirable. So make this a template that only gets used if the argument type
// is actually boolean
template <typename T>
MOZ_MUST_USE typename EnableIf<IsSame<T, bool>::value, bool>::Type ToJSValue(
JSContext* aCx, T aArgument, JS::MutableHandle<JS::Value> aValue) {
MOZ_MUST_USE typename std::enable_if<std::is_same<T, bool>::value, bool>::type
ToJSValue(JSContext* aCx, T aArgument, JS::MutableHandle<JS::Value> aValue) {
// Make sure we're called in a compartment
MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx));
@ -118,10 +120,9 @@ MOZ_MUST_USE inline bool ToJSValue(JSContext* aCx, CallbackObject& aArgument,
// Accept objects that inherit from nsWrapperCache (e.g. most
// DOM objects).
template <class T>
MOZ_MUST_USE
typename EnableIf<std::is_base_of<nsWrapperCache, T>::value, bool>::Type
ToJSValue(JSContext* aCx, T& aArgument,
JS::MutableHandle<JS::Value> aValue) {
MOZ_MUST_USE typename std::enable_if<std::is_base_of<nsWrapperCache, T>::value,
bool>::type
ToJSValue(JSContext* aCx, T& aArgument, JS::MutableHandle<JS::Value> aValue) {
// Make sure we're called in a compartment
MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx));
@ -134,8 +135,8 @@ MOZ_MUST_USE
namespace binding_detail {
template <class T>
MOZ_MUST_USE
typename EnableIf<std::is_base_of<NonRefcountedDOMObject, T>::value,
bool>::Type
typename std::enable_if<std::is_base_of<NonRefcountedDOMObject, T>::value,
bool>::type
ToJSValueFromPointerHelper(JSContext* aCx, T* aArgument,
JS::MutableHandle<JS::Value> aValue) {
// Make sure we're called in a compartment
@ -163,8 +164,8 @@ MOZ_MUST_USE
// nsAutoPtr.
template <class T>
MOZ_MUST_USE
typename EnableIf<std::is_base_of<NonRefcountedDOMObject, T>::value,
bool>::Type
typename std::enable_if<std::is_base_of<NonRefcountedDOMObject, T>::value,
bool>::type
ToJSValue(JSContext* aCx, nsAutoPtr<T>&& aArgument,
JS::MutableHandle<JS::Value> aValue) {
if (!binding_detail::ToJSValueFromPointerHelper(aCx, aArgument.get(),
@ -181,8 +182,8 @@ MOZ_MUST_USE
// UniquePtr.
template <class T>
MOZ_MUST_USE
typename EnableIf<std::is_base_of<NonRefcountedDOMObject, T>::value,
bool>::Type
typename std::enable_if<std::is_base_of<NonRefcountedDOMObject, T>::value,
bool>::type
ToJSValue(JSContext* aCx, UniquePtr<T>&& aArgument,
JS::MutableHandle<JS::Value> aValue) {
if (!binding_detail::ToJSValueFromPointerHelper(aCx, aArgument.get(),
@ -198,7 +199,8 @@ MOZ_MUST_USE
// Accept typed arrays built from appropriate nsTArray values
template <typename T>
MOZ_MUST_USE
typename EnableIf<std::is_base_of<AllTypedArraysBase, T>::value, bool>::Type
typename std::enable_if<std::is_base_of<AllTypedArraysBase, T>::value,
bool>::type
ToJSValue(JSContext* aCx, const TypedArrayCreator<T>& aArgument,
JS::MutableHandle<JS::Value> aValue) {
// Make sure we're called in a compartment
@ -215,11 +217,13 @@ MOZ_MUST_USE
// Accept objects that inherit from nsISupports but not nsWrapperCache (e.g.
// DOM File).
template <class T>
MOZ_MUST_USE typename EnableIf<!std::is_base_of<nsWrapperCache, T>::value &&
MOZ_MUST_USE
typename std::enable_if<!std::is_base_of<nsWrapperCache, T>::value &&
!std::is_base_of<CallbackObject, T>::value &&
std::is_base_of<nsISupports, T>::value,
bool>::Type
ToJSValue(JSContext* aCx, T& aArgument, JS::MutableHandle<JS::Value> aValue) {
bool>::type
ToJSValue(JSContext* aCx, T& aArgument,
JS::MutableHandle<JS::Value> aValue) {
// Make sure we're called in a compartment
MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx));
@ -252,9 +256,9 @@ MOZ_MUST_USE bool ToJSValue(JSContext* aCx, const NonNull<T>& aArgument,
// Accept WebIDL dictionaries
template <class T>
MOZ_MUST_USE
typename EnableIf<std::is_base_of<DictionaryBase, T>::value, bool>::Type
ToJSValue(JSContext* aCx, const T& aArgument,
MOZ_MUST_USE typename std::enable_if<std::is_base_of<DictionaryBase, T>::value,
bool>::type
ToJSValue(JSContext* aCx, const T& aArgument,
JS::MutableHandle<JS::Value> aValue) {
return aArgument.ToObjectInternal(aCx, aValue);
}
@ -312,7 +316,8 @@ MOZ_MUST_USE bool ToJSValue(JSContext* aCx, ErrorResult& aArgument,
// Accept owning WebIDL unions.
template <typename T>
MOZ_MUST_USE
typename EnableIf<std::is_base_of<AllOwningUnionBase, T>::value, bool>::Type
typename std::enable_if<std::is_base_of<AllOwningUnionBase, T>::value,
bool>::type
ToJSValue(JSContext* aCx, const T& aArgument,
JS::MutableHandle<JS::Value> aValue) {
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
@ -321,8 +326,8 @@ MOZ_MUST_USE
// Accept pointers to other things we accept
template <typename T>
MOZ_MUST_USE typename EnableIf<IsPointer<T>::value, bool>::Type ToJSValue(
JSContext* aCx, T aArgument, JS::MutableHandle<JS::Value> aValue) {
MOZ_MUST_USE typename std::enable_if<std::is_pointer<T>::value, bool>::type
ToJSValue(JSContext* aCx, T aArgument, JS::MutableHandle<JS::Value> aValue) {
return ToJSValue(aCx, *aArgument, aValue);
}