[seed] [libseed] Implement instanceof for GObject constructors and named GObject constructors, closes BGO 5
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [seed] [libseed] Implement instanceof for GObject constructors and named GObject constructors, closes BGO 5
- Date: Mon, 7 Sep 2009 06:13:17 +0000 (UTC)
commit 7053fcff8e4bbc5710b14485ec45768bc47ab37d
Author: Robert Carr <racarr gnome org>
Date: Mon Sep 7 02:13:10 2009 -0400
[libseed] Implement instanceof for GObject constructors and named GObject constructors, closes BGO 592936
libseed/seed-engine.c | 22 ++++++++++++++++++++--
1 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 6147da6..4f93349 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -64,6 +64,24 @@ static const GDebugKey seed_debug_keys[] = {
};
#endif /* SEED_ENABLE_DEBUG */
+static bool
+seed_gobject_has_instance (JSContextRef ctx, JSObjectRef constructor,
+ JSValueRef possible_instance, JSValueRef* exception)
+{
+ GType constructor_type, value_type;
+ if (JSValueIsNull (ctx, possible_instance) ||
+ !JSValueIsObject (ctx, possible_instance) ||
+ !JSValueIsObjectOfClass (ctx, possible_instance, gobject_class))
+ return FALSE;
+
+ constructor_type = (GType) JSObjectGetPrivate (constructor);
+ value_type = G_OBJECT_TYPE ((GObject *)
+ JSObjectGetPrivate ((JSObjectRef) possible_instance));
+
+ return g_type_is_a (value_type, constructor_type);
+}
+
+
/**
* seed_prepare_global_context:
* @ctx: A #SeedContext on which to add the default set of global objects.
@@ -1102,7 +1120,7 @@ JSClassDefinition gobject_constructor_def = {
NULL, /* Get Property Names */
NULL, /* Call As Function */
seed_gobject_constructor_invoked, /* Call As Constructor */
- NULL, /* Has Instance */
+ seed_gobject_has_instance, /* Has Instance */
seed_gobject_constructor_convert_to_type
};
@@ -1122,7 +1140,7 @@ JSClassDefinition gobject_named_constructor_def = {
NULL, /* Get Property Names */
NULL, /* Call As Function */
seed_gobject_named_constructor_invoked, /* Call As Constructor */
- NULL, /* Has Instance */
+ seed_gobject_has_instance, /* Has Instance */
seed_gobject_constructor_convert_to_type
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]