From 1b68e2e9f3579340bb65eb36d1e9e65e548c660e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 17 Dec 2019 04:06:57 +0100 Subject: gobject: Handle CONSTRUCT_ONLY flag CONSTRUCT_ONLY properties are supposed to be only writable during construction, however this is currently only enforced on the C level. Add some minimal handling for GObjects defined in JS as well, by redefining the property as read-only when set from the underlying C code. We know that call happens only during construction, as g_object_set_property() and friends handle the flag themselves, and turning the JS property read-only will prevent changes from javascript (unless it is explicitly made writable again). --- installed-tests/js/testLegacyGObject.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'installed-tests/js/testLegacyGObject.js') diff --git a/installed-tests/js/testLegacyGObject.js b/installed-tests/js/testLegacyGObject.js index f30bc906..c0b6017c 100644 --- a/installed-tests/js/testLegacyGObject.js +++ b/installed-tests/js/testLegacyGObject.js @@ -74,12 +74,7 @@ const MyObject = new GObject.Class({ }, set construct(val) { - // this should be called at most once - if (this._constructCalled) - throw Error('Construct-Only property set more than once'); - this._constructProp = val; - this._constructCalled = true; }, notify_prop() { @@ -220,13 +215,17 @@ describe('GObject class', function () { expect(myInstance3.construct).toEqual('quz'); }); + it('does not allow changing CONSTRUCT_ONLY properties', function () { + myInstance.construct = 'val'; + expect(myInstance.construct).toEqual('default'); + }); + it('has a name', function () { expect(MyObject.name).toEqual('MyObject'); }); // the following would (should) cause a CRITICAL: // myInstance.readonly = 'val'; - // myInstance.construct = 'val'; it('has a notify signal', function () { let notifySpy = jasmine.createSpy('notifySpy'); -- cgit v1.2.1