[gjs/wip/gobj-kitchen-sink: 10/23] Move GParamSpec registration together with the other infos



commit e53cdaa6640a7f18857cc1c17159fec56a29d803
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Fri Dec 9 18:47:17 2011 +0100

    Move GParamSpec registration together with the other infos
    
    Instead of special casing it in ns_new_resolve(), now that it has
    correctly a GType, we can handle it together with the other objects.
    Also, check that the classes we define inherit from GObject, since
    we assume that around the code.

 gi/ns.c   |   16 ----------------
 gi/repo.c |   18 +++++++++++++++---
 2 files changed, 15 insertions(+), 19 deletions(-)
---
diff --git a/gi/ns.c b/gi/ns.c
index cea0882..f5d9c2b 100644
--- a/gi/ns.c
+++ b/gi/ns.c
@@ -95,22 +95,6 @@ ns_new_resolve(JSContext *context,
 
     JS_BeginRequest(context);
 
-    /* Special-case fallback hack for GParamSpec */
-    if (strcmp(name, "ParamSpec") == 0 &&
-        strcmp(priv->namespace, "GObject") == 0) {
-        if (!gjs_define_param_class(context,
-                                    obj,
-                                    NULL)) {
-            JS_EndRequest(context);
-            goto out;
-        } else {
-            *objp = obj; /* we defined the property in this object */
-            JS_EndRequest(context);
-            ret = JS_TRUE;
-            goto out;
-        }
-    }
-
     repo = g_irepository_get_default();
 
     info = g_irepository_find_by_name(repo, priv->namespace, name);
diff --git a/gi/repo.c b/gi/repo.c
index fa6a585..5a34e20 100644
--- a/gi/repo.c
+++ b/gi/repo.c
@@ -27,6 +27,7 @@
 #include "ns.h"
 #include "function.h"
 #include "object.h"
+#include "param.h"
 #include "boxed.h"
 #include "union.h"
 #include "enumeration.h"
@@ -470,10 +471,21 @@ gjs_define_info(JSContext  *context,
             GType gtype;
             GIBaseInfo *info_for_gtype;
             gtype = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*)info);
-            if (!gjs_define_object_class(context, in_object, gtype, NULL, NULL, &info_for_gtype))
+
+            if (g_type_is_a (gtype, G_TYPE_PARAM)) {
+                if (!gjs_define_param_class(context, in_object, NULL))
+                    return JS_FALSE;
+            } else if (g_type_is_a (gtype, G_TYPE_OBJECT)) {
+                if (!gjs_define_object_class(context, in_object, gtype, NULL, NULL, &info_for_gtype))
+                    return JS_FALSE;
+                g_assert(g_base_info_equal(info, info_for_gtype));
+                g_base_info_unref(info_for_gtype);
+            } else {
+                gjs_throw (context,
+                           "Unsupported type %s, deriving from fundamental %s",
+                           g_type_name(gtype), g_type_name(g_type_fundamental(gtype)));
                 return JS_FALSE;
-            g_assert(g_base_info_equal(info, info_for_gtype));
-            g_base_info_unref(info_for_gtype);
+            }
         }
         break;
     case GI_INFO_TYPE_STRUCT:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]