summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2014-02-26 23:01:57 +0100
committerGiovanni Campagna <gcampagna@src.gnome.org>2014-04-11 01:35:53 +0200
commite20d7d74df695c92a6759482410d3ed54f768e6d (patch)
tree355eda4ee2be523c5edc86c31f0b0077e58d9193
parentc57a4d71e32808ad20d598022cd534af85fce04b (diff)
downloadgjs-e20d7d74df695c92a6759482410d3ed54f768e6d.tar.gz
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
-rw-r--r--gi/object.cpp12
-rw-r--r--gi/object.h5
-rw-r--r--gi/param.cpp5
3 files changed, 16 insertions, 6 deletions
diff --git a/gi/object.cpp b/gi/object.cpp
index d8c5beb4..9d0afd16 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 47b67812..b6579cbd 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 efd8d4ee..7b4b5b54 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);
}