[seed] Switch signal definition to use array of "signals" on GType definition.



commit b091b1bbd4ccbd36614ae661e258e2a94e307090
Author: Robert Carr <racarr svn gnome org>
Date:   Thu Apr 23 23:17:14 2009 -0400

    Switch signal definition to use array of "signals" on GType definition.
---
 libseed/seed-gtype.c                       |   85 ++++++++++++++++++++++++----
 tests/javascript/Makefile.am               |    1 -
 tests/javascript/gtype-signal-args.js      |   14 +---
 tests/javascript/gtype-signal-exception.js |   42 --------------
 tests/javascript/gtype-signal.js           |   18 +-----
 5 files changed, 82 insertions(+), 78 deletions(-)

diff --git a/libseed/seed-gtype.c b/libseed/seed-gtype.c
index 5852967..d6b477c 100644
--- a/libseed/seed-gtype.c
+++ b/libseed/seed-gtype.c
@@ -344,21 +344,78 @@ seed_gtype_install_signals (JSContextRef ctx,
   JSValueRef jslength;
   guint i, length;
   
-  signals = seed_object_get_property (ctx, definition, "signals");
+  signals = (JSObjectRef) seed_object_get_property (ctx, definition, "signals");
   if (JSValueIsNull(ctx, signals) || !JSValueIsObject (ctx, signals))
     return;
   
-  jslength = seed_object_get_property (ctx, definition, "length");
+  jslength = seed_object_get_property (ctx, signals, "length");
   if (JSValueIsNull (ctx, jslength))
     return;
   
   length = seed_value_to_uint (ctx, jslength, NULL);
   for (i = 0; i < length; i++)
     {
-      JSObjectRef signal = JSObjectGetPropertyAtIndex (ctx,
-						       (JSObjectRef) signals, 
-						       i,
-						       NULL);
+      GType return_type;
+      GType *param_types = NULL;
+      guint n_params = 0;
+      GSignalFlags flags;
+      JSValueRef jsname, jsflags, jsreturn_type, jsparams;
+      gchar *name;
+      JSObjectRef signal_def = (JSObjectRef)JSObjectGetPropertyAtIndex (ctx,
+									(JSObjectRef) signals, 
+									i,
+									NULL);
+      
+      if (JSValueIsNull (ctx, signal_def) || !JSValueIsObject(ctx, signal_def))
+	continue;
+
+      // TODO: Error checking
+      jsname = seed_object_get_property (ctx, signal_def, "name");
+      name = seed_value_to_string (ctx, jsname, NULL);
+      
+      SEED_NOTE(GTYPE, "Installing signal with name: %s on type: %s",
+		name, g_type_name (type));
+      
+      jsflags = seed_object_get_property (ctx, (JSObjectRef) signal_def, "flags");
+      if (JSValueIsNull (ctx, jsflags) || !JSValueIsNumber (ctx, jsflags))
+	flags = G_SIGNAL_RUN_LAST;
+      else
+	flags = seed_value_to_long (ctx, jsflags, NULL);
+      
+      jsreturn_type = seed_object_get_property (ctx, signal_def, "return_type");
+      if (JSValueIsNull (ctx, jsreturn_type) || !JSValueIsNumber (ctx, jsreturn_type))
+	return_type = G_TYPE_NONE;
+      else
+	return_type = seed_value_to_long (ctx, jsreturn_type, NULL);
+      
+      jsparams = seed_object_get_property (ctx, signal_def, "parameters");
+      
+      if (!JSValueIsNull (ctx, jsparams) && JSValueIsObject (ctx, jsparams))
+	{
+	  n_params = seed_value_to_int (ctx, seed_object_get_property (ctx, (JSObjectRef) jsparams, "length"), NULL);
+	  if (n_params > 0)
+	    {
+	      guint i;
+	      
+	      param_types = g_alloca (sizeof (GType)*n_params);
+	      for (i = 0; i < n_params; i++)
+		{
+		  JSValueRef ptype = JSObjectGetPropertyAtIndex (ctx,
+								 (JSObjectRef)
+								 jsparams,
+								 i,
+								 NULL);
+		  param_types[i] = (GType) seed_value_to_long (ctx, ptype, NULL);
+		}
+	    }
+	}
+
+      g_signal_newv (name, type,
+		     flags, 0, 0, 0,
+		     gi_cclosure_marshal_generic,
+		     return_type, n_params, param_types);
+      g_free (name);	  
+      
     }
   
 }
@@ -379,16 +436,22 @@ seed_gtype_class_init (gpointer g_class,
   ((GObjectClass *)g_class)->get_property = seed_gtype_get_property;
   ((GObjectClass *)g_class)->set_property = seed_gtype_set_property;
   ((GObjectClass *)g_class)->constructor = seed_gtype_construct;
-  
+
+  ctx = JSGlobalContextCreateInGroup (context_group, 0);
+
+  type = (GType) JSObjectGetPrivate (priv->constructor);
+  seed_gtype_install_signals (ctx, priv->definition, type);
+
   if (!priv->func)
-    return;
+    {
+      JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+      return;
+    }
   
-  ctx = JSGlobalContextCreateInGroup (context_group, 0);
+
   seed_prepare_global_context (ctx);
   
-  seed_gtype_install_signals (ctx, priv->definition, type);
     
-  type = (GType) JSObjectGetPrivate (priv->constructor);
   class_info = seed_get_class_info_for_type (type);
   
   jsargs[0] = seed_make_struct (ctx, g_class, class_info);
diff --git a/tests/javascript/Makefile.am b/tests/javascript/Makefile.am
index 7ec6cd2..83caa9b 100644
--- a/tests/javascript/Makefile.am
+++ b/tests/javascript/Makefile.am
@@ -21,7 +21,6 @@ EXTRA_DIST = \
     gtype.js \
     gtype-property.js \
     gtype-property-construct.js \
-    gtype-signal-exception.js \
     gtype-signal-args.js \
     gtype-signal.js \
     gtype-typerror.js \
diff --git a/tests/javascript/gtype-signal-args.js b/tests/javascript/gtype-signal-args.js
index d14a0cd..de1f0ce 100755
--- a/tests/javascript/gtype-signal-args.js
+++ b/tests/javascript/gtype-signal-args.js
@@ -11,15 +11,10 @@ Gtk.init(null, null);
 HelloWindow = new GType({
     parent: Gtk.Window.type,
     name: "HelloWindow",
-    class_init: function(klass, prototype)
-    {
-        var HelloSignalDefinition = {name: "hello",
-                                     parameters: [GObject.TYPE_INT,
-                                                  GObject.TYPE_STRING],
-                                     return_type: Gtk.Window.type};
-
-        hello_signal_id = klass.install_signal(HelloSignalDefinition);
-    }
+    signals: [{name: "hello",
+	       parameters: [GObject.TYPE_INT,
+			    GObject.TYPE_STRING],
+	       return_type: Gtk.Window.type}]
 });
 
 w = new HelloWindow();
@@ -30,6 +25,5 @@ w.signal.hello.connect(function(object, number, string)
                            Seed.print(number + " " + string);
                            return win;
                        });
-
 Seed.print(w.signal.hello.emit(2, "Test"));
 
diff --git a/tests/javascript/gtype-signal-exception.js b/tests/javascript/gtype-signal-exception.js
deleted file mode 100755
index dac0a62..0000000
--- a/tests/javascript/gtype-signal-exception.js
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env seed
-// Returns: 0
-// STDIN:
-// STDOUT:Signal definition needs name property\nSignal definition needs name property
-// STDERR:
-
-Gtk = imports.gi.Gtk;
-Gtk.init(null, null);
-
-HelloWindowType = {       
-    parent: Gtk.Window.type,
-    name: "HelloWindow",
-    class_init: function(klass, prototype)
-    {
-	var HelloSignalDefinition = {};
-	var GoodbyeSignalDefinition = {name: 3};
-	
-	try {
-		hello_signal_id = klass.install_signal(HelloSignalDefinition);
-	    }
-	catch (e){
-		Seed.print(e.message);
-	    }
-	try
-	    {
-		goodbye_signal_id = klass.install_signal(GoodbyeSignalDefinition);
-		hello_signal_id = klass.install_signal(HelloSignalDefinition);
-	    }
-	catch (e)
-	    {
-		Seed.print(e.message);
-	}
-
-    },
-    init: function(klass)
-    {
-    }};
-
-HelloWindow = new GType(HelloWindowType);
-w = new HelloWindow();
-
-	  
diff --git a/tests/javascript/gtype-signal.js b/tests/javascript/gtype-signal.js
index 005a587..e1d8e6a 100755
--- a/tests/javascript/gtype-signal.js
+++ b/tests/javascript/gtype-signal.js
@@ -7,21 +7,11 @@
 Gtk = imports.gi.Gtk;
 Gtk.init(null, null);
 
-HelloWindowType = {       
+HelloWindowType = {
     parent: Gtk.Window.type,
     name: "HelloWindow",
-    class_init: function(klass, prototype)
-    {
-	var HelloSignalDefinition = {name: "hello"};
-	var GoodbyeSignalDefinition = {name: "goodbye"};
-	
-	
-	hello_signal_id = klass.install_signal(HelloSignalDefinition);
-	goodbye_signal_id = klass.install_signal(GoodbyeSignalDefinition);
-    },
-    init: function(instance)
-    {
-    }};
+    signals: [{name: "hello"}, {name: "goodbye"}]
+};
 
 HelloWindow = new GType(HelloWindowType);
 w = new HelloWindow();
@@ -31,4 +21,4 @@ w.signal.goodbye.connect(function(){Seed.print("Goodbye");});
 
 w.signal.hello.emit();
 w.signal.goodbye.emit();
-	  
+



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