[gjs: 2/6] jsapi-util-args: Improve template for free_if_necessary




commit 631fe19591f1a6a195a74191e1836996ff509b09
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri Jul 2 18:02:58 2021 -0700

    jsapi-util-args: Improve template for free_if_necessary
    
    The previous scheme with disabling the nonspecialized template for
    JS::RootedObject* was not necessary; instead we can define a
    specialization for JS::RootedObject* directly.

 gjs/jsapi-util-args.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
---
diff --git a/gjs/jsapi-util-args.h b/gjs/jsapi-util-args.h
index e80495ae..62843121 100644
--- a/gjs/jsapi-util-args.h
+++ b/gjs/jsapi-util-args.h
@@ -184,20 +184,15 @@ GJS_ALWAYS_INLINE static inline void assign(JSContext* cx, char c,
     assign(cx, c, nullable, value, (int *)ref);
 }
 
-/* Force JS::RootedObject * to be converted to JS::MutableHandleObject,
- * see overload in jsapi-util-args.cpp */
-template <typename T, typename std::enable_if_t<
-                          !std::is_same_v<T, JS::RootedObject*>, int> = 0>
+template <typename T>
 static inline void free_if_necessary(T param_ref [[maybe_unused]]) {}
 
 GJS_ALWAYS_INLINE
-static inline void
-free_if_necessary(JS::MutableHandleObject param_ref)
-{
+static inline void free_if_necessary(JS::RootedObject* param_ref) {
     /* This is not exactly right, since before we consumed a JS::ObjectValue
      * there may have been something different inside the handle. But it has
      * already been clobbered at this point anyhow */
-    param_ref.set(nullptr);
+    JS::MutableHandleObject(param_ref).set(nullptr);
 }
 
 template <typename T>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]