[gjs/wip/gobj-kitchen-sink: 8/21] lang: Add helper "pointer_string" method for debugging



commit 5de7bf6492237eff286f10a0c397f35c8f331c67
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Nov 6 03:20:09 2011 -0500

    lang: Add helper "pointer_string" method for debugging
    
    https://bugzilla.gnome.org/show_bug.cgi?id=663492

 modules/lang.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/modules/lang.c b/modules/lang.c
index 6135745..cb97e93 100644
--- a/modules/lang.c
+++ b/modules/lang.c
@@ -50,6 +50,28 @@ gjs_lang_seal(JSContext *cx,
     return JS_TRUE;
 }
 
+static JSBool
+gjs_pointer_string(JSContext *cx,
+                   uintN      argc,
+                   jsval     *vp)
+{
+    jsval *argv = JS_ARGV(cx, vp);
+    gchar *strval;
+    jsval retval;
+    JSBool ret;
+    JSObject *ptr;
+
+    ptr = JSVAL_TO_OBJECT(argv[0]);
+
+    strval = g_strdup_printf("%p", ptr);
+
+    ret = gjs_string_from_utf8(cx, strval, -1, &retval);
+    if (ret)
+        JS_SET_RVAL(context, vp, retval);
+    g_free(strval);
+    return ret;
+}
+
 JSBool
 gjs_define_lang_stuff(JSContext      *context,
                       JSObject      *module_obj)
@@ -60,6 +82,12 @@ gjs_define_lang_stuff(JSContext      *context,
                            1, GJS_MODULE_PROP_FLAGS))
         return JS_FALSE;
 
+    if (!JS_DefineFunction(context, module_obj,
+                           "pointer_string",
+                           (JSNative)gjs_pointer_string,
+                           1, GJS_MODULE_PROP_FLAGS))
+        return JS_FALSE;
+
     return JS_TRUE;
 }
 



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