seed r126 - trunk/libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r126 - trunk/libseed
- Date: Wed, 5 Nov 2008 12:07:29 +0000 (UTC)
Author: racarr
Date: Wed Nov 5 12:07:29 2008
New Revision: 126
URL: http://svn.gnome.org/viewvc/seed?rev=126&view=rev
Log:
Rename SeedClosurePrivates to SeedNativeClosure. Move SeedClosure into
seed-closure.h. Add auto-conversion of function->SeedClosure in case
where function expects a type of GClosure.
Modified:
trunk/libseed/seed-builtins.c
trunk/libseed/seed-closure.c
trunk/libseed/seed-closure.h
trunk/libseed/seed-signals.h
trunk/libseed/seed-types.c
Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c (original)
+++ trunk/libseed/seed-builtins.c Wed Nov 5 12:07:29 2008
@@ -310,7 +310,7 @@
size_t argumentCount,
const JSValueRef arguments[], JSValueRef * exception)
{
- GClosure * closure;
+ SeedClosure * closure;
if (argumentCount < 1 || argumentCount > 2)
{
@@ -322,19 +322,11 @@
return JSValueMakeNull(ctx);
}
- closure = g_closure_new_simple(sizeof(SeedClosure), 0);
- g_closure_set_marshal(closure, seed_signal_marshal_func);
-
- ((SeedClosure *) closure)->function = (JSObjectRef) arguments[0];
- ((SeedClosure *) closure)->object =
- 0;
- if (argumentCount == 2 && !JSValueIsNull(eng->context, arguments[1])) {
- JSValueProtect(eng->context, (JSObjectRef) arguments[1]);
- ((SeedClosure *) closure)->this = (JSObjectRef) arguments[1];
- } else
- ((SeedClosure *) closure)->this = 0;
-
- JSValueProtect(eng->context, (JSObjectRef) arguments[0]);
+ if (argumentCount == 2)
+ closure = seed_make_gclosure((JSObjectRef)arguments[0], (JSObjectRef)arguments[1]);
+ else
+ closure = seed_make_gclosure((JSObjectRef)arguments[0], 0);
+
return (JSValueRef)seed_make_struct(closure, 0);
}
@@ -356,7 +348,7 @@
GITypeInfo * return_type;
GIArgInfo * arg_info;
gint num_args, i;
- SeedClosurePrivates * privates;
+ SeedNativeClosure * privates;
if (argumentCount != 2)
{
@@ -373,7 +365,7 @@
info = (GICallableInfo *)
JSObjectGetPrivate((JSObjectRef)arguments[1]);
- privates = seed_make_closure(info, arguments[0]);
+ privates = seed_make_native_closure(info, arguments[0]);
return JSObjectMake(eng->context, seed_native_callback_class, privates);
}
Modified: trunk/libseed/seed-closure.c
==============================================================================
--- trunk/libseed/seed-closure.c (original)
+++ trunk/libseed/seed-closure.c Wed Nov 5 12:07:29 2008
@@ -100,8 +100,8 @@
static void seed_closure_finalize(JSObjectRef object)
{
- SeedClosurePrivates * privates =
- (SeedClosurePrivates*)JSObjectGetPrivate(object);
+ SeedNativeClosure * privates =
+ (SeedNativeClosure*)JSObjectGetPrivate(object);
g_free(privates->cif->arg_types);
g_free(privates->cif);
@@ -115,7 +115,7 @@
void ** args,
void * userdata)
{
- SeedClosurePrivates * privates = userdata;
+ SeedNativeClosure * privates = userdata;
int num_args, i;
JSValueRef * jsargs;
JSValueRef return_value;
@@ -310,7 +310,7 @@
}
-SeedClosurePrivates * seed_make_closure(GICallableInfo * info,
+SeedNativeClosure * seed_make_native_closure(GICallableInfo * info,
JSValueRef function)
{
ffi_cif * cif;
@@ -321,7 +321,7 @@
GITypeInfo * return_type;
GIArgInfo * arg_info;
gint num_args, i;
- SeedClosurePrivates * privates;
+ SeedNativeClosure * privates;
num_args = g_callable_info_get_n_args(info);
@@ -329,7 +329,7 @@
arg_types = (ffi_type **)g_new0(ffi_type, num_args+1);
cif = g_new0(ffi_cif, 1);
- privates = g_new0(SeedClosurePrivates, 1);
+ privates = g_new0(SeedNativeClosure, 1);
privates->info = info;
privates->function = function;
privates->cif = cif;
@@ -355,6 +355,27 @@
return privates;
}
+SeedClosure * seed_make_gclosure(JSObjectRef function,
+ JSObjectRef this)
+{
+ GClosure * closure;
+
+ closure = g_closure_new_simple(sizeof(SeedClosure), 0);
+ g_closure_set_marshal(closure, seed_signal_marshal_func);
+
+ ((SeedClosure *) closure)->function = function;
+ ((SeedClosure *) closure)->object = 0;
+ if (this && !JSValueIsNull(eng->context, this)){
+ JSValueProtect(eng->context, this);
+ ((SeedClosure *) closure)->this = this;
+ } else
+ ((SeedClosure *) closure)->this = 0;
+
+ JSValueProtect(eng->context, function);
+
+ return (SeedClosure *)closure;
+}
+
JSClassDefinition seed_native_callback_def = {
0, /* Version, always 0 */
0,
Modified: trunk/libseed/seed-closure.h
==============================================================================
--- trunk/libseed/seed-closure.h (original)
+++ trunk/libseed/seed-closure.h Wed Nov 5 12:07:29 2008
@@ -21,19 +21,29 @@
#include "seed-private.h"
-typedef struct _SeedClosurePrivates
+typedef struct _SeedClosure {
+ GClosure closure;
+ JSObjectRef function;
+ JSObjectRef object;
+ JSObjectRef this;
+} SeedClosure;
+
+typedef struct _SeedNativeClosure
{
GICallableInfo * info;
JSValueRef function;
ffi_closure * closure;
ffi_cif * cif;
-} SeedClosurePrivates;
+} SeedNativeClosure;
extern JSClassRef seed_native_callback_class;
-SeedClosurePrivates * seed_make_closure(GICallableInfo * info,
+SeedNativeClosure * seed_make_native_closure(GICallableInfo * info,
JSValueRef function);
+SeedClosure * seed_make_gclosure(JSObjectRef function,
+ JSObjectRef this);
+
void seed_closures_init();
#endif
Modified: trunk/libseed/seed-signals.h
==============================================================================
--- trunk/libseed/seed-signals.h (original)
+++ trunk/libseed/seed-signals.h Wed Nov 5 12:07:29 2008
@@ -22,13 +22,6 @@
#include "seed-private.h"
-typedef struct _SeedClosure {
- GClosure closure;
- JSObjectRef function;
- JSObjectRef object;
- JSObjectRef this;
-} SeedClosure;
-
void
seed_signal_marshal_func(GClosure * closure,
GValue * return_value,
Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c (original)
+++ trunk/libseed/seed-types.c Wed Nov 5 12:07:29 2008
@@ -258,7 +258,21 @@
value, NULL);
break;
} else if (interface_type == GI_INFO_TYPE_STRUCT) {
- arg->v_pointer = seed_struct_get_pointer(value);
+ if (JSValueIsObjectOfClass(eng->context, value, gobject_method_class))
+ arg->v_pointer = seed_struct_get_pointer(value);
+ else
+ {
+ GType type = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*)interface);
+ if (!type)
+ return FALSE;
+ else if (g_type_is_a(type, G_TYPE_CLOSURE))
+ {
+ if (JSObjectIsFunction(eng->context, (JSObjectRef)value))
+ {
+ arg->v_pointer = seed_make_gclosure((JSObjectRef)value, 0);
+ }
+ }
+ }
break;
} else if (interface_type == GI_INFO_TYPE_CALLBACK) {
if (JSValueIsObjectOfClass(eng->context,
@@ -283,8 +297,8 @@
else if (JSValueIsObjectOfClass(eng->context,
value, seed_native_callback_class))
{
- SeedClosurePrivates * privates =
- (SeedClosurePrivates*)
+ SeedNativeClosure * privates =
+ (SeedNativeClosure*)
JSObjectGetPrivate((JSObjectRef)value);
arg->v_pointer = privates->closure;
break;
@@ -292,8 +306,9 @@
else if (JSObjectIsFunction(eng->context,
(JSObjectRef)value))
{
- SeedClosurePrivates * privates =
- seed_make_closure((GICallableInfo*)interface, value);
+ SeedNativeClosure * privates =
+ seed_make_native_closure(
+ (GICallableInfo*)interface, value);
arg->v_pointer = privates->closure;
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]