[gjs/ewlsh/gvalues] Small fixes for gvalues
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/ewlsh/gvalues] Small fixes for gvalues
- Date: Thu, 12 Aug 2021 07:23:00 +0000 (UTC)
commit 9ad4e4512c7f932537e9dd86f7560d953ba5d42b
Author: Evan Welsh <contact evanwelsh com>
Date: Thu Aug 12 00:22:50 2021 -0700
Small fixes for gvalues
gi/arg.cpp | 10 ++++++++--
gi/value.cpp | 10 ++++++++--
installed-tests/js/testGIMarshalling.js | 33 +++++++++++++++++++++------------
3 files changed, 37 insertions(+), 16 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 63e8e03c..e1a74634 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -2430,9 +2430,15 @@ gjs_value_from_g_argument (JSContext *context,
switch (type_tag) {
case GI_TYPE_TAG_VOID:
- value_p.setUndefined(); /* or .setNull() ? */
- break;
+ // If the argument is a pointer, convert
+ // to null to match our in handling.
+ if (g_type_info_is_pointer(type_info)) {
+ value_p.setNull();
+ } else {
+ value_p.setUndefined();
+ }
+ break;
case GI_TYPE_TAG_BOOLEAN:
value_p.setBoolean(gjs_arg_get<bool>(arg));
break;
diff --git a/gi/value.cpp b/gi/value.cpp
index ec64f0ac..2c044f45 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -756,9 +756,15 @@ gjs_value_to_g_value_no_copy(JSContext *context,
} else {
/* Need to distinguish between negative integers and unsigned integers */
GjsAutoEnumInfo info = g_irepository_find_by_gtype(nullptr, gtype);
- g_assert (info);
- v_double = _gjs_enum_from_int(info, v);
+ // Native enums don't have type info, assume
+ // they are signed to avoid crashing when
+ // they are exported to JS.
+ if (!info) {
+ v_double = int64_t(v);
+ } else {
+ v_double = _gjs_enum_from_int(info, v);
+ }
}
return JS::NumberValue(v_double);
diff --git a/installed-tests/js/testGIMarshalling.js b/installed-tests/js/testGIMarshalling.js
index 27e05c8a..298696da 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -758,21 +758,30 @@ describe('GValue', function () {
});
it('can be passed into a function and modified', function () {
- expect(() => GIMarshallingTests.gvalue_in_with_modification(42)).not.toThrow();
- // Let's assume this test doesn't expect that the modified GValue makes
- // it back to the caller; I don't see how that could be achieved.
- // See https://gitlab.gnome.org/GNOME/gjs/issues/80
+ const value = new GObject.Value();
+ value.init(GObject.TYPE_INT);
+ value.set_int(42);
+
+ expect(() => GIMarshallingTests.gvalue_in_with_modification(value)).not.toThrow();
+ expect(value.get_int()).toBe(24);
});
- xit('enum can be passed into a function and packed', function () {
- expect(() => GIMarshallingTests.gvalue_in_enum(GIMarshallingTests.Enum.VALUE3))
+ it('enum can be passed into a function and packed', function () {
+ const value = new GObject.Value();
+ // GIMarshallingTests.Enum is a native enum.
+ value.init(GObject.TYPE_ENUM);
+ value.set_enum(GIMarshallingTests.Enum.VALUE3);
+ expect(() => GIMarshallingTests.gvalue_in_enum(value))
.not.toThrow();
- }).pend("GJS doesn't support native enum types");
+ });
- xit('flags can be passed into a function and packed', function () {
- expect(() => GIMarshallingTests.gvalue_in_flags(GIMarshallingTests.Flags.VALUE3))
+ it('flags can be passed into a function and packed', function () {
+ const value = new GObject.Value();
+ value.init(GIMarshallingTests.Flags);
+ value.set_flags(GIMarshallingTests.Flags.VALUE3);
+ expect(() => GIMarshallingTests.gvalue_in_flags(value))
.not.toThrow();
- }).pend("we don't know to pack flags in a GValue as flags and not gint");
+ });
it('marshals as an int64 out parameter', function () {
expect(GIMarshallingTests.gvalue_int64_out()).toEqual(Limits.int64.max);
@@ -920,9 +929,9 @@ describe('Raw pointers', function () {
expect(GIMarshallingTests.pointer_in_return(null)).toBeFalsy();
});
- xit('can be roundtripped at least if the pointer is null', function () {
+ it('can be roundtripped at least if the pointer is null', function () {
expect(GIMarshallingTests.pointer_in_return(null)).toBeNull();
- }).pend('https://gitlab.gnome.org/GNOME/gjs/merge_requests/46');
+ });
});
describe('Registered enum type', function () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]