[gjs: 1/2] object: Fix write-only properties
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/2] object: Fix write-only properties
- Date: Mon, 22 Oct 2018 15:50:28 +0000 (UTC)
commit 71324d9dbe6b559ee635b902d27348fd6849a54b
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 | 15 ++++++---------
installed-tests/js/testEverythingEncapsulated.js | 10 ++++++++++
2 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 1c3b7c33..f0c41401 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -383,8 +383,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);
@@ -684,10 +686,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,
@@ -799,12 +798,10 @@ is_gobject_property_name(GIObjectInfo *info,
if (is_ginterface_property_name(iface_info, canonical_name))
return true;
}
- }
-
- 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]