seed r144 - trunk/libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r144 - trunk/libseed
- Date: Thu, 6 Nov 2008 15:00:39 +0000 (UTC)
Author: racarr
Date: Thu Nov 6 15:00:39 2008
New Revision: 144
URL: http://svn.gnome.org/viewvc/seed?rev=144&view=rev
Log:
Implement subclassing (in a sense...). Fix reference counting once and
for all!
Modified:
trunk/libseed/seed-engine.c
trunk/libseed/seed-types.c
trunk/libseed/seed-types.h
Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c (original)
+++ trunk/libseed/seed-engine.c Thu Nov 6 15:00:39 2008
@@ -407,7 +407,8 @@
gobject = seed_value_to_object((JSValueRef) object, 0);
if (!gobject)
return;
-
+
+ g_object_remove_toggle_ref(gobject, seed_toggle_ref, 0);
g_object_unref(gobject);
}
Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c (original)
+++ trunk/libseed/seed-types.c Thu Nov 6 15:00:39 2008
@@ -37,6 +37,25 @@
return JSValueIsObjectOfClass(eng->context, value, gobject_class);
}
+void seed_toggle_ref(gpointer data,
+ GObject * object,
+ gboolean is_last_ref)
+{
+ JSValueRef wrapper;
+
+ wrapper = (JSValueRef)data;
+
+ if (is_last_ref)
+ {
+ JSValueUnprotect(eng->context, wrapper);
+ }
+ else
+ {
+ JSValueProtect(eng->context, wrapper);
+ }
+
+}
+
static SeedValue seed_wrap_object(GObject * object)
{
SeedValue user_data;
@@ -89,7 +108,14 @@
}
}
- object = g_object_ref_sink(object);
+ g_object_ref_sink(object);
+
+ g_object_set_data(object, "js-ref", (gpointer)js_ref);
+
+ JSValueProtect(eng->context, js_ref);
+ g_object_add_toggle_ref(object, seed_toggle_ref, (gpointer)js_ref);
+
+ g_object_unref(object);
return js_ref;
}
@@ -252,7 +278,7 @@
return FALSE;
}
- arg->v_pointer = g_object_ref(gobject);
+ arg->v_pointer = gobject;
break;
} else if (interface_type == GI_INFO_TYPE_ENUM ||
interface_type == GI_INFO_TYPE_FLAGS) {
@@ -1028,7 +1054,21 @@
GObject *gobject;
if (!seed_value_is_gobject(val)) {
- return NULL;
+ JSValueRef object;
+ if(!JSValueIsObject(eng->context, val))
+ return NULL;
+ object = seed_value_get_property(val, "gobject_parent");
+ if (val && object && JSValueIsObject(eng->context, object));
+ {
+ JSValueRef ref_data = 0;
+ gobject = seed_value_to_object(object, exception);
+ if (gobject)
+ {
+ g_object_set_data(gobject, "js-ref",
+ (gpointer)val);
+ }
+ return gobject;
+ }
}
gobject = (GObject *) JSObjectGetPrivate((JSObjectRef) val);
Modified: trunk/libseed/seed-types.h
==============================================================================
--- trunk/libseed/seed-types.h (original)
+++ trunk/libseed/seed-types.h Thu Nov 6 15:00:39 2008
@@ -76,4 +76,8 @@
GObject *seed_value_to_object(JSValueRef val, JSValueRef * exception);
JSValueRef seed_value_from_object(GObject * val, JSValueRef * exception);
+void seed_toggle_ref(gpointer data,
+ GObject * object,
+ gboolean is_last_ref);
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]