summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Welsh <contact@evanwelsh.com>2021-08-24 22:03:14 -0700
committerEvan Welsh <contact@evanwelsh.com>2021-08-24 22:09:40 -0700
commit40d6c2af62520daa8fcd5c21d56a3519c1de0c83 (patch)
treedbe60d322e4ed79965226ddd01393ea89ba936b6
parenta3450059256c20f7751cb0f36c8ab187cf0de65e (diff)
downloadgjs-ewlsh/handle-native-enums.tar.gz
gi: Assume native enums are signed, avoid asserting.ewlsh/handle-native-enums
-rw-r--r--gi/value.cpp10
-rw-r--r--installed-tests/js/testGIMarshalling.js11
2 files changed, 15 insertions, 6 deletions
diff --git a/gi/value.cpp b/gi/value.cpp
index ec64f0ac..b58388d8 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 exposed 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..999a1720 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -764,11 +764,14 @@ describe('GValue', function () {
// See https://gitlab.gnome.org/GNOME/gjs/issues/80
});
- 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))
.not.toThrow();