[seed] Revert "[libseed] The real problem with seed_gtype_construct was that the qdata storing the instance
- From: Tim Horton <hortont src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [seed] Revert "[libseed] The real problem with seed_gtype_construct was that the qdata storing the instance
- Date: Fri, 31 Jul 2009 04:31:38 +0000 (UTC)
commit c5fa8fcf5afd15113c2d6d481cbc2e4ee7429a82
Author: Tim Horton <hortont424 gmail com>
Date: Fri Jul 31 00:28:13 2009 -0400
Revert "[libseed] The real problem with seed_gtype_construct was that the qdata storing the instance init function was being overwritten, use a hash table keyed by type now"
This reverts commit c7daca0f60ae7e687804b11a7f71990a96042b49.
Conflicts:
libseed/seed-gtype.c
examples/pango.js | 3 -
libseed/seed-gtype.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 155 insertions(+), 13 deletions(-)
---
diff --git a/examples/pango.js b/examples/pango.js
index dec9333..c554c51 100755
--- a/examples/pango.js
+++ b/examples/pango.js
@@ -396,9 +396,6 @@ window.resize(600, 600);
window.add(vbox);
window.show_all();
-// Ask Clutter to return motion events at 60Hz to help make dragging smoother
-Clutter.set_motion_events_frequency(60);
-
load_actors();
stage.show_all();
diff --git a/libseed/seed-gtype.c b/libseed/seed-gtype.c
index d2e0532..3204ce3 100644
--- a/libseed/seed-gtype.c
+++ b/libseed/seed-gtype.c
@@ -23,16 +23,19 @@
typedef GObject *(*GObjectConstructCallback) (GType, guint,
GObjectConstructParam *);
-GHashTable *gtype_iinits;
-
JSClassRef seed_gtype_class;
GIBaseInfo *objectclass_info = NULL;
GIBaseInfo *paramspec_info = NULL;
JSObjectRef seed_gtype_constructor;
-typedef struct _SeedGClassPrivates
-{
+GQuark qgetter;
+GQuark qsetter;
+
+GQuark qiinit;
+GQuark qcinit;
+
+typedef struct _SeedGClassPrivates {
JSObjectRef constructor;
JSObjectRef func;
@@ -193,6 +196,74 @@ seed_gsignal_method_invoked (JSContextRef ctx,
return (JSValueRef) seed_value_from_uint (ctx, signal_id, exception);
}
+static void
+seed_gtype_builtin_set_property (GObject * object,
+ guint property_id,
+ const GValue * value, GParamSpec * spec)
+{
+ JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
+ gchar *name = g_strjoin (NULL, "_", spec->name, NULL);
+ JSObjectRef jsobj = (JSObjectRef) seed_value_from_object (ctx, object, 0);
+
+ seed_prepare_global_context (ctx);
+
+ seed_object_set_property (ctx,
+ jsobj,
+ name,
+ seed_value_from_gvalue (ctx, (GValue *) value,
+ 0));
+
+ g_free (name);
+ JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+}
+
+static void
+seed_gtype_builtin_get_property (GObject * object,
+ guint property_id,
+ GValue * value, GParamSpec * spec)
+{
+ // TODO: Exceptions
+ JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
+ gchar *name = g_strjoin (NULL, "_", spec->name, NULL);
+ JSObjectRef jsobj = (JSObjectRef) seed_value_from_object (ctx, object, 0);
+ JSValueRef jsval = seed_object_get_property (ctx, jsobj,
+ name);
+
+ seed_prepare_global_context (ctx);
+
+ seed_gvalue_from_seed_value (ctx, jsval, spec->value_type, value, 0);
+
+ g_free (name);
+ JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+}
+
+static void
+seed_gtype_set_property (GObject * object,
+ guint property_id,
+ const GValue * value, GParamSpec * spec)
+{
+ gpointer data = g_param_spec_get_qdata (spec, qsetter);
+
+ if (!data)
+ {
+ seed_gtype_builtin_set_property (object, property_id, value, spec);
+ return;
+ }
+}
+
+static void
+seed_gtype_get_property (GObject * object,
+ guint property_id, GValue * value, GParamSpec * spec)
+{
+ gpointer data = g_param_spec_get_qdata (spec, qgetter);
+
+ if (!data)
+ {
+ seed_gtype_builtin_get_property (object, property_id, value, spec);
+ return;
+ }
+}
+
static GIBaseInfo *
seed_get_class_info_for_type (GType type)
{
@@ -231,7 +302,8 @@ seed_gtype_call_construct (GType type, GObject * object)
JSValueRef exception = NULL, args[1];
gchar *mes;
- func = g_hash_table_lookup (gtype_iinits, GINT_TO_POINTER (type));
+ func = g_type_get_qdata (type, qiinit);
+
if (func)
{
ctx = JSGlobalContextCreateInGroup (context_group, 0);
@@ -644,7 +716,9 @@ seed_gtype_class_init (gpointer g_class, gpointer class_data)
priv = (SeedGClassPrivates *) class_data;
- ((GObjectClass *) g_class)->constructor = seed_gtype_construct;
+ ((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);
@@ -804,8 +878,7 @@ seed_gtype_constructor_invoked (JSContextRef ctx,
JSValueIsObject (ctx, instance_init) &&
JSObjectIsFunction (ctx, (JSObjectRef) instance_init))
{
- g_hash_table_insert (gtype_iinits, GINT_TO_POINTER (new_type),
- (gpointer) instance_init);
+ g_type_set_qdata (new_type, qiinit, (gpointer) instance_init);
JSValueProtect (ctx, instance_init);
}
@@ -813,6 +886,72 @@ seed_gtype_constructor_invoked (JSContextRef ctx,
return constructor_ref;
}
+static JSValueRef
+seed_param_getter_invoked (JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef * exception)
+{
+ GParamSpec *pspec = seed_pointer_get_pointer (ctx, thisObject);
+
+ if (argumentCount != 1)
+ {
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "ParamSpec.get expected "
+ "1 argument, got %zd", argumentCount);
+
+ return JSValueMakeNull (ctx);
+ }
+ else if (JSValueIsNull (ctx, arguments[0]) ||
+ !JSValueIsObject (ctx, arguments[0]) ||
+ !JSObjectIsFunction (ctx, (JSObjectRef) arguments[0]))
+ {
+ // Maybe should accept C functions
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "ParamSpec.get expected a function");
+ return JSValueMakeNull (ctx);
+ }
+
+ g_param_spec_set_qdata (pspec, qgetter, (gpointer) arguments[0]);
+
+ return seed_value_from_boolean (ctx, TRUE, exception);
+}
+
+static JSValueRef
+seed_param_setter_invoked (JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef * exception)
+{
+ GParamSpec *pspec = seed_pointer_get_pointer (ctx, thisObject);
+
+ if (argumentCount != 1)
+ {
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "ParamSpec.set expected "
+ "1 argument, got %zd", argumentCount);
+
+ return JSValueMakeNull (ctx);
+ }
+ else if (JSValueIsNull (ctx, arguments[0]) ||
+ !JSValueIsObject (ctx, arguments[0]) ||
+ !JSObjectIsFunction (ctx, (JSObjectRef) arguments[0]))
+ {
+ // Maybe should accept C functions
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "ParamSpec.set expected a function");
+ return JSValueMakeNull (ctx);
+ }
+
+ g_param_spec_set_qdata (pspec, qsetter, (gpointer) arguments[0]);
+
+ return seed_value_from_boolean (ctx, TRUE, exception);
+}
+
void
seed_define_gtype_functions (JSContextRef ctx)
{
@@ -822,6 +961,12 @@ seed_define_gtype_functions (JSContextRef ctx)
"GObject", "ObjectClass");
proto = seed_struct_prototype (ctx, objectclass_info);
+
+ paramspec_info = g_irepository_find_by_name (NULL, "GObject", "ParamSpec");
+ proto = seed_struct_prototype (ctx, paramspec_info);
+
+ seed_create_function (ctx, "get", &seed_param_getter_invoked, proto);
+ seed_create_function (ctx, "set", &seed_param_setter_invoked, proto);
}
void
@@ -840,7 +985,7 @@ seed_gtype_init (SeedEngine * local_eng)
local_eng->global, "GType",
seed_gtype_constructor);
- seed_define_gtype_functions (local_eng->context);
+ qiinit = g_quark_from_static_string("js-instance-init");
- gtype_iinits = g_hash_table_new (g_int_hash, g_str_equal);
+ seed_define_gtype_functions (local_eng->context);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]