[seed] libseed: Separate the logic to make a wrapper for a given GObject type, out from the logic to make a



commit fd7178be8030892cffeb1fc257de47e6de3d5c51
Author: Robert Carr <racarr svn gnome org>
Date:   Thu May 21 13:18:49 2009 -0400

    libseed: Separate the logic to make a wrapper for a given GObject type, out from the logic to make a wrapper for a specific object. This is necessary to be able to make the wrapper, before the call to g_object_newv, which will be required to see custom properties in init ha ndlers
---
 libseed/seed-types.c |   41 ++++++++++++++++++++++++-----------------
 libseed/seed-types.h |    2 ++
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index 3fe181b..123048e 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -59,14 +59,34 @@ seed_gobject_destroyed (gpointer object)
   JSObjectSetPrivate ((JSObjectRef) object, 0);
 }
 
+JSObjectRef
+seed_make_wrapper_for_type (JSContextRef ctx, GType type)
+{
+  JSClassRef class;
+  JSObjectRef ret;
+  JSValueRef prototype;
+  
+  class = seed_gobject_get_class_for_gtype (ctx, type);
+  
+  while (!class && (type = g_type_parent (type)))
+    class = seed_gobject_get_class_for_gtype (ctx, type);
+  
+  prototype = seed_gobject_get_prototype_for_gtype (type);
+  ret = JSObjectMake (ctx, class, NULL);
+  if (prototype)
+    JSObjectSetPrototype (ctx, ret, prototype);
+  else
+    g_assert_not_reached();
+  
+  return ret;
+}
+
 static JSValueRef
 seed_wrap_object (JSContextRef ctx, GObject * object)
 {
   JSValueRef user_data;
   JSObjectRef js_ref;
-  JSClassRef class;
   GType type;
-  JSValueRef prototype;
 
   type = G_OBJECT_TYPE (object);
 
@@ -75,21 +95,8 @@ seed_wrap_object (JSContextRef ctx, GObject * object)
   if (user_data)
     return user_data;
 
-  class = seed_gobject_get_class_for_gtype (ctx, type);
-
-  while (!class && (type = g_type_parent (type)))
-    {
-      class = seed_gobject_get_class_for_gtype (ctx, type);
-    }
-
-  prototype = seed_gobject_get_prototype_for_gtype (type);
-  js_ref = JSObjectMake (ctx, class, object);
-  if (prototype)
-    JSObjectSetPrototype (ctx, (JSObjectRef) js_ref, prototype);
-  else
-    {
-      g_assert_not_reached ();
-    }
+  js_ref = seed_make_wrapper_for_type (ctx, type);
+  JSObjectSetPrivate (js_ref, object);
 
   g_object_set_qdata_full (object, js_ref_quark, (gpointer) js_ref,
 			  seed_gobject_destroyed);
diff --git a/libseed/seed-types.h b/libseed/seed-types.h
index 1940123..79b9d76 100644
--- a/libseed/seed-types.h
+++ b/libseed/seed-types.h
@@ -150,4 +150,6 @@ seed_value_from_binary_string (JSContextRef ctx,
 			       gint n_bytes,
 			       JSValueRef *exception);
 
+JSObjectRef seed_make_wrapper_for_type (JSContextRef ctx, GType type);
+
 #endif



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