From f547e2da1a7d06784910aac1f6c25badbefb3193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 15 Jun 2022 13:59:09 +0200 Subject: union: define or create class using a static methods To be consistent with other implementations. --- gi/arg.cpp | 2 +- gi/repo.cpp | 3 ++- gi/union.cpp | 15 +++++---------- gi/union.h | 19 +++++++++---------- gi/value.cpp | 2 +- 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(interface_info), gjs_arg_get(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