Bug 1623957 - Part 7: Replace mozilla::EnableIf with std::enable_if. r=jwalden
authorAndré Bargull <andre.bargull@gmail.com>
Sat, 21 Mar 2020 14:41:09 +0000
changeset 519991 c6427d6143d941135fedc5276e1e576dccbb00dd
parent 519990 680f4f1018e65fd996606e21aa81861df786c548
child 519992 2244abeb2f3602e8d4a8536b7e08660d3e3d7fa3
push id37237
push useraiakab@mozilla.com
push dateSat, 21 Mar 2020 21:28:09 +0000
treeherdermozilla-central@a1bea41f99f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1623957
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1623957 - Part 7: Replace mozilla::EnableIf with std::enable_if. r=jwalden Differential Revision: https://phabricator.services.mozilla.com/D67655
js/public/RootingAPI.h
js/public/Utility.h
js/public/Vector.h
js/src/jit/TypePolicy.h
js/src/threading/Thread.h
js/src/vm/JSContext-inl.h
js/src/vm/Xdr.h
--- a/js/public/RootingAPI.h
+++ b/js/public/RootingAPI.h
@@ -579,19 +579,19 @@ template <typename T>
 class MOZ_NONHEAP_CLASS Handle : public js::HandleBase<T, Handle<T>> {
   friend class MutableHandle<T>;
 
  public:
   using ElementType = T;
 
   /* Creates a handle from a handle of a type convertible to T. */
   template <typename S>
-  MOZ_IMPLICIT Handle(Handle<S> handle,
-                      typename mozilla::EnableIf<std::is_convertible_v<S, T>,
-                                                 int>::Type dummy = 0) {
+  MOZ_IMPLICIT Handle(
+      Handle<S> handle,
+      std::enable_if_t<std::is_convertible_v<S, T>, int> dummy = 0) {
     static_assert(sizeof(Handle<T>) == sizeof(T*),
                   "Handle must be binary compatible with T*.");
     ptr = reinterpret_cast<const T*>(handle.address());
   }
 
   MOZ_IMPLICIT Handle(decltype(nullptr)) {
     static_assert(mozilla::IsPointer<T>::value,
                   "nullptr_t overload not valid for non-pointer types");
@@ -623,31 +623,28 @@ class MOZ_NONHEAP_CLASS Handle : public 
 
   /*
    * Construct a handle from an explicitly rooted location. This is the
    * normal way to create a handle, and normally happens implicitly.
    */
   template <typename S>
   inline MOZ_IMPLICIT Handle(
       const Rooted<S>& root,
-      typename mozilla::EnableIf<std::is_convertible_v<S, T>, int>::Type dummy =
-          0);
+      std::enable_if_t<std::is_convertible_v<S, T>, int> dummy = 0);
 
   template <typename S>
   inline MOZ_IMPLICIT Handle(
       const PersistentRooted<S>& root,
-      typename mozilla::EnableIf<std::is_convertible_v<S, T>, int>::Type dummy =
-          0);
+      std::enable_if_t<std::is_convertible_v<S, T>, int> dummy = 0);
 
   /* Construct a read only handle from a mutable handle. */
   template <typename S>
   inline MOZ_IMPLICIT Handle(
       MutableHandle<S>& root,
-      typename mozilla::EnableIf<std::is_convertible_v<S, T>, int>::Type dummy =
-          0);
+      std::enable_if_t<std::is_convertible_v<S, T>, int> dummy = 0);
 
   DECLARE_POINTER_CONSTREF_OPS(T);
   DECLARE_NONPOINTER_ACCESSOR_METHODS(*ptr);
 
  private:
   Handle() = default;
   DELETE_ASSIGNMENT_OPS(Handle, T);
 
@@ -1237,33 +1234,33 @@ class HandleBase<JSObject*, Container>
 } /* namespace js */
 
 namespace JS {
 
 template <typename T>
 template <typename S>
 inline Handle<T>::Handle(
     const Rooted<S>& root,
-    typename mozilla::EnableIf<std::is_convertible_v<S, T>, int>::Type dummy) {
+    std::enable_if_t<std::is_convertible_v<S, T>, int> dummy) {
   ptr = reinterpret_cast<const T*>(root.address());
 }
 
 template <typename T>
 template <typename S>
 inline Handle<T>::Handle(
     const PersistentRooted<S>& root,
-    typename mozilla::EnableIf<std::is_convertible_v<S, T>, int>::Type dummy) {
+    std::enable_if_t<std::is_convertible_v<S, T>, int> dummy) {
   ptr = reinterpret_cast<const T*>(root.address());
 }
 
 template <typename T>
 template <typename S>
 inline Handle<T>::Handle(
     MutableHandle<S>& root,
-    typename mozilla::EnableIf<std::is_convertible_v<S, T>, int>::Type dummy) {
+    std::enable_if_t<std::is_convertible_v<S, T>, int> dummy) {
   ptr = reinterpret_cast<const T*>(root.address());
 }
 
 template <typename T>
 inline MutableHandle<T>::MutableHandle(Rooted<T>* root) {
   static_assert(sizeof(MutableHandle<T>) == sizeof(T*),
                 "MutableHandle must be binary compatible with T*.");
   ptr = root->address();
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -633,18 +633,17 @@ namespace JS {
 
 template <typename T>
 struct DeletePolicy {
   constexpr DeletePolicy() = default;
 
   template <typename U>
   MOZ_IMPLICIT DeletePolicy(
       DeletePolicy<U> other,
-      typename mozilla::EnableIf<std::is_convertible_v<U*, T*>, int>::Type
-          dummy = 0) {}
+      std::enable_if_t<std::is_convertible_v<U*, T*>, int> dummy = 0) {}
 
   void operator()(const T* ptr) { js_delete(const_cast<T*>(ptr)); }
 };
 
 struct FreePolicy {
   void operator()(const void* ptr) { js_free(const_cast<void*>(ptr)); }
 };
 
--- a/js/public/Vector.h
+++ b/js/public/Vector.h
@@ -3,16 +3,19 @@
  * 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/. */
 
 #ifndef js_Vector_h
 #define js_Vector_h
 
 #include "mozilla/Vector.h"
+
+#include <type_traits>
+
 #include "js/TypeDecls.h"
 
 namespace js {
 
 class JS_PUBLIC_API TempAllocPolicy;
 
 namespace detail {
 
@@ -22,15 +25,14 @@ struct TypeIsGCThing : mozilla::FalseTyp
 template <>
 struct TypeIsGCThing<JS::Value> : mozilla::TrueType {};
 
 }  // namespace detail
 
 template <typename T, size_t MinInlineCapacity = 0,
           class AllocPolicy = TempAllocPolicy,
           // Don't use this with JS::Value!  Use JS::RootedValueVector instead.
-          typename = typename mozilla::EnableIf<
-              !detail::TypeIsGCThing<T>::value>::Type>
+          typename = std::enable_if_t<!detail::TypeIsGCThing<T>::value>>
 using Vector = mozilla::Vector<T, MinInlineCapacity, AllocPolicy>;
 
 }  // namespace js
 
 #endif /* js_Vector_h */
--- a/js/src/jit/TypePolicy.h
+++ b/js/src/jit/TypePolicy.h
@@ -2,17 +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/. */
 
 #ifndef jit_TypePolicy_h
 #define jit_TypePolicy_h
 
-#include "mozilla/TypeTraits.h"
+#include <type_traits>
 
 #include "jit/IonTypes.h"
 #include "jit/JitAllocPolicy.h"
 
 namespace js {
 namespace jit {
 
 class MInstruction;
@@ -414,18 +414,18 @@ template <class... Policies>
 class MixPolicy final : public TypePolicy {
   template <class P>
   static bool staticAdjustInputsHelper(TempAllocator& alloc,
                                        MInstruction* ins) {
     return P::staticAdjustInputs(alloc, ins);
   }
 
   template <class P, class... Rest>
-  static typename mozilla::EnableIf<(sizeof...(Rest) > 0), bool>::Type
-  staticAdjustInputsHelper(TempAllocator& alloc, MInstruction* ins) {
+  static std::enable_if_t<(sizeof...(Rest) > 0), bool> staticAdjustInputsHelper(
+      TempAllocator& alloc, MInstruction* ins) {
     return P::staticAdjustInputs(alloc, ins) &&
            MixPolicy::staticAdjustInputsHelper<Rest...>(alloc, ins);
   }
 
  public:
   constexpr MixPolicy() = default;
   EMPTY_DATA_;
   static MOZ_MUST_USE bool staticAdjustInputs(TempAllocator& alloc,
--- a/js/src/threading/Thread.h
+++ b/js/src/threading/Thread.h
@@ -59,18 +59,17 @@ class Thread {
   // be created for this Thread by calling |init|. Some of the thread's
   // properties may be controlled by passing options to this constructor.
   template <
       typename O = Options,
       // SFINAE to make sure we don't try and treat functors for the other
       // constructor as an Options and vice versa.
       typename NonConstO = typename mozilla::RemoveConst<O>::Type,
       typename DerefO = typename mozilla::RemoveReference<NonConstO>::Type,
-      typename = typename mozilla::EnableIf<std::is_same_v<DerefO, Options>,
-                                            void*>::Type>
+      typename = std::enable_if_t<std::is_same_v<DerefO, Options>>>
   explicit Thread(O&& options = Options())
       : id_(ThreadId()), options_(std::forward<O>(options)) {
     MOZ_ASSERT(isInitialized());
   }
 
   // Start a thread of execution at functor |f| with parameters |args|. This
   // method will return false if thread creation fails. This Thread must not
   // already have been created. Note that the arguments must be either POD or
--- a/js/src/vm/JSContext-inl.h
+++ b/js/src/vm/JSContext-inl.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef vm_JSContext_inl_h
 #define vm_JSContext_inl_h
 
 #include "vm/JSContext.h"
 
 #include <type_traits>
+#include <utility>
 
 #include "builtin/Object.h"
 #include "gc/Zone.h"
 #include "jit/JitFrames.h"
 #include "proxy/Proxy.h"
 #include "util/DiagnosticAssertions.h"
 #include "vm/BigIntType.h"
 #include "vm/GlobalObject.h"
@@ -134,19 +135,18 @@ class ContextChecks {
     } else if (v.isBigInt()) {
       check(v.toBigInt(), argIndex);
     }
   }
 
   // Check the contents of any container class that supports the C++
   // iteration protocol, eg GCVector<jsid>.
   template <typename Container>
-  typename mozilla::EnableIf<
-      std::is_same_v<decltype(((Container*)nullptr)->begin()),
-                     decltype(((Container*)nullptr)->end())>>::Type
+  std::enable_if_t<std::is_same_v<decltype(std::declval<Container>().begin()),
+                                  decltype(std::declval<Container>().end())>>
   check(const Container& container, int argIndex) {
     for (auto i : container) {
       check(i, argIndex);
     }
   }
 
   void check(const JS::HandleValueArray& arr, int argIndex) {
     for (size_t i = 0; i < arr.length(); i++) {
--- a/js/src/vm/Xdr.h
+++ b/js/src/vm/Xdr.h
@@ -7,16 +7,18 @@
 #ifndef vm_Xdr_h
 #define vm_Xdr_h
 
 #include "mozilla/EndianUtils.h"
 #include "mozilla/MaybeOneOf.h"
 #include "mozilla/TypeTraits.h"
 #include "mozilla/Utf8.h"
 
+#include <type_traits>
+
 #include "jsapi.h"
 #include "jsfriendapi.h"
 #include "NamespaceImports.h"
 
 #include "js/CompileOptions.h"
 #include "js/Transcoding.h"
 #include "js/TypeDecls.h"
 #include "vm/JSAtom.h"
@@ -341,17 +343,17 @@ class XDRState : public XDRCoderBase {
   /*
    * Use SFINAE to refuse any specialization which is not an enum.  Uses of
    * this function do not have to specialize the type of the enumerated field
    * as C++ will extract the parameterized from the argument list.
    */
   template <typename T>
   XDRResult codeEnum32(
       T* val,
-      typename mozilla::EnableIf<mozilla::IsEnum<T>::value, T>::Type* = NULL) {
+      std::enable_if_t<mozilla::IsEnum<T>::value>* = nullptr) {
     // Mix the enumeration value with a random magic number, such that a
     // corruption with a low-ranged value (like 0) is less likely to cause a
     // miss-interpretation of the XDR content and instead cause a failure.
     const uint32_t MAGIC = 0x21AB218C;
     uint32_t tmp;
     if (mode == XDR_ENCODE) {
       tmp = uint32_t(*val) ^ MAGIC;
     }