diff options
author | Florian Müllner <fmuellner@gnome.org> | 2019-12-17 04:06:57 +0100 |
---|---|---|
committer | Florian Müllner <fmuellner@gnome.org> | 2019-12-18 01:18:10 +0100 |
commit | 1b68e2e9f3579340bb65eb36d1e9e65e548c660e (patch) | |
tree | 8d1697913871c488438a04524e6c19a983797802 /installed-tests/js/testLegacyGObject.js | |
parent | 471591a3154c71990e1e59344a369f79d343caf7 (diff) | |
download | gjs-1b68e2e9f3579340bb65eb36d1e9e65e548c660e.tar.gz |
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).
Diffstat (limited to 'installed-tests/js/testLegacyGObject.js')
-rw-r--r-- | installed-tests/js/testLegacyGObject.js | 11 |
1 files changed, 5 insertions, 6 deletions
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'); |