[gjs: 13/18] wrapperutils: Remove to_string_kind()




commit ed3958a0c1c64ef68d16579abeca6a7947e0549e
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Nov 28 20:27:15 2020 -0800

    wrapperutils: Remove to_string_kind()
    
    None of the classes except ObjectInstance ever need to display a string
    tag in toString() that isn't a constexpr. Just use DEBUG_TAG for this
    purpose, and let ObjectBase override toString() as it already does.

 gi/boxed.h        |  4 +---
 gi/fundamental.h  |  4 ----
 gi/interface.h    |  4 +---
 gi/object.cpp     | 17 ++++++-----------
 gi/object.h       |  1 -
 gi/union.h        |  2 --
 gi/wrapperutils.h |  6 +++---
 7 files changed, 11 insertions(+), 27 deletions(-)
---
diff --git a/gi/boxed.h b/gi/boxed.h
index ccad2b2b..2fd05ab7 100644
--- a/gi/boxed.h
+++ b/gi/boxed.h
@@ -51,7 +51,7 @@ class BoxedBase
         : GIWrapperBase(proto) {}
 
     static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_GBOXED;
-    static constexpr const char* DEBUG_TAG = "GBoxed";
+    static constexpr const char* DEBUG_TAG = "boxed";
 
     static const struct JSClassOps class_ops;
     static const struct JSClass klass;
@@ -65,8 +65,6 @@ class BoxedBase
 
     // Helper methods that work on either instances or prototypes
 
-    [[nodiscard]] const char* to_string_kind() const { return "boxed"; }
-
     GJS_JSAPI_RETURN_CONVENTION
     GIFieldInfo* get_field_info(JSContext* cx, uint32_t id) const;
 
diff --git a/gi/fundamental.h b/gi/fundamental.h
index c2f4bf65..aa8f0762 100644
--- a/gi/fundamental.h
+++ b/gi/fundamental.h
@@ -44,10 +44,6 @@ class FundamentalBase
     static const struct JSClassOps class_ops;
     static const struct JSClass klass;
 
-    // Helper methods
-
-    [[nodiscard]] const char* to_string_kind() const { return "fundamental"; }
-
     // Public API
 
  public:
diff --git a/gi/interface.h b/gi/interface.h
index 24448494..b3ddaecf 100644
--- a/gi/interface.h
+++ b/gi/interface.h
@@ -47,14 +47,12 @@ class InterfaceBase : public GIWrapperBase<InterfaceBase, InterfacePrototype,
         : GIWrapperBase(proto) {}
 
     static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_GINTERFACE;
-    static constexpr const char* DEBUG_TAG = "GInterface";
+    static constexpr const char* DEBUG_TAG = "interface";
 
     static const struct JSClassOps class_ops;
     static const struct JSClass klass;
     static JSFunctionSpec static_methods[];
 
-    [[nodiscard]] const char* to_string_kind(void) const { return "interface"; }
-
     // JSNative methods
 
     // Overrides GIWrapperBase::constructor().
diff --git a/gi/object.cpp b/gi/object.cpp
index 653fc093..f8323bb0 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2182,25 +2182,20 @@ bool ObjectInstance::signals_action_impl(JSContext* cx,
 
 bool ObjectBase::to_string(JSContext* cx, unsigned argc, JS::Value* vp) {
     GJS_GET_WRAPPER_PRIV(cx, argc, vp, args, obj, ObjectBase, priv);
+    const char* kind = ObjectBase::DEBUG_TAG;
+    if (!priv->is_prototype())
+        kind = priv->to_instance()->to_string_kind();
     return gjs_wrapper_to_string_func(
-        cx, obj, priv->to_string_kind(), priv->info(), priv->gtype(),
+        cx, obj, kind, priv->info(), priv->gtype(),
         priv->is_prototype() ? nullptr : priv->to_instance()->ptr(),
         args.rval());
 }
 
-// Override of GIWrapperBase::to_string_kind()
-const char* ObjectBase::to_string_kind(void) const {
-    if (is_prototype())
-        return "object";
-    return to_instance()->to_string_kind();
-}
-
 /*
  * ObjectInstance::to_string_kind:
  *
- * Instance-only version of GIWrapperBase::to_string_kind(). ObjectInstance
- * shows a "finalized" marker in its toString() method if the wrapped GObject
- * has already been finalized.
+ * ObjectInstance shows a "finalized" marker in its toString() method if the
+ * wrapped GObject has already been finalized.
  */
 const char* ObjectInstance::to_string_kind(void) const {
     return m_gobj_disposed ? "object (FINALIZED)" : "object";
diff --git a/gi/object.h b/gi/object.h
index 2467fc40..d3f1ebf5 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -168,7 +168,6 @@ class ObjectBase
                                                            JS::Value* vp);
     GJS_JSAPI_RETURN_CONVENTION
     static bool to_string(JSContext* cx, unsigned argc, JS::Value* vp);
-    [[nodiscard]] const char* to_string_kind() const;
     GJS_JSAPI_RETURN_CONVENTION
     static bool init_gobject(JSContext* cx, unsigned argc, JS::Value* vp);
     GJS_JSAPI_RETURN_CONVENTION
diff --git a/gi/union.h b/gi/union.h
index cefcff66..71faf5ba 100644
--- a/gi/union.h
+++ b/gi/union.h
@@ -37,8 +37,6 @@ class UnionBase
 
     static const JSClassOps class_ops;
     static const JSClass klass;
-
-    [[nodiscard]] static const char* to_string_kind(void) { return "union"; }
 };
 
 class UnionPrototype : public GIWrapperPrototype<UnionBase, UnionPrototype,
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index 3146b210..05b34499 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -532,9 +532,9 @@ class GIWrapperBase {
     GJS_JSAPI_RETURN_CONVENTION
     static bool to_string(JSContext* cx, unsigned argc, JS::Value* vp) {
         GJS_GET_WRAPPER_PRIV(cx, argc, vp, args, obj, Base, priv);
-        return gjs_wrapper_to_string_func(
-            cx, obj, static_cast<const Base*>(priv)->to_string_kind(),
-            priv->info(), priv->gtype(), priv->ptr_addr(), args.rval());
+        return gjs_wrapper_to_string_func(cx, obj, Base::DEBUG_TAG,
+                                          priv->info(), priv->gtype(),
+                                          priv->ptr_addr(), args.rval());
     }
 
     // Helper methods


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