[gjs: 7/8] jsapi-util: initialize typeclass by gtype



commit fa61d3667c2e83ea10dbd8f34160feb5b6d45c6a
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Oct 9 07:30:14 2018 +0200

    jsapi-util: initialize typeclass by gtype

 gi/arg.cpp       | 2 +-
 gi/gerror.cpp    | 2 +-
 gi/object.cpp    | 4 ++--
 gi/private.cpp   | 2 +-
 gi/value.cpp     | 2 +-
 gjs/jsapi-util.h | 2 ++
 6 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 96cb7e5b..35965ad2 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -53,7 +53,7 @@ _gjs_flags_value_is_valid(JSContext   *context,
     if (gtype == G_TYPE_NONE)
         return true;
 
-    GjsAutoTypeClass<GTypeClass> klass = g_type_class_ref(gtype);
+    GjsAutoTypeClass<GTypeClass> klass(gtype);
 
     /* check all bits are defined for flags.. not necessarily desired */
     tmpval = (guint32)value;
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index 7150cf67..7f04e8d4 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -575,7 +575,7 @@ gjs_gerror_make_from_error(JSContext       *cx,
     if (!gjs_string_to_utf8(cx, v_message, &message))
         return nullptr;
 
-    GjsAutoTypeClass<GEnumClass> klass = g_type_class_ref(GJS_TYPE_JS_ERROR);
+    GjsAutoTypeClass<GEnumClass> klass(GJS_TYPE_JS_ERROR);
     const GEnumValue *value = g_enum_get_value_by_name(klass, name);
     int code;
     if (value)
diff --git a/gi/object.cpp b/gi/object.cpp
index c1f70086..8ca4bc90 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -284,7 +284,7 @@ GParamSpec* ObjectPrototype::find_param_spec_from_id(JSContext* cx,
         return nullptr;
 
     GjsAutoChar gname = gjs_hyphen_from_camel(js_prop_name);
-    GjsAutoTypeClass<GObjectClass> gobj_class = g_type_class_ref(m_gtype);
+    GjsAutoTypeClass<GObjectClass> gobj_class(m_gtype);
     GParamSpec* pspec = g_object_class_find_property(gobj_class, gname);
     GjsAutoParam param_spec(pspec, GjsAutoParam::TakeOwnership());
 
@@ -2400,7 +2400,7 @@ find_vfunc_info (JSContext *context,
 
     is_interface = g_base_info_get_type(ancestor_info) == GI_INFO_TYPE_INTERFACE;
 
-    GjsAutoTypeClass<void> implementor_class = g_type_class_ref(implementor_gtype);
+    GjsAutoTypeClass<void> implementor_class(implementor_gtype);
     if (is_interface) {
         GTypeInstance *implementor_iface_class;
         implementor_iface_class = (GTypeInstance*) g_type_interface_peek(implementor_class,
diff --git a/gi/private.cpp b/gi/private.cpp
index bbfbd8d4..7a852ddc 100644
--- a/gi/private.cpp
+++ b/gi/private.cpp
@@ -63,7 +63,7 @@ static bool gjs_override_property(JSContext* cx, unsigned argc, JS::Value* vp) {
         pspec = g_object_interface_find_property(interface_type, name);
         g_type_default_interface_unref(interface_type);
     } else {
-        GjsAutoTypeClass<GObjectClass> class_type = g_type_class_ref(gtype);
+        GjsAutoTypeClass<GObjectClass> class_type(gtype);
         pspec = g_object_class_find_property(class_type, name);
     }
 
diff --git a/gi/value.cpp b/gi/value.cpp
index bc265763..4cf4ae4e 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -598,7 +598,7 @@ gjs_value_to_g_value_internal(JSContext      *context,
 
         if (JS::ToInt64(context, value, &value_int64)) {
             GEnumValue *v;
-            GjsAutoTypeClass<GEnumClass> enum_class = g_type_class_ref(gtype);
+            GjsAutoTypeClass<GEnumClass> enum_class(gtype);
 
             /* See arg.c:_gjs_enum_to_int() */
             v = g_enum_get_value(enum_class, (int)value_int64);
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 81623b38..f206ddfe 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -71,6 +71,8 @@ class GjsAutoTypeClass : public std::unique_ptr<T, decltype(&g_type_class_unref)
 public:
     GjsAutoTypeClass(gpointer ptr = nullptr)
         : GjsAutoTypeClass::unique_ptr(static_cast<T*>(ptr), g_type_class_unref) {}
+    explicit GjsAutoTypeClass(GType gtype)
+        : GjsAutoTypeClass(g_type_class_ref(gtype)) {}
 
     operator T *() const { return GjsAutoTypeClass::unique_ptr::get(); }
 


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