seed r641 - trunk/libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r641 - trunk/libseed
- Date: Sun, 4 Jan 2009 10:03:51 +0000 (UTC)
Author: racarr
Date: Sun Jan 4 10:03:51 2009
New Revision: 641
URL: http://svn.gnome.org/viewvc/seed?rev=641&view=rev
Log:
Merge branch 'struct-prototypes'
Modified:
trunk/libseed/seed-engine.c
trunk/libseed/seed-structs.c
trunk/libseed/seed-structs.h
Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c (original)
+++ trunk/libseed/seed-engine.c Sun Jan 4 10:03:51 2009
@@ -1038,6 +1038,7 @@
else if (info && (g_base_info_get_type(info) == GI_INFO_TYPE_STRUCT))
{
JSObjectRef struct_ref;
+ JSObjectRef proto;
gint i, n_methods;
GIFunctionInfo *finfo;
@@ -1052,6 +1053,11 @@
(ctx, finfo, struct_ref, FALSE);
}
+
+ proto = seed_struct_prototype(ctx,
+ info);
+ seed_object_set_property(ctx, struct_ref,
+ "prototype", proto);
seed_object_set_property(ctx, namespace_ref,
g_base_info_get_name(info), struct_ref);
@@ -1061,6 +1067,7 @@
else if (info && (g_base_info_get_type(info) == GI_INFO_TYPE_UNION))
{
JSObjectRef struct_ref;
+ JSObjectRef proto;
gint i, n_methods;
GIFunctionInfo *finfo;
@@ -1076,6 +1083,11 @@
}
+ proto = seed_union_prototype(ctx,
+ info);
+ seed_object_set_property(ctx, struct_ref,
+ "prototype", proto);
+
seed_object_set_property(ctx, namespace_ref,
g_base_info_get_name(info), struct_ref);
Modified: trunk/libseed/seed-structs.c
==============================================================================
--- trunk/libseed/seed-structs.c (original)
+++ trunk/libseed/seed-structs.c Sun Jan 4 10:03:51 2009
@@ -33,6 +33,9 @@
gsize size;
} seed_struct_privates;
+GHashTable * struct_prototype_hash = NULL;
+GHashTable * union_prototype_hash = NULL;
+
static void seed_pointer_finalize(JSObjectRef object)
{
seed_struct_privates *priv =
@@ -338,7 +341,7 @@
JSClassDefinition seed_struct_def = {
0, /* Version, always 0 */
- 0,
+ kJSClassAttributeNoAutomaticPrototype,
"seed_struct", /* Class Name */
NULL, /* Parent Class */
NULL, /* Static Values */
@@ -358,7 +361,7 @@
JSClassDefinition seed_union_def = {
0, /* Version, always 0 */
- 0,
+ kJSClassAttributeNoAutomaticPrototype,
"seed_union", /* Class Name */
NULL, /* Parent Class */
NULL, /* Static Values */
@@ -378,7 +381,7 @@
JSClassDefinition seed_boxed_def = {
0, /* Version, always 0 */
- 0,
+ kJSClassAttributeNoAutomaticPrototype,
"seed_boxed", /* Class Name */
NULL, /* Parent Class */
NULL, /* Static Values */
@@ -436,21 +439,25 @@
return JSObjectMake(ctx, seed_pointer_class, priv);
}
-JSObjectRef seed_make_union(JSContextRef ctx, gpointer younion,
- GIBaseInfo * info)
+JSObjectRef seed_union_prototype(JSContextRef ctx,
+ GIBaseInfo *info)
{
- JSObjectRef object;
- gint i, n_methods;
- seed_struct_privates *priv = g_slice_alloc(sizeof(seed_struct_privates));
-
- priv->pointer = younion;
- priv->info = info ? g_base_info_ref(info) : 0;
- priv->free_pointer = FALSE;
-
- object = JSObjectMake(ctx, seed_union_class, priv);
-
- if (info)
+ JSObjectRef proto;
+ const gchar *namespace, *name;
+ gchar *key;
+ gint n_methods, i;
+
+ name = g_base_info_get_name(info);
+ namespace = g_base_info_get_namespace(info);
+ key = g_strjoin(NULL, namespace, name, NULL);
+
+ proto = (JSObjectRef) g_hash_table_lookup(union_prototype_hash,
+ key);
+
+ if (!proto)
{
+ proto = JSObjectMake(ctx, 0, 0);
+
n_methods = g_union_info_get_n_methods((GIUnionInfo *) info);
for (i = 0; i < n_methods; i++)
{
@@ -460,48 +467,80 @@
seed_gobject_define_property_from_function_info(ctx,
(GIFunctionInfo *)
- finfo, object,
+ finfo, proto,
TRUE);
g_base_info_unref((GIBaseInfo *) finfo);
}
+
+ g_hash_table_insert(union_prototype_hash,
+ key,
+ proto);
}
- return object;
+ return proto;
}
-JSObjectRef seed_make_boxed(JSContextRef ctx, gpointer boxed, GIBaseInfo * info)
+JSObjectRef seed_make_union(JSContextRef ctx, gpointer younion,
+ GIBaseInfo * info)
{
JSObjectRef object;
seed_struct_privates *priv = g_slice_alloc(sizeof(seed_struct_privates));
+ priv->pointer = younion;
priv->info = info ? g_base_info_ref(info) : 0;
- priv->pointer = boxed;
- // Boxed finalize handler handles freeing.
priv->free_pointer = FALSE;
- object = JSObjectMake(ctx, seed_boxed_class, priv);
+ object = JSObjectMake(ctx, seed_union_class, priv);
- // FIXME: Instance methods?
+ if (info)
+ {
+ JSObjectRef proto = seed_union_prototype(ctx, info);
+ if (proto)
+ JSObjectSetPrototype(ctx, object, proto);
+ else
+ g_assert_not_reached();
+ }
return object;
}
-JSObjectRef seed_make_struct(JSContextRef ctx,
- gpointer strukt, GIBaseInfo * info)
+JSObjectRef seed_make_boxed(JSContextRef ctx, gpointer boxed, GIBaseInfo * info)
{
JSObjectRef object;
- gint i, n_methods;
seed_struct_privates *priv = g_slice_alloc(sizeof(seed_struct_privates));
priv->info = info ? g_base_info_ref(info) : 0;
- priv->pointer = strukt;
+ priv->pointer = boxed;
+ // Boxed finalize handler handles freeing.
priv->free_pointer = FALSE;
- object = JSObjectMake(ctx, seed_struct_class, priv);
+ object = JSObjectMake(ctx, seed_boxed_class, priv);
- if (info)
+ // FIXME: Instance methods?
+
+ return object;
+}
+
+JSObjectRef seed_struct_prototype(JSContextRef ctx,
+ GIBaseInfo *info)
+{
+ JSObjectRef proto;
+ const gchar *namespace, *name;
+ gchar *key;
+ gint n_methods, i;
+
+ name = g_base_info_get_name(info);
+ namespace = g_base_info_get_namespace(info);
+ key = g_strjoin(NULL, namespace, name, NULL);
+
+ proto = (JSObjectRef) g_hash_table_lookup(struct_prototype_hash,
+ key);
+
+ if (!proto)
{
+ proto = JSObjectMake(ctx, 0, 0);
+
n_methods = g_struct_info_get_n_methods((GIStructInfo *) info);
for (i = 0; i < n_methods; i++)
{
@@ -511,11 +550,40 @@
seed_gobject_define_property_from_function_info(ctx,
(GIFunctionInfo *)
- finfo, object,
+ finfo, proto,
TRUE);
g_base_info_unref((GIBaseInfo *) finfo);
}
+
+ g_hash_table_insert(struct_prototype_hash,
+ key,
+ proto);
+ }
+
+ return proto;
+}
+
+JSObjectRef seed_make_struct(JSContextRef ctx,
+ gpointer strukt, GIBaseInfo * info)
+{
+ JSObjectRef object;
+ JSObjectRef proto;
+ seed_struct_privates *priv = g_slice_alloc(sizeof(seed_struct_privates));
+
+ priv->info = info ? g_base_info_ref(info) : 0;
+ priv->pointer = strukt;
+ priv->free_pointer = FALSE;
+
+ object = JSObjectMake(ctx, seed_struct_class, priv);
+ // Examine cases where struct is being used without info.
+ if (info)
+ {
+ proto = seed_struct_prototype(ctx, info);
+ if (proto)
+ JSObjectSetPrototype(ctx, object, proto);
+ else
+ g_assert_not_reached();
}
return object;
@@ -530,6 +598,11 @@
seed_union_class = JSClassCreate(&seed_union_def);
seed_boxed_def.parentClass = seed_struct_class;
seed_boxed_class = JSClassCreate(&seed_boxed_def);
+
+ struct_prototype_hash = g_hash_table_new(g_str_hash,
+ g_str_equal);
+ union_prototype_hash = g_hash_table_new(g_str_hash,
+ g_str_equal);
}
JSObjectRef
Modified: trunk/libseed/seed-structs.h
==============================================================================
--- trunk/libseed/seed-structs.h (original)
+++ trunk/libseed/seed-structs.h Sun Jan 4 10:03:51 2009
@@ -50,6 +50,11 @@
JSObjectRef parameters,
JSValueRef * exception);
+JSObjectRef seed_union_prototype(JSContextRef ctx,
+ GIBaseInfo *info);
+JSObjectRef seed_struct_prototype(JSContextRef ctx,
+ GIBaseInfo *info);
+
void seed_structs_init();
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]