[gjs: 1/3] jsapi-util-string: Fix object logging



commit ef2172b73d1b035b3cb192c487a1c4f4fd0800ad
Author: Philip Chimento <philip chimento gmail com>
Date:   Tue May 15 22:17:00 2018 -0400

    jsapi-util-string: Fix object logging
    
    There were a bunch of places where the nonexistent gjs_debug_object() was
    called, but it didn't fail to build because they were in log statements
    that were ifdef'd out.

 gi/boxed.cpp              |  3 ++-
 gjs/jsapi-util-string.cpp | 13 ++++++++++---
 gjs/jsapi-util.h          |  2 ++
 3 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index cd020e44..69b221c7 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -120,7 +120,8 @@ boxed_resolve(JSContext       *context,
 {
     Boxed *priv = priv_from_js(context, obj);
     gjs_debug_jsprop(GJS_DEBUG_GBOXED, "Resolve prop '%s' hook, obj %s, priv %p",
-                     gjs_debug_id(id).c_str(), gjs_debug_obj(obj).c_str(), priv);
+                     gjs_debug_id(id).c_str(), gjs_debug_object(obj).c_str(),
+                     priv);
 
     if (priv == nullptr)
         return false; /* wrong class */
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index dc9777f0..2add8902 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -444,6 +444,15 @@ gjs_debug_symbol(JS::Symbol * const sym)
     return out.str();
 }
 
+std::string
+gjs_debug_object(JSObject * const obj)
+{
+    std::ostringstream out;
+    const JSClass* clasp = JS_GetClass(obj);
+    out << "<object " << clasp->name << " at " << obj <<  '>';
+    return out.str();
+}
+
 std::string
 gjs_debug_value(JS::Value v)
 {
@@ -479,9 +488,7 @@ gjs_debug_value(JS::Value v)
         return out.str();
     }
     if (v.isObject()) {
-        JSObject *obj = &v.toObject();
-        const JSClass* clasp = JS_GetClass(obj);
-        out << "<object " << clasp->name << " at " << obj <<  '>';
+        out << gjs_debug_object(&v.toObject());
         return out.str();
     }
     if (v.isBoolean())
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 869e962d..2474f3b8 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -25,6 +25,7 @@
 #define __GJS_JSAPI_UTIL_H__
 
 #include <memory>
+#include <string>
 #include <stdbool.h>
 
 #include <glib-object.h>
@@ -385,6 +386,7 @@ bool gjs_object_require_converted_property(JSContext       *cx,
 
 std::string gjs_debug_string(JSString *str);
 std::string gjs_debug_symbol(JS::Symbol * const sym);
+std::string gjs_debug_object(JSObject *obj);
 std::string gjs_debug_value(JS::Value v);
 std::string gjs_debug_id(jsid id);
 


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