[seed] libseed: seed_gobject_init_method_invoked should support non argv class arrays by copying
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] libseed: seed_gobject_init_method_invoked should support non argv class arrays by copying
- Date: Sun, 24 May 2009 17:43:16 -0400 (EDT)
commit cd1dd4f20e8fa7e76b5d1ae04237e64ed3e2312e
Author: Robert Carr <racarr svn gnome org>
Date: Sat May 23 21:11:55 2009 -0400
libseed: seed_gobject_init_method_invoked should support non argv class arrays by copying
---
ChangeLog | 4 ++-
libseed/seed-engine.c | 63 ++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 60 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 65c5b61..d5d73e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,10 @@
-== Seed 0.8, "Third Stage" (2009.05.27) ==
+== Seed 0.8, "Bringing It All Back Home" (2009.05.27) ==
* Importer now supports constructing directory objects, to avoid manipulation of search path.
Importer directory objects now support property enumeration.
* Fix small leak in GObject wrapper initialization. (and also simplify the process).
* GtkBuilder module to handle GtkBuilder automatic signal connection.
+* *_init methods now take normal arrays (by value) in addition to the special Seed.argv array.
+* GObject constructors (init methods) now take "self" as a parameter.
* Module documentation rewritten in docbook, and builds one nice manual.
* New Cairo module, supports most of the cairo API, with automatic memory management
and everything you would expect.
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 069f30a..97bf6b5 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -308,6 +308,34 @@ seed_gobject_method_finalize (JSObjectRef method)
typedef void (*InitMethodCallback) (gint *argc, gchar ***argv);
+static gboolean
+seed_gobject_init_build_argv (JSContextRef ctx,
+ JSObjectRef array,
+ SeedArgvPrivates *priv,
+ JSValueRef *exception)
+{
+ guint i,length;
+ JSValueRef jsl;
+
+ jsl = seed_object_get_property (ctx, array, "length");
+ if (JSValueIsNull (ctx, jsl) || JSValueIsUndefined (ctx, jsl))
+ return FALSE;
+
+ length = seed_value_to_uint (ctx, jsl, exception);
+ priv->argv = g_new(gchar *, length);
+ priv->argc = length;
+
+ for (i = 0; i < length; i++)
+ {
+ priv->argv[i] = seed_value_to_string (ctx,
+ JSObjectGetPropertyAtIndex (ctx, array, i,
+ exception),
+ exception);
+ }
+ return TRUE;
+
+}
+
static JSValueRef
seed_gobject_init_method_invoked (JSContextRef ctx,
JSObjectRef function,
@@ -320,6 +348,8 @@ seed_gobject_init_method_invoked (JSContextRef ctx,
GTypelib *typelib;
InitMethodCallback c;
SeedArgvPrivates *priv;
+ gboolean allocated = FALSE;
+
if (argumentCount != 1 && argumentCount != 2)
{
seed_make_exception (ctx, exception,
@@ -328,14 +358,33 @@ seed_gobject_init_method_invoked (JSContextRef ctx,
return JSValueMakeUndefined (ctx);
}
- // TODO: In future support all arrays.Through a seperate code path.
- if (!argumentCount == 2)
+ if (argumentCount ==1)
{
- if (JSValueIsNull (ctx, arguments[0]) || !JSValueIsObject (ctx, arguments[0]) ||
- !JSValueIsObjectOfClass (ctx, arguments[0], seed_argv_class))
+ if (JSValueIsNull (ctx, arguments[0]) || !JSValueIsObject (ctx, arguments[0]))
+
{
seed_make_exception (ctx, exception,
- "ArgumentError", "init method expects an argv object as argument");
+ "ArgumentError", "init method expects an array object as argument");
+ return JSValueMakeUndefined (ctx);
+ }
+ if(JSValueIsObjectOfClass (ctx, arguments[0], seed_argv_class))
+ {
+ priv = JSObjectGetPrivate ((JSObjectRef)arguments[0]);
+ }
+ else
+ {
+ priv = g_newa (SeedArgvPrivates,1);
+ if (!seed_gobject_init_build_argv (ctx,
+ (JSObjectRef)arguments[0],
+ priv,
+ exception))
+ {
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "Init method expects an array as argument");
+ return JSValueMakeUndefined (ctx);
+
+ }
+ allocated = TRUE;
}
}
@@ -349,8 +398,10 @@ seed_gobject_init_method_invoked (JSContextRef ctx,
return JSValueMakeUndefined (ctx);
}
- priv = JSObjectGetPrivate ((JSObjectRef)arguments[0]);
c(&priv->argc, &priv->argv);
+
+ if (allocated)
+ g_free (priv->argv);
return JSValueMakeUndefined (ctx);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]