[gjs] system: Add a debugger function to retrieve the refcount of a GObject



commit a1ce1b02e2f2c58894935e9246589456aaf9ac18
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue May 15 16:21:59 2012 -0300

    system: Add a debugger function to retrieve the refcount of a GObject

 modules/system.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/modules/system.c b/modules/system.c
index c7c5b5c..60b9cce 100644
--- a/modules/system.c
+++ b/modules/system.c
@@ -28,6 +28,7 @@
 #include <unistd.h>
 
 #include <gjs/gjs-module.h>
+#include <gi/object.h>
 #include <jsapi.h>
 
 #include "system.h"
@@ -56,6 +57,29 @@ gjs_address_of(JSContext *context,
 }
 
 static JSBool
+gjs_refcount(JSContext *context,
+             uintN      argc,
+             jsval     *vp)
+{
+    jsval *argv = JS_ARGV(cx, vp);
+    jsval retval;
+    JSObject *target_obj;
+    GObject *obj;
+
+    if (!gjs_parse_args(context, "refcount", "o", argc, argv, "object", &target_obj))
+        return JS_FALSE;
+
+    obj = gjs_g_object_from_object(context, target_obj);
+
+    if (obj == NULL)
+        return JS_FALSE;
+
+    retval = INT_TO_JSVAL(obj->ref_count);
+    JS_SET_RVAL(context, vp, retval);
+    return JS_TRUE;
+}
+
+static JSBool
 gjs_breakpoint(JSContext *context,
                uintN      argc,
                jsval     *vp)
@@ -132,6 +156,12 @@ gjs_js_define_system_stuff(JSContext *context,
         return JS_FALSE;
 
     if (!JS_DefineFunction(context, module,
+                           "refcount",
+                           (JSNative) gjs_refcount,
+                           1, GJS_MODULE_PROP_FLAGS))
+        return JS_FALSE;
+
+    if (!JS_DefineFunction(context, module,
                            "breakpoint",
                            (JSNative) gjs_breakpoint,
                            0, GJS_MODULE_PROP_FLAGS))



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