[gjs/ewlsh/return-null-for-pointers: 8/8] gi: Return null if return argument is a pointer type




commit 5194d7b4cb45e10761e7278c392b5bc0f54527e1
Author: Evan Welsh <contact evanwelsh com>
Date:   Tue Aug 24 22:01:36 2021 -0700

    gi: Return null if return argument is a pointer type

 gi/arg.cpp                              | 7 ++++++-
 installed-tests/js/testGIMarshalling.js | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 5804cdd5..cff40e10 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -2431,7 +2431,12 @@ gjs_value_from_g_argument (JSContext             *context,
 
     switch (type_tag) {
     case GI_TYPE_TAG_VOID:
-        value_p.setUndefined(); /* or .setNull() ? */
+        // 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:
diff --git a/installed-tests/js/testGIMarshalling.js b/installed-tests/js/testGIMarshalling.js
index 27e05c8a..5958605d 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -920,9 +920,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]