[gjs/gnome-3-30] object: Fix write-only properties



commit 9f53812a19bf8364ad3d71ed6e39ea6f72e1ef40
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Oct 21 15:05:11 2018 +0100

    object: Fix write-only properties
    
    Since the property refactor, write-only properties have not been working.
    The problem was that a getter and setter function were not defined for
    them, because is_gobject_property_name() did not consider them to be
    properties. Now, the setter function works as normal while the getter
    function just pretends a write-only property has the value of undefined.
    
    The test is marked pending until a test is added to the
    gobject-introspection test suite.

 gi/object.cpp                                    | 17 ++++++++---------
 installed-tests/js/testEverythingEncapsulated.js | 10 ++++++++++
 2 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 0082ecbf..8ef7b1ab 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -386,8 +386,10 @@ ObjectInstance::prop_getter_impl(JSContext             *cx,
     if (g_param_spec_get_qdata(param, ObjectInstance::custom_property_quark()))
         return true;
 
-    if ((param->flags & G_PARAM_READABLE) == 0)
+    if ((param->flags & G_PARAM_READABLE) == 0) {
+        rval.setUndefined();
         return true;
+    }
 
     gjs_debug_jsprop(GJS_DEBUG_GOBJECT, "Accessing GObject property %s",
                      param->name);
@@ -691,10 +693,7 @@ static bool is_ginterface_property_name(GIInterfaceInfo* info,
         prop_info.reset();
     }
 
-    if (!prop_info)
-        return false;
-
-    return g_property_info_get_flags(prop_info) & G_PARAM_READABLE;
+    return !!prop_info;
 }
 
 bool ObjectPrototype::lazy_define_gobject_property(JSContext* cx,
@@ -812,14 +811,14 @@ is_gobject_property_name(GIObjectInfo *info,
                 return true;
             }
         }
+
+        g_free(canonical_name);
+        return false;
     }
 
     g_free(canonical_name);
 
-    if (!prop_info)
-        return false;
-
-    return g_property_info_get_flags(prop_info) & G_PARAM_READABLE;
+    return true;
 }
 
 bool ObjectBase::resolve(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
diff --git a/installed-tests/js/testEverythingEncapsulated.js 
b/installed-tests/js/testEverythingEncapsulated.js
index ec8215c1..d463fd75 100644
--- a/installed-tests/js/testEverythingEncapsulated.js
+++ b/installed-tests/js/testEverythingEncapsulated.js
@@ -234,6 +234,16 @@ describe('Introspected GObject', function () {
         expect(obj.name_conflict).toEqual(42);
         expect(obj.name_conflict instanceof Function).toBeFalsy();
     });
+
+    xit('sets write-only properties', function () {
+        expect(obj.int).not.toEqual(0);
+        obj.write_only = true;
+        expect(obj.int).toEqual(0);
+    });
+
+    it('gives undefined for write-only properties', function () {
+        expect(obj.write_only).not.toBeDefined();
+    });
 });
 
 describe('Introspected function length', function () {


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