summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (TreviƱo) <mail@3v1n0.net>2022-06-15 13:59:09 +0200
committerPhilip Chimento <philip.chimento@gmail.com>2022-11-20 19:08:18 -0800
commitf547e2da1a7d06784910aac1f6c25badbefb3193 (patch)
tree15bbb1477b655900478856bc0d8573baad89b1b9
parentd4af0286a54ca49148734db668f7052598094f0f (diff)
downloadgjs-f547e2da1a7d06784910aac1f6c25badbefb3193.tar.gz
union: define or create class using a static methods
To be consistent with other implementations.
-rw-r--r--gi/arg.cpp2
-rw-r--r--gi/repo.cpp3
-rw-r--r--gi/union.cpp15
-rw-r--r--gi/union.h19
-rw-r--r--gi/value.cpp2
5 files changed, 18 insertions, 23 deletions
diff --git a/gi/arg.cpp b/gi/arg.cpp
index f1ad91b4..ef94cea7 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -2681,7 +2681,7 @@ gjs_value_from_g_argument (JSContext *context,
}
if (interface_type == GI_INFO_TYPE_UNION) {
- JSObject* obj = gjs_union_from_c_union(
+ JSObject* obj = UnionInstance::new_for_c_union(
context, static_cast<GIUnionInfo*>(interface_info),
gjs_arg_get<void*>(arg));
if (!obj)
diff --git a/gi/repo.cpp b/gi/repo.cpp
index ab23677f..27e78b5e 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -407,7 +407,8 @@ gjs_define_info(JSContext *context,
return false;
break;
case GI_INFO_TYPE_UNION:
- if (!gjs_define_union_class(context, in_object, (GIUnionInfo*) info))
+ if (!UnionPrototype::define_class(context, in_object,
+ (GIUnionInfo*)info))
return false;
break;
case GI_INFO_TYPE_ENUM:
diff --git a/gi/union.cpp b/gi/union.cpp
index b8356c9e..ab52f58b 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -153,11 +153,9 @@ const struct JSClass UnionBase::klass = {
};
// clang-format on
-bool
-gjs_define_union_class(JSContext *context,
- JS::HandleObject in_object,
- GIUnionInfo *info)
-{
+bool UnionPrototype::define_class(JSContext* context,
+ JS::HandleObject in_object,
+ GIUnionInfo* info) {
GType gtype;
JS::RootedObject prototype(context), constructor(context);
@@ -174,11 +172,8 @@ gjs_define_union_class(JSContext *context,
&constructor, &prototype);
}
-JSObject*
-gjs_union_from_c_union(JSContext *context,
- GIUnionInfo *info,
- void *gboxed)
-{
+JSObject* UnionInstance::new_for_c_union(JSContext* context, GIUnionInfo* info,
+ void* gboxed) {
GType gtype;
if (!gboxed)
diff --git a/gi/union.h b/gi/union.h
index 4b490811..65f5f95f 100644
--- a/gi/union.h
+++ b/gi/union.h
@@ -58,6 +58,11 @@ class UnionPrototype : public GIWrapperPrototype<UnionBase, UnionPrototype,
// Overrides GIWrapperPrototype::constructor_nargs().
[[nodiscard]] unsigned constructor_nargs(void) const { return 0; }
+
+ public:
+ GJS_JSAPI_RETURN_CONVENTION
+ static bool define_class(JSContext* cx, JS::HandleObject in_object,
+ GIUnionInfo* info);
};
class UnionInstance
@@ -73,6 +78,10 @@ class UnionInstance
const JS::CallArgs& args);
public:
+ GJS_JSAPI_RETURN_CONVENTION
+ static JSObject* new_for_c_union(JSContext* cx, GIUnionInfo* info,
+ void* gboxed);
+
/*
* UnionInstance::copy_union:
*
@@ -85,14 +94,4 @@ class UnionInstance
static void* copy_ptr(JSContext* cx, GType gtype, void* ptr);
};
-GJS_JSAPI_RETURN_CONVENTION
-bool gjs_define_union_class(JSContext *context,
- JS::HandleObject in_object,
- GIUnionInfo *info);
-
-GJS_JSAPI_RETURN_CONVENTION
-JSObject* gjs_union_from_c_union (JSContext *context,
- GIUnionInfo *info,
- void *gboxed);
-
#endif // GI_UNION_H_
diff --git a/gi/value.cpp b/gi/value.cpp
index 5fa0a208..2e2f49aa 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -1030,7 +1030,7 @@ gjs_value_from_g_value_internal(JSContext *context,
else
obj = BoxedInstance::new_for_c_struct(context, info, gboxed);
} else if (type == GI_INFO_TYPE_UNION) {
- obj = gjs_union_from_c_union(context, info, gboxed);
+ obj = UnionInstance::new_for_c_union(context, info, gboxed);
} else {
gjs_throw(context, "Unexpected introspection type %d for %s",
info.type(), g_type_name(gtype));