[gjs: 4/14] fundamental: Also allow to transform a fundamental to a compatible gvalue
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 4/14] fundamental: Also allow to transform a fundamental to a compatible gvalue
- Date: Sat, 17 Apr 2021 04:36:47 +0000 (UTC)
commit ba6293fe61fa9ff4298b910e270abfb5b2b3a563
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date: Thu Apr 8 18:29:38 2021 +0200
fundamental: Also allow to transform a fundamental to a compatible gvalue
gi/fundamental.cpp | 7 +++++++
installed-tests/js/testFundamental.js | 12 ++++++++++++
2 files changed, 19 insertions(+)
---
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index d3221193..e117907e 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -470,6 +470,13 @@ bool FundamentalBase::to_gvalue(JSContext* cx, JS::HandleObject obj,
if (g_value_type_compatible(instance->gtype(), G_VALUE_TYPE(gvalue))) {
g_value_set_instance(gvalue, instance->m_ptr);
return true;
+ } else if (g_value_type_transformable(instance->gtype(),
+ G_VALUE_TYPE(gvalue))) {
+ GValue instance_value = {0};
+ g_value_init(&instance_value, instance->gtype());
+ g_value_set_instance(&instance_value, instance->m_ptr);
+ g_value_transform(&instance_value, gvalue);
+ return true;
}
gjs_throw(cx,
diff --git a/installed-tests/js/testFundamental.js b/installed-tests/js/testFundamental.js
index 4b555b61..0c939573 100644
--- a/installed-tests/js/testFundamental.js
+++ b/installed-tests/js/testFundamental.js
@@ -96,4 +96,16 @@ describe('Fundamental type support', function () {
expect(() => obj.emit('test-fundamental-no-funcs-subtype', fund)).toThrowError(
/ RegressTestFundamentalObjectNoGetSetFunc .* conversion to a GValue.*
RegressTestFundamentalSubObjectNoGetSetFunc/);
}).pend('https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/268');
+
+ it('can marshal a custom fundamental type into a transformable type', function () {
+ Regress.TestFundamentalObjectNoGetSetFunc.make_compatible_with_fundamental_sub_object();
+ const fund = new Regress.TestFundamentalObjectNoGetSetFunc('foo');
+ const obj = new TestObj();
+ const signalSpy = jasmine.createSpy('signalSpy');
+ obj.connect('test-fundamental-value-funcs-subtype', signalSpy);
+ obj.connect('test-fundamental-value-funcs-subtype', (_o, f) =>
+ expect(f instanceof Regress.TestFundamentalSubObject).toBeTrue());
+ obj.emit('test-fundamental-value-funcs-subtype', fund);
+ expect(signalSpy).toHaveBeenCalled();
+ }).pend('https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/268');
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]