seed r353 - trunk/libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r353 - trunk/libseed
- Date: Wed, 26 Nov 2008 00:59:00 +0000 (UTC)
Author: racarr
Date: Wed Nov 26 00:59:00 2008
New Revision: 353
URL: http://svn.gnome.org/viewvc/seed?rev=353&view=rev
Log:
More global context rework. Add context group. Custom context for signals.
Modified:
trunk/libseed/seed-api.c
trunk/libseed/seed-builtins.c
trunk/libseed/seed-closure.c
trunk/libseed/seed-closure.h
trunk/libseed/seed-engine.c
trunk/libseed/seed-engine.h
trunk/libseed/seed-exceptions.c
trunk/libseed/seed-gtype.c
trunk/libseed/seed-gtype.h
trunk/libseed/seed-signals.c
trunk/libseed/seed-structs.c
trunk/libseed/seed-types.c
trunk/libseed/seed-types.h
trunk/libseed/seed.h
Modified: trunk/libseed/seed-api.c
==============================================================================
--- trunk/libseed/seed-api.c (original)
+++ trunk/libseed/seed-api.c Wed Nov 26 00:59:00 2008
@@ -22,7 +22,7 @@
}
ret->line_number = line_number;
- JSCheckScriptSyntax(eng->context, ret->script,
+ JSCheckScriptSyntax(ctx, ret->script,
ret->source_url, ret->line_number, &ret->exception);
return ret;
@@ -35,7 +35,7 @@
JSValueRef ret;
js->exception = 0;
- ret = JSEvaluateScript(eng->context,
+ ret = JSEvaluateScript(ctx,
js->script, this, js->source_url,
js->line_number, &js->exception);
Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c (original)
+++ trunk/libseed/seed-builtins.c Wed Nov 26 00:59:00 2008
@@ -52,7 +52,7 @@
g_free(mes);
return JSValueMakeNull(ctx);
}
- import_file = seed_value_to_string(arguments[0], exception);
+ import_file = seed_value_to_string(ctx, arguments[0], exception);
g_file_get_contents(import_file, &buffer, 0, 0);
@@ -103,7 +103,7 @@
return JSValueMakeNull(ctx);
}
- gchar *buf = seed_value_to_string(arguments[0], exception);
+ gchar *buf = seed_value_to_string(ctx, arguments[0], exception);
printf("%s\n", buf);
g_free(buf);
@@ -135,13 +135,13 @@
return JSValueMakeNull(ctx);
}
- buf = seed_value_to_string(arguments[0], exception);
+ buf = seed_value_to_string(ctx, arguments[0], exception);
str = readline(buf);
if (str && *str)
{
add_history(str);
- valstr = seed_value_from_string(str, exception);
+ valstr = seed_value_from_string(ctx, str, exception);
g_free(str);
}
@@ -230,20 +230,20 @@
info = (GICallableInfo *) JSObjectGetPrivate((JSObjectRef) arguments[0]);
data_obj = JSObjectMake(ctx, NULL, NULL);
- seed_object_set_property(data_obj, "name", (JSValueRef)
- seed_value_from_string(g_base_info_get_name
+ seed_object_set_property(ctx, data_obj, "name", (JSValueRef)
+ seed_value_from_string(ctx, g_base_info_get_name
((GIBaseInfo *) info),
exception));
- seed_object_set_property(data_obj, "return_type",
+ seed_object_set_property(ctx, data_obj, "return_type",
seed_value_from_string
- (seed_g_type_name_to_string
+ (ctx, seed_g_type_name_to_string
(g_callable_info_get_return_type(info)),
exception));
args_obj = JSObjectMake(ctx, NULL, NULL);
- seed_object_set_property(data_obj, "args", args_obj);
+ seed_object_set_property(ctx, data_obj, "args", args_obj);
for (i = 0; i < g_callable_info_get_n_args(info); ++i)
{
@@ -253,8 +253,9 @@
seed_g_type_name_to_string(g_arg_info_get_type
(g_callable_info_get_arg(info, i)));
- seed_object_set_property(argument, "type",
- seed_value_from_string(arg_name, exception));
+ seed_object_set_property(ctx, argument, "type",
+ seed_value_from_string(ctx,
+ arg_name, exception));
JSObjectSetPropertyAtIndex(ctx, args_obj, i, argument, NULL);
}
@@ -437,19 +438,31 @@
JSObjectRef arrayObj;
JSValueRef argcref;
JSObjectRef obj =
- (JSObjectRef) seed_object_get_property(local_eng->global, "Seed");
+ (JSObjectRef) seed_object_get_property(local_eng->context,
+ local_eng->global, "Seed");
- seed_create_function("include", &seed_include, obj);
- seed_create_function("print", &seed_print, obj);
- seed_create_function("readline", &seed_readline, obj);
- seed_create_function("prototype", &seed_prototype, obj);
- seed_create_function("check_syntax", &seed_check_syntax, obj);
- seed_create_function("introspect", &seed_introspect, obj);
- seed_create_function("fork", &seed_fork, obj);
- seed_create_function("closure", &seed_closure, obj);
- seed_create_function("setTimeout", &seed_set_timeout, obj);
- seed_create_function("closure_native", &seed_closure_native, obj);
- seed_create_function("quit", &seed_quit, obj);
+ seed_create_function(local_eng->context,
+ "include", &seed_include, obj);
+ seed_create_function(local_eng->context,
+ "print", &seed_print, obj);
+ seed_create_function(local_eng->context,
+ "readline", &seed_readline, obj);
+ seed_create_function(local_eng->context,
+ "prototype", &seed_prototype, obj);
+ seed_create_function(local_eng->context,
+ "check_syntax", &seed_check_syntax, obj);
+ seed_create_function(local_eng->context,
+ "introspect", &seed_introspect, obj);
+ seed_create_function(local_eng->context,
+ "fork", &seed_fork, obj);
+ seed_create_function(local_eng->context,
+ "closure", &seed_closure, obj);
+ seed_create_function(local_eng->context,
+ "setTimeout", &seed_set_timeout, obj);
+ seed_create_function(local_eng->context,
+ "closure_native", &seed_closure_native, obj);
+ seed_create_function(local_eng->context,
+ "quit", &seed_quit, obj);
arrayObj = JSObjectMake(local_eng->context, NULL, NULL);
@@ -458,11 +471,12 @@
// TODO: exceptions!
JSObjectSetPropertyAtIndex(local_eng->context, arrayObj, i,
- seed_value_from_string((*argv)[i], 0), NULL);
+ seed_value_from_string(local_eng->context,
+ (*argv)[i], 0), NULL);
}
argcref = seed_value_from_int(*argc, 0);
- seed_object_set_property(arrayObj, "length", argcref);
- seed_object_set_property(obj, "argv", arrayObj);
+ seed_object_set_property(local_eng->context, arrayObj, "length", argcref);
+ seed_object_set_property(local_eng->context, obj, "argv", arrayObj);
}
Modified: trunk/libseed/seed-closure.c
==============================================================================
--- trunk/libseed/seed-closure.c (original)
+++ trunk/libseed/seed-closure.c Wed Nov 26 00:59:00 2008
@@ -120,6 +120,9 @@
GITypeInfo *return_type;
GArgument rarg;
GArgument *return_arg = g_new0(GArgument, 1);
+ JSContextRef ctx =
+ JSGlobalContextCreateInGroup(context_group, 0);
+
SEED_NOTE(INVOCATION, "Invoking closure of type: %s \n",
g_base_info_get_name((GIBaseInfo *) privates->info));
@@ -224,20 +227,20 @@
default:
arg->v_pointer = 0;
}
- jsargs[i] = seed_gi_argument_make_js(arg, arg_type, 0);
+ jsargs[i] = seed_gi_argument_make_js(ctx, arg, arg_type, 0);
seed_gi_release_in_arg(g_arg_info_get_ownership_transfer(arg_info),
arg_type, arg);
g_base_info_unref((GIBaseInfo *) arg_info);
}
return_value = (JSValueRef)
- JSObjectCallAsFunction(privates->ctx,
+ JSObjectCallAsFunction(ctx,
(JSObjectRef) privates->function, 0,
num_args, jsargs, 0);
g_free(jsargs);
- seed_gi_make_argument((JSValueRef) return_value, return_type,
+ seed_gi_make_argument(ctx, (JSValueRef) return_value, return_type,
return_arg, 0);
switch (return_tag)
{
@@ -323,6 +326,7 @@
*(gpointer *) result = 0;
}
+ JSGlobalContextRelease((JSGlobalContextRef)ctx);
g_free(return_arg);
}
@@ -342,7 +346,7 @@
JSObjectRef cached;
cached =
- (JSObjectRef) seed_object_get_property((JSObjectRef) function,
+ (JSObjectRef) seed_object_get_property(ctx, (JSObjectRef) function,
"__seed_native_closure");
if (cached
&& JSValueIsObjectOfClass(ctx, cached,
@@ -360,7 +364,6 @@
privates->info = info;
privates->function = function;
privates->cif = cif;
- privates->ctx = ctx;
for (i = 0; i < num_args; i++)
{
@@ -377,11 +380,11 @@
get_ffi_type(return_type), arg_types);
ffi_prep_closure(closure, cif, seed_handle_closure, privates);
- seed_object_set_property((JSObjectRef) function,
+ seed_object_set_property(ctx, (JSObjectRef) function,
"__seed_native_closure",
(JSValueRef) JSObjectMake(ctx,
- seed_native_callback_class,
- privates));
+ seed_native_callback_class,
+ privates));
return privates;
}
Modified: trunk/libseed/seed-closure.h
==============================================================================
--- trunk/libseed/seed-closure.h (original)
+++ trunk/libseed/seed-closure.h Wed Nov 26 00:59:00 2008
@@ -36,7 +36,6 @@
} SeedClosure;
typedef struct _SeedNativeClosure {
- JSContextRef ctx;
GICallableInfo *info;
JSValueRef function;
Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c (original)
+++ trunk/libseed/seed-engine.c Wed Nov 26 00:59:00 2008
@@ -29,6 +29,8 @@
JSClassRef gobject_signal_class;
JSClassRef seed_struct_constructor_class;
+JSContextGroupRef context_group;
+
GParamSpec **global_prop_cache;
gchar *glib_message = 0;
@@ -163,7 +165,7 @@
else
type = param_spec->value_type;
- seed_gvalue_from_seed_value(jsprop_value,
+ seed_gvalue_from_seed_value(ctx, jsprop_value,
type, ¶ms[i].value, exception);
if (*exception)
@@ -213,7 +215,7 @@
gchar *mes = g_strdup_printf("GObject equals comparison expected"
" 1 argument, got %d", argumentCount);
seed_make_exception(ctx, exception, "ArgumentError", mes);
- g_free(mes);
+ g_free(mes);
return JSValueMakeNull(ctx);
}
@@ -261,7 +263,7 @@
GIDirection dir;
JSValueRef retval_ref;
GError *error = 0;
-
+
info = JSObjectGetPrivate(function);
// We just want to check if there IS an object, not actually throw an
// exception if we don't
@@ -293,7 +295,7 @@
else if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT)
{
- if (!seed_gi_make_argument(arguments[i],
+ if (!seed_gi_make_argument(ctx, arguments[i],
type_info,
&in_args[n_in_args++], exception))
{
@@ -371,10 +373,10 @@
}
}
retval_ref =
- seed_gi_argument_make_js(&retval, type_info, exception);
-
- seed_gi_release_arg(g_callable_info_get_caller_owns((GICallableInfo
- *) info),
+ seed_gi_argument_make_js(ctx, &retval, type_info, exception);
+
+ seed_gi_release_arg(
+ g_callable_info_get_caller_owns((GICallableInfo*) info),
type_info, &retval);
}
g_base_info_unref((GIBaseInfo *) type_info);
@@ -406,12 +408,12 @@
g_base_info_unref((GIBaseInfo *) arg_info);
continue;
}
- jsout_val = seed_gi_argument_make_js(&out_values[i],
+ jsout_val = seed_gi_argument_make_js(ctx, &out_values[i],
type_info, exception);
if (!JSValueIsNull(ctx, arguments[i]) &&
JSValueIsObject(ctx, arguments[i]))
{
- seed_object_set_property((JSObjectRef) arguments[i],
+ seed_object_set_property(ctx, (JSObjectRef) arguments[i],
"value", jsout_val);
}
@@ -426,7 +428,8 @@
}
void
-seed_gobject_define_property_from_function_info(GIFunctionInfo * info,
+seed_gobject_define_property_from_function_info(JSContextRef ctx,
+ GIFunctionInfo * info,
JSObjectRef object,
gboolean instance)
{
@@ -445,17 +448,18 @@
return;
}
- method_ref = JSObjectMake(eng->context, gobject_method_class, info);
+ method_ref = JSObjectMake(ctx, gobject_method_class, info);
name = g_base_info_get_name((GIBaseInfo *) info);
if (!strcmp(name, "new"))
name = "_new";
- seed_object_set_property(object, name, method_ref);
+ seed_object_set_property(ctx, object, name, method_ref);
}
static void
-seed_gobject_add_methods_for_interfaces(GIObjectInfo * oinfo,
+seed_gobject_add_methods_for_interfaces(JSContextRef ctx,
+ GIObjectInfo * oinfo,
JSObjectRef object)
{
GIInterfaceInfo *interface;
@@ -474,14 +478,15 @@
{
function = g_interface_info_get_method(interface, k);
seed_gobject_define_property_from_function_info
- (function, object, TRUE);
+ (ctx, function, object, TRUE);
}
// g_base_info_unref((GIBaseInfo*)interface);
}
}
static void
-seed_gobject_add_methods_for_type(GIObjectInfo * oinfo, JSObjectRef object)
+seed_gobject_add_methods_for_type(JSContextRef ctx,
+ GIObjectInfo * oinfo, JSObjectRef object)
{
gint n_methods;
gint i;
@@ -492,11 +497,12 @@
for (i = 0; i < n_methods; i++)
{
info = g_object_info_get_method(oinfo, i);
- seed_gobject_define_property_from_function_info(info, object, TRUE);
+ seed_gobject_define_property_from_function_info(ctx,
+ info, object, TRUE);
}
}
-JSClassRef seed_gobject_get_class_for_gtype(GType type)
+JSClassRef seed_gobject_get_class_for_gtype(JSContextRef ctx, GType type)
{
JSClassDefinition def;
GType parent;
@@ -517,30 +523,31 @@
def.className = g_type_name(type);
if ((parent = g_type_parent(type)))
- parent_class = seed_gobject_get_class_for_gtype(parent);
+ parent_class = seed_gobject_get_class_for_gtype(ctx, parent);
def.parentClass = parent_class;
def.attributes = kJSClassAttributeNoAutomaticPrototype;
- prototype_obj = JSObjectMake(eng->context, 0, 0);
+ prototype_obj = JSObjectMake(ctx, 0, 0);
if (parent)
{
parent_prototype = seed_gobject_get_prototype_for_gtype(parent);
if (parent_prototype)
- JSObjectSetPrototype(eng->context, prototype_obj, parent_prototype);
+ JSObjectSetPrototype(ctx, prototype_obj, parent_prototype);
}
ref = JSClassCreate(&def);
JSClassRetain(ref);
- JSValueProtect(eng->context, prototype_obj);
+ JSValueProtect(ctx, prototype_obj);
g_type_set_qdata(type, qname, ref);
g_type_set_qdata(type, qprototype, prototype_obj);
if (info && (g_base_info_get_type(info) == GI_INFO_TYPE_OBJECT))
{
- seed_gobject_add_methods_for_type((GIObjectInfo *) info, prototype_obj);
- seed_gobject_add_methods_for_interfaces((GIObjectInfo *) info,
+ seed_gobject_add_methods_for_type(ctx,
+ (GIObjectInfo *) info, prototype_obj);
+ seed_gobject_add_methods_for_interfaces(ctx, (GIObjectInfo *) info,
prototype_obj);
}
else
@@ -564,7 +571,7 @@
g_interface_info_get_method((GIInterfaceInfo
*) interface, k);
seed_gobject_define_property_from_function_info
- (function, prototype_obj, TRUE);
+ (ctx, function, prototype_obj, TRUE);
}
}
}
@@ -712,7 +719,7 @@
g_value_init(&gval, spec->value_type);
g_object_get_property(b, cproperty_name, &gval);
- ret = seed_value_from_gvalue(&gval, exception);
+ ret = seed_value_from_gvalue(context, &gval, exception);
g_value_unset(&gval);
g_free(cproperty_name);
@@ -767,7 +774,7 @@
else
type = spec->value_type;
- seed_gvalue_from_seed_value(value, type, &gval, exception);
+ seed_gvalue_from_seed_value(context, value, type, &gval, exception);
if (*exception)
{
g_free(cproperty_name);
@@ -843,10 +850,10 @@
return JSValueMakeNull(ctx);
}
- namespace = seed_value_to_string(arguments[0], exception);
+ namespace = seed_value_to_string(ctx, arguments[0], exception);
if (argumentCount == 2)
{
- version = seed_value_to_string(arguments[1], exception);
+ version = seed_value_to_string(ctx, arguments[1], exception);
}
extension = seed_try_load_extension(namespace);
@@ -861,7 +868,7 @@
(*init)(eng);
g_free(namespace);
- return JSValueMakeNull(eng->context);
+ return JSValueMakeNull(ctx);
}
if (!g_irepository_require(g_irepository_get_default(), namespace,
@@ -875,7 +882,7 @@
namespace_ref = JSObjectMake(ctx, NULL, NULL);
JSValueProtect(ctx, namespace_ref);
- seed_object_set_property(eng->global, namespace, namespace_ref);
+ seed_object_set_property(ctx, eng->global, namespace, namespace_ref);
for (i = 0; i < n; i++)
{
@@ -883,7 +890,8 @@
namespace, i);
if (info && (g_base_info_get_type(info) == GI_INFO_TYPE_FUNCTION))
{
- seed_gobject_define_property_from_function_info((GIFunctionInfo *)
+ seed_gobject_define_property_from_function_info(ctx,
+ (GIFunctionInfo *)
info, namespace_ref,
FALSE);
}
@@ -896,7 +904,7 @@
JSObjectRef enum_class = JSObjectMake(ctx,
0, 0);
JSValueProtect(ctx, (JSValueRef) enum_class);
- seed_object_set_property(namespace_ref,
+ seed_object_set_property(ctx, namespace_ref,
g_base_info_get_name(info), enum_class);
for (j = 0; j < num_vals; j++)
@@ -919,7 +927,7 @@
name[j] = '_';
}
- seed_object_set_property(enum_class, name, value_ref);
+ seed_object_set_property(ctx, enum_class, name, value_ref);
g_free(name);
@@ -941,13 +949,14 @@
GIFunctionInfo *finfo;
GIFunctionInfoFlags flags;
- class_ref = seed_gobject_get_class_for_gtype(type);
+ class_ref = seed_gobject_get_class_for_gtype(ctx,
+ type);
constructor_ref =
JSObjectMake(ctx,
gobject_constructor_class, (gpointer) type);
- seed_object_set_property(constructor_ref,
+ seed_object_set_property(ctx, constructor_ref,
"type",
seed_value_from_int(type, exception));
@@ -959,7 +968,7 @@
if (flags & GI_FUNCTION_IS_CONSTRUCTOR)
{
seed_gobject_define_property_from_function_info
- (finfo, constructor_ref, FALSE);
+ (ctx, finfo, constructor_ref, FALSE);
}
else
{
@@ -967,7 +976,7 @@
}
}
- seed_object_set_property(namespace_ref,
+ seed_object_set_property(ctx, namespace_ref,
g_base_info_get_name
(info), constructor_ref);
JSValueProtect(ctx, (JSValueRef) constructor_ref);
@@ -989,11 +998,11 @@
{
finfo = g_struct_info_get_method((GIStructInfo *) info, i);
seed_gobject_define_property_from_function_info
- (finfo, struct_ref, FALSE);
+ (ctx, finfo, struct_ref, FALSE);
}
- seed_object_set_property(namespace_ref,
+ seed_object_set_property(ctx, namespace_ref,
g_base_info_get_name(info), struct_ref);
JSValueProtect(ctx, (JSValueRef) struct_ref);
@@ -1014,11 +1023,11 @@
{
finfo = g_union_info_get_method((GIUnionInfo *) info, i);
seed_gobject_define_property_from_function_info
- (finfo, struct_ref, FALSE);
+ (ctx, finfo, struct_ref, FALSE);
}
- seed_object_set_property(namespace_ref,
+ seed_object_set_property(ctx, namespace_ref,
g_base_info_get_name(info), struct_ref);
JSValueProtect(ctx, (JSValueRef) struct_ref);
@@ -1028,7 +1037,7 @@
JSObjectRef callback_ref = JSObjectMake(ctx,
seed_callback_class,
info);
- seed_object_set_property(namespace_ref,
+ seed_object_set_property(ctx, namespace_ref,
g_base_info_get_name(info),
(JSValueRef) callback_ref);
}
@@ -1039,9 +1048,9 @@
g_constant_info_get_value((GIConstantInfo *) info, &argument);
constant_value =
- seed_gi_argument_make_js(&argument,
- g_constant_info_get_type((GIConstantInfo *) info), exception);
- seed_object_set_property(namespace_ref,
+ seed_gi_argument_make_js(ctx, &argument,
+ g_constant_info_get_type((GIConstantInfo *) info), exception);
+ seed_object_set_property(ctx, namespace_ref,
g_base_info_get_name(info),
constant_value);
@@ -1171,13 +1180,15 @@
NULL /* Convert To Type */
};
-void seed_create_function(gchar * name, gpointer func, JSObjectRef obj)
+void seed_create_function(JSContextRef ctx,
+ gchar * name,
+ gpointer func, JSObjectRef obj)
{
JSObjectRef oref;
- oref = JSObjectMakeFunctionWithCallback(eng->context, NULL, func);
- JSValueProtect(eng->context, oref);
- seed_object_set_property(obj, name, oref);
+ oref = JSObjectMakeFunctionWithCallback(ctx, NULL, func);
+ JSValueProtect(ctx, oref);
+ seed_object_set_property(ctx, obj, name, oref);
}
static void
@@ -1280,9 +1291,12 @@
qprototype = g_quark_from_static_string("js-prototype");
eng = (SeedEngine *) g_malloc(sizeof(SeedEngine));
+
+ context_group = JSContextGroupCreate();
- eng->context = JSGlobalContextCreateInGroup(NULL, NULL);
+ eng->context = JSGlobalContextCreateInGroup(context_group, NULL);
eng->global = JSContextGetGlobalObject(eng->context);
+
gobject_class = JSClassCreate(&gobject_def);
JSClassRetain(gobject_class);
gobject_method_class = JSClassCreate(&gobject_method_def);
@@ -1299,16 +1313,16 @@
g_type_set_qdata(G_TYPE_OBJECT, qname, gobject_class);
seed_obj_ref = JSObjectMake(eng->context, NULL, NULL);
- seed_object_set_property(eng->global, "Seed", seed_obj_ref);
+ seed_object_set_property(eng->context, eng->global, "Seed", seed_obj_ref);
JSValueProtect(eng->context, seed_obj_ref);
- seed_create_function("import_namespace", &seed_gi_import_namespace,
+ seed_create_function(eng->context, "import_namespace", &seed_gi_import_namespace,
seed_obj_ref);
seed_init_builtins(eng, argc, argv);
seed_closures_init();
seed_structs_init();
- seed_gtype_init();
+ seed_gtype_init(eng);
defaults_script =
JSStringCreateWithUTF8CString("try{Seed.include(\"/usr/share/"
Modified: trunk/libseed/seed-engine.h
==============================================================================
--- trunk/libseed/seed-engine.h (original)
+++ trunk/libseed/seed-engine.h Wed Nov 26 00:59:00 2008
@@ -30,6 +30,8 @@
extern JSClassRef seed_callback_class;
extern SeedEngine *eng;
+extern JSContextGroupRef context_group;
+
typedef struct _SeedScript {
JSStringRef script;
JSValueRef exception;
@@ -39,13 +41,15 @@
} SeedScript;
JSObjectRef seed_gobject_get_prototype_for_gtype(GType type);
-JSClassRef seed_gobject_get_class_for_gtype(GType type);
+JSClassRef seed_gobject_get_class_for_gtype(JSContextRef ctx, GType type);
void
-seed_gobject_define_property_from_function_info(GIFunctionInfo * info,
+seed_gobject_define_property_from_function_info(JSContextRef ctx,
+ GIFunctionInfo * info,
JSObjectRef object,
gboolean instance);
-void seed_create_function(gchar * name, gpointer func, JSObjectRef obj);
+void seed_create_function(JSContextRef ctx, gchar * name,
+ gpointer func, JSObjectRef obj);
typedef void (*SeedModuleInitCallback) (SeedEngine * eng);
Modified: trunk/libseed/seed-exceptions.c
==============================================================================
--- trunk/libseed/seed-exceptions.c (original)
+++ trunk/libseed/seed-exceptions.c Wed Nov 26 00:59:00 2008
@@ -47,8 +47,8 @@
}
exception_obj = JSObjectMake(ctx, 0, NULL);
- seed_object_set_property(exception_obj, "message", js_message_ref);
- seed_object_set_property(exception_obj, "name", js_name_ref);
+ seed_object_set_property(ctx, exception_obj, "message", js_message_ref);
+ seed_object_set_property(ctx, exception_obj, "name", js_name_ref);
*exception = exception_obj;
@@ -91,8 +91,8 @@
if (!JSValueIsObject(ctx, e))
return 0;
- name = seed_object_get_property((JSObjectRef) e, "name");
- return seed_value_to_string(name, 0);
+ name = seed_object_get_property(ctx, (JSObjectRef) e, "name");
+ return seed_value_to_string(ctx, name, 0);
}
gchar *seed_exception_get_message(JSContextRef ctx, JSValueRef e)
@@ -102,8 +102,8 @@
if (!JSValueIsObject(ctx, e))
return 0;
- name = seed_object_get_property((JSObjectRef) e, "message");
- return seed_value_to_string(name, 0);
+ name = seed_object_get_property(ctx, (JSObjectRef) e, "message");
+ return seed_value_to_string(ctx, name, 0);
}
guint seed_exception_get_line(JSContextRef ctx, JSValueRef e)
@@ -112,7 +112,7 @@
g_assert((e));
if (!JSValueIsObject(ctx, e))
return 0;
- line = seed_object_get_property((JSObjectRef) e, "line");
+ line = seed_object_get_property(ctx, (JSObjectRef) e, "line");
return seed_value_to_uint(line, 0);
}
@@ -122,8 +122,8 @@
g_assert((e));
if (!JSValueIsObject(ctx, e))
return 0;
- line = seed_object_get_property((JSObjectRef) e, "sourceURL");
- return seed_value_to_string(line, 0);
+ line = seed_object_get_property(ctx, (JSObjectRef) e, "sourceURL");
+ return seed_value_to_string(ctx, line, 0);
}
gchar *seed_exception_to_string(JSContextRef ctx, JSValueRef e)
Modified: trunk/libseed/seed-gtype.c
==============================================================================
--- trunk/libseed/seed-gtype.c (original)
+++ trunk/libseed/seed-gtype.c Wed Nov 26 00:59:00 2008
@@ -232,14 +232,14 @@
spec = (GParamSpec *) seed_pointer_get_pointer(ctx, arguments[0]);
- oldcount = seed_object_get_property(thisObject, "property_count");
+ oldcount = seed_object_get_property(ctx, thisObject, "property_count");
property_count = seed_value_to_int(oldcount, exception);
class = seed_pointer_get_pointer(ctx, thisObject);
g_object_class_install_property(class, property_count, spec);
newcount = seed_value_from_int(property_count + 1, exception);
- seed_object_set_property(thisObject, "property_count", newcount);
+ seed_object_set_property(ctx, thisObject, "property_count", newcount);
return oldcount;
}
@@ -280,7 +280,7 @@
}
/* Signal name */
- jsname = seed_object_get_property((JSObjectRef) arguments[0], "name");
+ jsname = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "name");
/* seed_value_to_string can handle non strings, however the kind
* of strings we want as a signal name are rather small, so make sure
* we have an actual string */
@@ -291,14 +291,15 @@
"Signal definition needs name property");
return (JSObjectRef) JSValueMakeNull(ctx);
}
- name = seed_value_to_string(jsname, exception);
+ name = seed_value_to_string(ctx, jsname, exception);
/* Type to install on. Comes from class. */
- jstype = seed_object_get_property(thisObject, "type");
+ jstype = seed_object_get_property(ctx, thisObject, "type");
itype = seed_value_to_int(jstype, exception);
/* Signal flags */
- jsflags = seed_object_get_property((JSObjectRef) arguments[0], "flags");
+ jsflags = seed_object_get_property(ctx,
+ (JSObjectRef) arguments[0], "flags");
if (JSValueIsNull(ctx, jsflags) ||
!JSValueIsNumber(ctx, jsflags))
flags = G_SIGNAL_RUN_LAST;
@@ -306,7 +307,7 @@
flags = seed_value_to_long(jsflags, exception);
/* Return type */
- jsreturn_type = seed_object_get_property((JSObjectRef) arguments[0],
+ jsreturn_type = seed_object_get_property(ctx, (JSObjectRef) arguments[0],
"return_type");
if (JSValueIsNull(ctx, jsreturn_type) ||
!JSValueIsNumber(ctx, jsreturn_type))
@@ -315,13 +316,13 @@
return_type = seed_value_to_int(jsreturn_type, exception);
/* Number of params and types */
- jsparams = seed_object_get_property((JSObjectRef) arguments[0],
+ jsparams = seed_object_get_property(ctx, (JSObjectRef) arguments[0],
"parameters");
if (!JSValueIsNull(ctx, jsparams) &&
JSValueIsObject(ctx, jsparams))
{
n_params = seed_value_to_int
- (seed_object_get_property((JSObjectRef) jsparams, "length"),
+ (seed_object_get_property(ctx, (JSObjectRef) jsparams, "length"),
exception);
if (n_params > 0)
{
@@ -360,30 +361,34 @@
JSValueRef jsargs[2];
GType type;
JSValueRef exception = 0;
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group,
+ 0);
type = (GType) JSObjectGetPrivate(*(JSObjectRef *) args[1]);
- jsargs[0] = seed_make_pointer(eng->context, *(gpointer *) args[0]);
+ jsargs[0] = seed_make_pointer(ctx, *(gpointer *) args[0]);
jsargs[1] = seed_gobject_get_prototype_for_gtype(type);
// TODO:
// Should probably have a custom type for class, and have it auto convert.
- seed_object_set_property((JSObjectRef) jsargs[0],
+ seed_object_set_property(ctx, (JSObjectRef) jsargs[0],
"type", seed_value_from_int(type, 0));
- seed_object_set_property((JSObjectRef) jsargs[0],
+ seed_object_set_property(ctx, (JSObjectRef) jsargs[0],
"property_count", seed_value_from_int(1, 0));
- seed_create_function("install_signal",
+ seed_create_function(ctx, "install_signal",
&seed_gsignal_method_invoked, (JSObjectRef) jsargs[0]);
- seed_create_function("install_property",
+ seed_create_function(ctx, "install_property",
&seed_property_method_invoked,
(JSObjectRef) jsargs[0]);
- JSObjectCallAsFunction(eng->context, function, 0, 2, jsargs, 0);
+ JSObjectCallAsFunction(ctx, function, 0, 2, jsargs, 0);
if (exception)
{
- gchar *mes = seed_exception_to_string(eng->context,
+ gchar *mes = seed_exception_to_string(ctx,
exception);
g_warning("Exception in class init closure. %s \n", mes, 0);
}
+
+ JSGlobalContextRelease((JSGlobalContextRef)ctx);
}
static void
@@ -395,19 +400,25 @@
JSValueRef exception = 0;
JSObjectRef this_object;
- jsargs = seed_make_pointer(eng->context, *(gpointer *) args[1]);
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group,
+ 0);
+
+
+ jsargs = seed_make_pointer(ctx, *(gpointer *) args[1]);
this_object =
(JSObjectRef) seed_value_from_object(*(GObject **) args[0], 0);
- JSObjectCallAsFunction(eng->context, function, this_object, 1, &jsargs,
+ JSObjectCallAsFunction(ctx, function, this_object, 1, &jsargs,
&exception);
if (exception)
{
- gchar *mes = seed_exception_to_string(eng->context,
+ gchar *mes = seed_exception_to_string(ctx,
exception);
g_warning("Exception in instance init closure. %s \n", mes, 0);
}
+ JSGlobalContextRelease((JSGlobalContextRef)ctx);
+
}
static ffi_closure *seed_make_class_init_closure(JSObjectRef function)
@@ -418,7 +429,7 @@
ffi_arg result;
ffi_status status;
- JSValueProtect(eng->context, function);
+// Might need to protect function.
cif = g_new0(ffi_cif, 1);
arg_types = g_new0(ffi_type *, 3);
@@ -443,7 +454,7 @@
ffi_arg result;
ffi_status status;
- JSValueProtect(eng->context, function);
+// Might need to protect function.
cif = g_new0(ffi_cif, 1);
arg_types = g_new0(ffi_type *, 3);
@@ -504,14 +515,16 @@
return (JSObjectRef) JSValueMakeNull(ctx);
}
- parent_ref = seed_object_get_property((JSObjectRef) arguments[0], "parent");
- class_init = seed_object_get_property((JSObjectRef) arguments[0],
+ parent_ref = seed_object_get_property(ctx,
+ (JSObjectRef) arguments[0], "parent");
+ class_init = seed_object_get_property(ctx,
+ (JSObjectRef) arguments[0],
"class_init");
- instance_init = seed_object_get_property((JSObjectRef) arguments[0],
+ instance_init = seed_object_get_property(ctx, (JSObjectRef) arguments[0],
"instance_init");
- name = seed_object_get_property((JSObjectRef) arguments[0], "name");
+ name = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "name");
- new_name = seed_value_to_string(name, exception);
+ new_name = seed_value_to_string(ctx, name, exception);
if (!JSValueIsNumber(ctx, parent_ref))
{
seed_make_exception(ctx, exception, "TypeError",
@@ -548,7 +561,7 @@
type_info.class_data = constructor_ref;
new_type = g_type_register_static(parent_type, new_name, &type_info, 0);
- seed_gobject_get_class_for_gtype(new_type);
+ seed_gobject_get_class_for_gtype(ctx, new_type);
JSObjectSetPrivate(constructor_ref, (gpointer) new_type);
g_free(new_name);
@@ -556,7 +569,7 @@
(gpointer) new_type);
}
-void seed_gtype_init(void)
+void seed_gtype_init(SeedEngine * local_eng)
{
JSClassDefinition gtype_def = kJSClassDefinitionEmpty;
JSObjectRef gtype_constructor;
@@ -565,7 +578,8 @@
seed_gtype_class = JSClassCreate(>ype_def);
JSClassRetain(seed_gtype_class);
- gtype_constructor = JSObjectMake(eng->context, seed_gtype_class, 0);
+ gtype_constructor = JSObjectMake(local_eng->context, seed_gtype_class, 0);
- seed_object_set_property(eng->global, "GType", gtype_constructor);
+ seed_object_set_property(local_eng->context,
+ local_eng->global, "GType", gtype_constructor);
}
Modified: trunk/libseed/seed-gtype.h
==============================================================================
--- trunk/libseed/seed-gtype.h (original)
+++ trunk/libseed/seed-gtype.h Wed Nov 26 00:59:00 2008
@@ -24,6 +24,6 @@
#include "seed-private.h"
-void seed_gtype_init(void);
+void seed_gtype_init(SeedEngine * eng);
#endif
Modified: trunk/libseed/seed-signals.c
==============================================================================
--- trunk/libseed/seed-signals.c (original)
+++ trunk/libseed/seed-signals.c Wed Nov 26 00:59:00 2008
@@ -60,7 +60,7 @@
priv->object = obj;
priv->signal_name = signal->signal_name;
- seed_object_set_property(object_ref, js_signal_name, signal_ref);
+ seed_object_set_property(ctx, object_ref, js_signal_name, signal_ref);
g_free(js_signal_name);
}
@@ -153,7 +153,7 @@
user_data = (JSObjectRef)arguments[2];
}
- signal_name = seed_value_to_string(arguments[0], NULL);
+ signal_name = seed_value_to_string(ctx, arguments[0], NULL);
obj = (GObject *)JSObjectGetPrivate(thisObject);
obj_type = G_OBJECT_TYPE(obj);
@@ -192,14 +192,14 @@
g_free(interfaces);
}
- seed_object_set_property(object_ref, "signal", signals_ref);
+ seed_object_set_property(ctx, object_ref, "signal", signals_ref);
connect_func =
JSObjectMakeFunctionWithCallback(ctx, NULL,
&seed_gobject_signal_connect_by_name);
JSValueProtect(ctx, connect_func);
- seed_object_set_property(signals_ref, "connect", connect_func);
+ seed_object_set_property(ctx, signals_ref, "connect", connect_func);
}
void
@@ -213,12 +213,17 @@
JSValueRef *args, exception = 0;
JSValueRef ret = 0;
gint i;
+
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group,
+ 0);
args = g_newa(JSValueRef, n_param_values + 1);
for (i = 0; i < n_param_values; i++)
{
- args[i] = seed_value_from_gvalue((GValue *) & param_values[i], 0);
+ args[i] = seed_value_from_gvalue(ctx,
+ (GValue *) & param_values[i],
+ 0);
if (!args[i])
g_error("Error in signal marshal. "
@@ -230,34 +235,36 @@
if (seed_closure->user_data)
args[i] = seed_closure->user_data;
else
- args[i] = JSValueMakeNull(eng->context);
+ args[i] = JSValueMakeNull(ctx);
- ret = JSObjectCallAsFunction(eng->context, seed_closure->function,
+ ret = JSObjectCallAsFunction(ctx, seed_closure->function,
seed_closure->this,
n_param_values + 1, args, &exception);
if (exception)
{
- gchar *mes = seed_exception_to_string(eng->context,
+ gchar *mes = seed_exception_to_string(ctx,
exception);
g_warning("Exception in signal handler. %s \n", mes, 0);
g_free(mes);
exception = 0;
}
- if (ret && !JSValueIsNull(eng->context, ret)
+ if (ret && !JSValueIsNull(ctx, ret)
&& (seed_closure->return_type != G_TYPE_NONE))
{
- seed_gvalue_from_seed_value(ret, seed_closure->return_type,
+ seed_gvalue_from_seed_value(ctx, ret, seed_closure->return_type,
return_value, &exception);
}
if (exception)
{
- gchar *mes = seed_exception_to_string(eng->context, exception);
+ gchar *mes = seed_exception_to_string(ctx, exception);
g_warning("Exception in signal handler return value. %s \n", mes, 0);
g_free(mes);
}
+
+ JSGlobalContextRelease((JSGlobalContextRef)ctx);
}
@@ -298,7 +305,7 @@
g_value_init(¶ms[0], G_TYPE_OBJECT);
g_value_set_object(¶ms[0], privates->object);
for (i = 0; i < argumentCount; i++)
- seed_gvalue_from_seed_value(arguments[i],
+ seed_gvalue_from_seed_value(ctx, arguments[i],
query.param_types[i],
¶ms[i + 1], exception);
@@ -308,7 +315,7 @@
g_value_unset(¶ms[i]);
g_free(params);
- ret = seed_value_from_gvalue(&ret_value, exception);
+ ret = seed_value_from_gvalue(ctx, &ret_value, exception);
return ret;
}
Modified: trunk/libseed/seed-structs.c
==============================================================================
--- trunk/libseed/seed-structs.c (original)
+++ trunk/libseed/seed-structs.c Wed Nov 26 00:59:00 2008
@@ -38,8 +38,11 @@
seed_struct_privates *priv =
(seed_struct_privates *) JSObjectGetPrivate(object);
- SEED_NOTE(STRUCTS, "Finalizing seed_pointer object. with "
- "priv->free_pointer = %d \n", priv->free_pointer);
+ SEED_NOTE(STRUCTS, "Finalizing seed_pointer object %p. with "
+ "priv->free_pointer = %d with type: %s\n",
+ priv->pointer,
+ priv->free_pointer,
+ priv->info ? g_base_info_get_name(priv->info) : "[generic]");
if (priv->free_pointer)
g_free(priv->pointer);
@@ -154,7 +157,7 @@
}
// Maybe need to release argument.
- ret = seed_gi_argument_make_js(&field_value, field_type, exception);
+ ret = seed_gi_argument_make_js(ctx, &field_value, field_type, exception);
if (field_type)
g_base_info_unref((GIBaseInfo *) field_type);
return ret;
@@ -235,7 +238,9 @@
field_type = g_field_info_get_type(field);
- seed_gi_make_argument(value, field_type, &field_value, exception);
+ seed_gi_make_argument(context,
+ value,
+ field_type, &field_value, exception);
ret = g_field_info_set_field(field, priv->pointer, &field_value);
g_free(cproperty_name);
@@ -378,7 +383,7 @@
JSValueRef pointer,
gboolean free_pointer)
{
- if (JSValueIsObjectOfClass(eng->context, pointer, seed_pointer_class))
+ if (JSValueIsObjectOfClass(ctx, pointer, seed_pointer_class))
{
seed_struct_privates *priv = JSObjectGetPrivate((JSObjectRef) pointer);
priv->free_pointer = free_pointer;
@@ -417,7 +422,8 @@
finfo = g_union_info_get_method((GIUnionInfo *) info, i);
- seed_gobject_define_property_from_function_info((GIFunctionInfo *)
+ seed_gobject_define_property_from_function_info(ctx,
+ (GIFunctionInfo *)
finfo, object,
TRUE);
}
@@ -469,7 +475,8 @@
finfo = g_struct_info_get_method((GIStructInfo *) info, i);
- seed_gobject_define_property_from_function_info((GIFunctionInfo *)
+ seed_gobject_define_property_from_function_info(ctx,
+ (GIFunctionInfo *)
finfo, object,
TRUE);
}
@@ -516,15 +523,15 @@
size = g_union_info_get_size((GIUnionInfo *) info);
}
g_assert(size);
- object = g_slice_alloc0(size);
+ object = g_malloc0(size);
if (type == GI_INFO_TYPE_STRUCT)
ret = seed_make_struct(ctx, object, info);
else
ret = seed_make_union(ctx, object, info);
-
- seed_pointer_set_free(ctx, ret, TRUE);
+ seed_pointer_set_free(ctx, ret, TRUE);
+
if (!parameters)
return ret;
@@ -564,7 +571,7 @@
(JSObjectRef)parameters,
jsprop_name, NULL);
- seed_gi_make_argument(jsprop_value, field_type,
+ seed_gi_make_argument(ctx, jsprop_value, field_type,
&field_value, exception);
g_field_info_set_field(field, object, &field_value);
@@ -573,7 +580,8 @@
i++;
}
+ JSPropertyNameArrayRelease(jsprops);
-return ret;
+ return ret;
}
Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c (original)
+++ trunk/libseed/seed-types.c Wed Nov 26 00:59:00 2008
@@ -76,11 +76,11 @@
if (user_data)
return user_data;
- class = seed_gobject_get_class_for_gtype(type);
+ class = seed_gobject_get_class_for_gtype(eng->context, type);
while (!class && (type = g_type_parent(type)))
{
- class = seed_gobject_get_class_for_gtype(type);
+ class = seed_gobject_get_class_for_gtype(eng->context, type);
}
prototype = seed_gobject_get_prototype_for_gtype(type);
@@ -183,7 +183,8 @@
}
gboolean
-seed_gi_make_argument(JSValueRef value,
+seed_gi_make_argument(JSContextRef ctx,
+ JSValueRef value,
GITypeInfo * type_info, GArgument * arg,
JSValueRef * exception)
{
@@ -191,7 +192,7 @@
// FIXME: Some types are not "nullable", also need to check if argument
// can be null before doing this.
- if (!value || JSValueIsNull(eng->context, value))
+ if (!value || JSValueIsNull(ctx, value))
{
arg->v_pointer = 0;
return 1;
@@ -247,7 +248,7 @@
arg->v_double = seed_value_to_double(value, exception);
break;
case GI_TYPE_TAG_UTF8:
- arg->v_string = seed_value_to_string(value, exception);
+ arg->v_string = seed_value_to_string(ctx, value, exception);
break;
case GI_TYPE_TAG_INTERFACE:
{
@@ -293,9 +294,9 @@
}
else if (interface_type == GI_INFO_TYPE_STRUCT)
{
- if (JSValueIsObjectOfClass(eng->context,
+ if (JSValueIsObjectOfClass(ctx,
value, seed_struct_class))
- arg->v_pointer = seed_pointer_get_pointer(eng->context,
+ arg->v_pointer = seed_pointer_get_pointer(ctx,
value);
else
{
@@ -312,10 +313,10 @@
else if (g_type_is_a(type, G_TYPE_CLOSURE))
{
if (JSObjectIsFunction
- (eng->context, (JSObjectRef) value))
+ (ctx, (JSObjectRef) value))
{
arg->v_pointer =
- seed_make_gclosure(eng->context,
+ seed_make_gclosure(ctx,
(JSObjectRef) value, 0);
}
}
@@ -323,9 +324,9 @@
{
JSObjectRef strukt =
seed_construct_struct_type_with_parameters(
- eng->context,
+ ctx,
interface, (JSObjectRef)value, exception);
- arg->v_pointer = seed_pointer_get_pointer(eng->context,
+ arg->v_pointer = seed_pointer_get_pointer(ctx,
strukt);
}
}
@@ -334,7 +335,7 @@
}
else if (interface_type == GI_INFO_TYPE_CALLBACK)
{
- if (JSValueIsNull(eng->context, value))
+ if (JSValueIsNull(ctx, value))
{
arg->v_pointer = NULL;
g_base_info_unref(interface);
@@ -345,7 +346,7 @@
// Have to dlsym the symbol to be able to do this.
// NOTE: Some cases where dlsym(NULL, symbol) doesn't work depending
// On how libseed is loaded.
- else if (JSValueIsObjectOfClass(eng->context,
+ else if (JSValueIsObjectOfClass(ctx,
value, gobject_method_class))
{
GIFunctionInfo *info =
@@ -369,7 +370,7 @@
}
// Somewhat deprecated from when it was necessary to manually
// create closure objects...
- else if (JSValueIsObjectOfClass(eng->context,
+ else if (JSValueIsObjectOfClass(ctx,
value,
seed_native_callback_class))
{
@@ -382,10 +383,10 @@
}
// Automagically create closure around function passed in as
// callback.
- else if (JSObjectIsFunction(eng->context, (JSObjectRef) value))
+ else if (JSObjectIsFunction(ctx, (JSObjectRef) value))
{
SeedNativeClosure *privates =
- seed_make_native_closure(eng->context,
+ seed_make_native_closure(ctx,
(GICallableInfo *) interface,
value);
arg->v_pointer = privates->closure;
@@ -404,7 +405,8 @@
}
JSValueRef
-seed_gi_argument_make_js(GArgument * arg, GITypeInfo * type_info,
+seed_gi_argument_make_js(JSContextRef ctx,
+ GArgument * arg, GITypeInfo * type_info,
JSValueRef * exception)
{
GITypeTag gi_tag = g_type_info_get_tag(type_info);
@@ -444,7 +446,7 @@
case GI_TYPE_TAG_DOUBLE:
return seed_value_from_double(arg->v_double, exception);
case GI_TYPE_TAG_UTF8:
- return seed_value_from_string(arg->v_string, exception);
+ return seed_value_from_string(ctx, arg->v_string, exception);
case GI_TYPE_TAG_INTERFACE:
{
GIBaseInfo *interface;
@@ -459,7 +461,7 @@
if (arg->v_pointer == 0)
{
g_base_info_unref(interface);
- return JSValueMakeNull(eng->context);
+ return JSValueMakeNull(ctx);
}
g_base_info_unref(interface);
return seed_value_from_object(arg->v_pointer, exception);
@@ -474,7 +476,7 @@
{
JSValueRef strukt;
- strukt = seed_make_struct(eng->context,
+ strukt = seed_make_struct(ctx,
arg->v_pointer, interface);
g_base_info_unref(interface);
@@ -489,7 +491,7 @@
gint i = 0;
GList *list = arg->v_pointer;
- ret = JSObjectMake(eng->context, NULL, NULL);
+ ret = JSObjectMake(ctx, NULL, NULL);
list_type = g_type_info_get_param_type(type_info, 0);
for (; list != NULL; list = list->next)
@@ -498,9 +500,9 @@
larg.v_pointer = list->data;
ival =
- (JSValueRef) seed_gi_argument_make_js(&larg,
+ (JSValueRef) seed_gi_argument_make_js(ctx, &larg,
list_type, exception);
- JSObjectSetPropertyAtIndex(eng->context, ret, i, ival, NULL);
+ JSObjectSetPropertyAtIndex(ctx, ret, i, ival, NULL);
i++;
}
return ret;
@@ -514,7 +516,7 @@
gint i = 0;
GSList *list = arg->v_pointer;
- ret = JSObjectMake(eng->context, NULL, NULL);
+ ret = JSObjectMake(ctx, NULL, NULL);
list_type = g_type_info_get_param_type(type_info, 0);
for (; list != NULL; list = list->next)
@@ -523,9 +525,9 @@
larg.v_pointer = list->data;
ival =
- (JSValueRef) seed_gi_argument_make_js(&larg,
+ (JSValueRef) seed_gi_argument_make_js(ctx, &larg,
list_type, exception);
- JSObjectSetPropertyAtIndex(eng->context, ret, i, ival, NULL);
+ JSObjectSetPropertyAtIndex(ctx, ret, i, ival, NULL);
i++;
}
return ret;
@@ -538,7 +540,9 @@
return 0;
}
-JSValueRef seed_value_from_gvalue(GValue * gval, JSValueRef * exception)
+JSValueRef seed_value_from_gvalue(JSContextRef ctx,
+ GValue * gval,
+ JSValueRef * exception)
{
if (!G_IS_VALUE(gval))
{
@@ -569,14 +573,14 @@
case G_TYPE_DOUBLE:
return seed_value_from_double(g_value_get_double(gval), exception);
case G_TYPE_STRING:
- return seed_value_from_string((gchar *)
+ return seed_value_from_string(ctx, (gchar *)
g_value_get_string(gval), exception);
case G_TYPE_POINTER:
- return seed_make_pointer(eng->context,
+ return seed_make_pointer(ctx,
g_value_get_pointer(gval));
case G_TYPE_PARAM:
// Might need to dup and make a boxed.
- return seed_make_pointer(eng->context,
+ return seed_make_pointer(ctx,
g_value_get_param(gval));
}
@@ -602,17 +606,17 @@
if (type == GI_INFO_TYPE_UNION)
{
- return seed_make_union(eng->context,
+ return seed_make_union(ctx,
g_value_peek_pointer(gval), info);
}
else if (type == GI_INFO_TYPE_STRUCT)
{
- return seed_make_struct(eng->context,
+ return seed_make_struct(ctx,
g_value_peek_pointer(gval), info);
}
else if (type == GI_INFO_TYPE_BOXED)
{
- return seed_make_boxed(eng->context,
+ return seed_make_boxed(ctx,
g_value_dup_boxed(gval), info);
}
@@ -622,7 +626,9 @@
}
gboolean
-seed_gvalue_from_seed_value(JSValueRef val, GType type, GValue * ret,
+seed_gvalue_from_seed_value(JSContextRef ctx,
+ JSValueRef val,
+ GType type, GValue * ret,
JSValueRef * exception)
{
switch (type)
@@ -693,7 +699,7 @@
}
case G_TYPE_STRING:
{
- gchar *cval = seed_value_to_string(val, exception);
+ gchar *cval = seed_value_to_string(ctx, val, exception);
g_value_init(ret, G_TYPE_STRING);
g_value_take_string(ret, cval);
@@ -702,7 +708,7 @@
}
default:
{
- switch (JSValueGetType(eng->context, val))
+ switch (JSValueGetType(ctx, val))
{
case kJSTypeBoolean:
{
@@ -720,7 +726,7 @@
}
case kJSTypeString:
{
- gchar *cv = seed_value_to_string(val,
+ gchar *cv = seed_value_to_string(ctx, val,
exception);
g_value_init(ret, G_TYPE_STRING);
@@ -734,21 +740,21 @@
}
}
- if (g_type_is_a(type, G_TYPE_ENUM) && JSValueIsNumber(eng->context, val))
+ if (g_type_is_a(type, G_TYPE_ENUM) && JSValueIsNumber(ctx, val))
{
g_value_init(ret, type);
ret->data[0].v_long = seed_value_to_long(val, exception);
return TRUE;
}
else if (g_type_is_a(type, G_TYPE_FLAGS)
- && JSValueIsNumber(eng->context, val))
+ && JSValueIsNumber(ctx, val))
{
g_value_init(ret, type);
ret->data[0].v_long = seed_value_to_long(val, exception);
return TRUE;
}
else if (g_type_is_a(type, G_TYPE_OBJECT)
- && (JSValueIsNull(eng->context, val)
+ && (JSValueIsNull(ctx, val)
|| seed_value_is_gobject(val)))
{
GObject *o = seed_value_to_object(val, exception);
@@ -764,7 +770,7 @@
/* Boxed handling is broken. Will be fixed in struct overhall. */
else if (g_type_is_a(type, G_TYPE_BOXED))
{
- gpointer p = seed_pointer_get_pointer(eng->context, val);
+ gpointer p = seed_pointer_get_pointer(ctx, val);
if (p)
{
g_value_init(ret, type);
@@ -773,7 +779,7 @@
}
else
{
- if (JSValueIsObject(eng->context, val))
+ if (JSValueIsObject(ctx, val))
{
GIBaseInfo * info = g_irepository_find_by_gtype(0, type);
JSObjectRef new_struct;
@@ -781,11 +787,11 @@
return FALSE;
new_struct =
- seed_construct_struct_type_with_parameters(eng->context,
+ seed_construct_struct_type_with_parameters(ctx,
info,
(JSObjectRef)val,
exception);
- p = seed_pointer_get_pointer(eng->context, new_struct);
+ p = seed_pointer_get_pointer(ctx, new_struct);
if (p)
{
g_value_init(ret, type);
@@ -801,7 +807,8 @@
return FALSE;
}
-JSValueRef seed_object_get_property(JSObjectRef val, const gchar * name)
+JSValueRef seed_object_get_property(JSContextRef ctx,
+ JSObjectRef val, const gchar * name)
{
JSStringRef jname = JSStringCreateWithUTF8CString(name);
@@ -815,14 +822,14 @@
}
gboolean
-seed_object_set_property(JSObjectRef object,
+seed_object_set_property(JSContextRef ctx, JSObjectRef object,
const gchar * name, JSValueRef value)
{
JSStringRef jname = JSStringCreateWithUTF8CString(name);
if (value)
{
- JSObjectSetProperty(eng->context, (JSObjectRef) object,
+ JSObjectSetProperty(ctx, (JSObjectRef) object,
jname, value, 0, 0);
}
@@ -1068,7 +1075,8 @@
return JSValueMakeNumber(eng->context, (gdouble) val);
}
-gchar *seed_value_to_string(JSValueRef val, JSValueRef * exception)
+gchar *seed_value_to_string(JSContextRef ctx,
+ JSValueRef val, JSValueRef * exception)
{
JSStringRef jsstr = 0;
JSValueRef func, str;
@@ -1078,29 +1086,30 @@
if (val == NULL)
return NULL;
- if (JSValueIsBoolean(eng->context, val)
- || JSValueIsNumber(eng->context, val))
+ if (JSValueIsBoolean(ctx, val)
+ || JSValueIsNumber(ctx, val))
{
- buf = g_strdup_printf("%f", JSValueToNumber(eng->context, val, NULL));
+ buf = g_strdup_printf("%f", JSValueToNumber(ctx, val, NULL));
}
- else if (JSValueIsNull(eng->context, val)
- || JSValueIsUndefined(eng->context, val))
+ else if (JSValueIsNull(ctx, val)
+ || JSValueIsUndefined(ctx, val))
{
buf = strdup("[null]");
}
else
{
- if (!JSValueIsString(eng->context, val)) // In this case,
+ if (!JSValueIsString(ctx, val)) // In this case,
// it's an object
{
- func = seed_object_get_property((JSObjectRef) val, "toString");
+ func = seed_object_get_property(ctx,
+ (JSObjectRef) val, "toString");
str =
- JSObjectCallAsFunction(eng->context,
+ JSObjectCallAsFunction(ctx,
(JSObjectRef) func,
(JSObjectRef) val, 0, NULL, NULL);
}
- jsstr = JSValueToStringCopy(eng->context, val, NULL);
+ jsstr = JSValueToStringCopy(ctx, val, NULL);
length = JSStringGetMaximumUTF8CStringSize(jsstr);
if (length > 0)
{
@@ -1114,10 +1123,11 @@
return buf;
}
-JSValueRef seed_value_from_string(const gchar * val, JSValueRef * exception)
+JSValueRef seed_value_from_string(JSContextRef ctx,
+ const gchar * val, JSValueRef * exception)
{
JSStringRef jsstr = JSStringCreateWithUTF8CString(val);
- JSValueRef valstr = JSValueMakeString(eng->context, jsstr);
+ JSValueRef valstr = JSValueMakeString(ctx, jsstr);
JSStringRelease(jsstr);
return valstr;
Modified: trunk/libseed/seed-types.h
==============================================================================
--- trunk/libseed/seed-types.h (original)
+++ trunk/libseed/seed-types.h Wed Nov 26 00:59:00 2008
@@ -24,17 +24,25 @@
#include "seed-private.h"
-JSValueRef seed_value_from_gvalue(GValue * gval, JSValueRef * exception);
-JSValueRef seed_object_get_property(JSObjectRef val, const gchar * name);
+JSValueRef seed_value_from_gvalue(JSContextRef ctx,
+ GValue * gval,
+ JSValueRef * exception);
-gboolean seed_object_set_property(JSObjectRef object,
+JSValueRef seed_object_get_property(JSContextRef ctx,
+ JSObjectRef val, const gchar * name);
+
+gboolean seed_object_set_property(JSContextRef ctx, JSObjectRef object,
const gchar * name, JSValueRef value);
-gboolean seed_gvalue_from_seed_value(JSValueRef val, GType type,
+gboolean seed_gvalue_from_seed_value(JSContextRef ctx,
+ JSValueRef val, GType type,
GValue * gval, JSValueRef * exception);
-gboolean seed_gi_make_argument(JSValueRef value,
+
+gboolean seed_gi_make_argument(JSContextRef ctx,
+ JSValueRef value,
GITypeInfo * type_info,
GArgument * arg, JSValueRef * exception);
-JSValueRef seed_gi_argument_make_js(GArgument * arg,
+JSValueRef seed_gi_argument_make_js(JSContextRef ctx,
+ GArgument * arg,
GITypeInfo * type_info,
JSValueRef * exception);
@@ -77,8 +85,10 @@
gdouble seed_value_to_double(JSValueRef val, JSValueRef * exception);
JSValueRef seed_value_from_double(gdouble val, JSValueRef * exception);
-gchar *seed_value_to_string(JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_string(const gchar * val, JSValueRef * exception);
+gchar *seed_value_to_string(JSContextRef ctx,
+ JSValueRef val, JSValueRef * exception);
+JSValueRef seed_value_from_string(JSContextRef ctx,
+ const gchar * val, JSValueRef * exception);
GObject *seed_value_to_object(JSValueRef val, JSValueRef * exception);
JSValueRef seed_value_from_object(GObject * val, JSValueRef * exception);
Modified: trunk/libseed/seed.h
==============================================================================
--- trunk/libseed/seed.h (original)
+++ trunk/libseed/seed.h Wed Nov 26 00:59:00 2008
@@ -116,8 +116,10 @@
gdouble seed_value_to_double(SeedValue val, SeedException * exception);
SeedValue seed_value_from_double(gdouble val, SeedException * exception);
-gchar *seed_value_to_string(SeedValue val, SeedException * exception);
-SeedValue seed_value_from_string(gchar * val, SeedException * exception);
+gchar *seed_value_to_string(SeedContext ctx,
+ SeedValue val, SeedException * exception);
+SeedValue seed_value_from_string(SeedContext ctx,
+ gchar * val, SeedException * exception);
GObject *seed_value_to_object(SeedValue val, SeedException * exception);
SeedValue seed_value_from_object(GObject * val, SeedException * exception);
@@ -129,7 +131,8 @@
const SeedValue arguments[],
SeedException * exception);
-void seed_create_function(gchar * name, SeedFunctionCallback callback,
+void seed_create_function(SeedContext ctx,
+ gchar * name, SeedFunctionCallback callback,
SeedObject object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]