[gjs: 9/10] arg: Fix marshalling GDK_NONE as GdkAtom argument in




commit 549395599d147aca4bcbf1a80a7c43cbb04f6e02
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Jan 29 21:57:15 2022 -0800

    arg: Fix marshalling GDK_NONE as GdkAtom argument in
    
    Mistakenly, gjs_value_to_g_argument() was expecting a JS Object value for
    a GdkAtom, meaning that it would do a null check and throw if the value
    was null while the argument was non-nullable. This broke the case of
    passing in GDK_NONE (as the JS string 'NONE' or JS null) because they
    correspond to the GdkAtom value of zero, which failed the null check.
    
    The previous behaviour was mistakenly encoded in a test, so rewrite the
    test as it ought to work.

 gi/arg.cpp                     |  3 ++-
 installed-tests/js/testGtk3.js | 17 +++--------------
 2 files changed, 5 insertions(+), 15 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 3322c4b79..34e7c1a73 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1642,7 +1642,8 @@ bool gjs_value_to_g_argument(JSContext* context, JS::HandleValue value,
 
         GIInfoType interface_type = g_base_info_get_type(interface_info);
         if (interface_type == GI_INFO_TYPE_ENUM ||
-            interface_type == GI_INFO_TYPE_FLAGS)
+            interface_type == GI_INFO_TYPE_FLAGS ||
+            arg::is_gdk_atom(interface_info))
             expect_object = false;
 
         if (interface_type == GI_INFO_TYPE_STRUCT &&
diff --git a/installed-tests/js/testGtk3.js b/installed-tests/js/testGtk3.js
index 83ca82478..9ffd83d29 100644
--- a/installed-tests/js/testGtk3.js
+++ b/installed-tests/js/testGtk3.js
@@ -251,20 +251,9 @@ describe('Gtk overrides', function () {
     });
 
     it('accepts null in place of GdkAtom as GDK_NONE', function () {
-        /**
-         * When you pass GDK_NONE (an atom, interned from the 'NONE' string)
-         * to Gtk.Clipboard.get(), it throws an error, mentioning null in
-         * its message.
-         */
-        expect(() => Gtk.Clipboard.get('NONE')).toThrowError(/null/);
-
-        /**
-         * Null is converted to GDK_NONE, so you get the same message. If you
-         * know an API function that accepts GDK_NONE without throwing, and
-         * returns something different when passed another atom, consider
-         * adding a less confusing example here.
-         */
-        expect(() => Gtk.Clipboard.get(null)).toThrowError(/null/);
+        const clipboard = Gtk.Clipboard.get('NONE');
+        const clipboard2 = Gtk.Clipboard.get(null);
+        expect(clipboard2).toBe(clipboard);
     });
 
     it('uses the correct GType for null child properties', function () {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]