[gjs] param: implement static methods



commit e20d7d74df695c92a6759482410d3ed54f768e6d
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Wed Feb 26 23:01:57 2014 +0100

    param: implement static methods
    
    We can share the code with object, and get them for free.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725282

 gi/object.cpp |   12 ++++++------
 gi/object.h   |    5 +++++
 gi/param.cpp  |    5 +++++
 3 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index d8c5beb..9d0afd1 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1851,11 +1851,11 @@ JSFunctionSpec gjs_object_instance_proto_funcs[] = {
     { NULL }
 };
 
-static JSBool
-gjs_define_static_methods(JSContext    *context,
-                          JSObject     *constructor,
-                          GType         gtype,
-                          GIObjectInfo *object_info)
+JSBool
+gjs_object_define_static_methods(JSContext    *context,
+                                 JSObject     *constructor,
+                                 GType         gtype,
+                                 GIObjectInfo *object_info)
 {
     int i;
     int n_methods;
@@ -1997,7 +1997,7 @@ gjs_define_object_class(JSContext      *context,
               constructor_name, prototype, JS_GetClass(prototype), in_object);
 
     if (info)
-        gjs_define_static_methods(context, constructor, gtype, info);
+        gjs_object_define_static_methods(context, constructor, gtype, info);
 
     value = OBJECT_TO_JSVAL(gjs_gtype_create_gtype_wrapper(context, gtype));
     JS_DefineProperty(context, constructor, "$gtype", value,
diff --git a/gi/object.h b/gi/object.h
index 47b6781..b6579cb 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -49,6 +49,11 @@ JSBool    gjs_typecheck_is_object       (JSContext     *context,
 
 void      gjs_object_prepare_shutdown   (JSContext     *context);
 
+JSBool    gjs_object_define_static_methods(JSContext    *context,
+                                           JSObject     *constructor,
+                                           GType         gtype,
+                                           GIObjectInfo *object_info);
+
 G_END_DECLS
 
 #endif  /* __GJS_OBJECT_H__ */
diff --git a/gi/param.cpp b/gi/param.cpp
index efd8d4e..7b4b5b5 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -224,6 +224,7 @@ gjs_define_param_class(JSContext    *context,
     JSObject *prototype;
     jsval value;
     JSObject *constructor;
+    GIObjectInfo *info;
 
     constructor_name = "ParamSpec";
 
@@ -250,6 +251,10 @@ gjs_define_param_class(JSContext    *context,
     JS_DefineProperty(context, constructor, "$gtype", value,
                       NULL, NULL, JSPROP_PERMANENT);
 
+    info = (GIObjectInfo*)g_irepository_find_by_gtype(g_irepository_get_default(), G_TYPE_PARAM);
+    gjs_object_define_static_methods(context, constructor, G_TYPE_PARAM, info);
+    g_base_info_unref( (GIBaseInfo*) info);
+
     gjs_debug(GJS_DEBUG_GPARAM, "Defined class %s prototype is %p class %p in object %p",
               constructor_name, prototype, JS_GetClass(prototype), in_object);
 }


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