diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2021-03-24 18:06:06 +0100 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2021-03-29 01:47:41 +0200 |
commit | 78bfccd3125d54caf8e1c0b8d2b84643e717a8b1 (patch) | |
tree | a22164e1c78ab02d2f3c9fae9b2341cf8e755eb6 /installed-tests/js/testGObjectDestructionAccess.js | |
parent | d2b30c523adf14f8fcdaaeb6967662465224a315 (diff) | |
download | gjs-78bfccd3125d54caf8e1c0b8d2b84643e717a8b1.tar.gz |
object: Return undefined and not the actual function on disposed objects
When calling a proto function on a disposed object we return true not to
throw, however when doing this we implicitly return to JS the actual
underlying function pointer and that may cause use the return value to
be used to wrongly set a variable or to be wrongly evaluated.
To avoid this and be consistent, return undefined instead.
Adapt tests for this and add more for uncovered methods.
Fixes #396
Diffstat (limited to 'installed-tests/js/testGObjectDestructionAccess.js')
-rw-r--r-- | installed-tests/js/testGObjectDestructionAccess.js | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/installed-tests/js/testGObjectDestructionAccess.js b/installed-tests/js/testGObjectDestructionAccess.js index ed1d6bb6..0b35d859 100644 --- a/installed-tests/js/testGObjectDestructionAccess.js +++ b/installed-tests/js/testGObjectDestructionAccess.js @@ -5,6 +5,7 @@ imports.gi.versions.Gtk = '3.0'; const GLib = imports.gi.GLib; +const GObject = imports.gi.GObject; const Gtk = imports.gi.Gtk; describe('Access to destroyed GObject', function () { @@ -23,7 +24,7 @@ describe('Access to destroyed GObject', function () { GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL, 'Object Gtk.Window (0x*'); - void destroyedWindow.title; + expect(destroyedWindow.title).toBeUndefined(); GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0, 'testExceptionInDestroyedObjectPropertyGet'); @@ -45,7 +46,7 @@ describe('Access to destroyed GObject', function () { GLib.test_expect_message('Gtk', GLib.LogLevelFlags.LEVEL_CRITICAL, '*GTK_IS_WINDOW*'); - void destroyedWindow.get_title(); + expect(destroyedWindow.get_title()).toBeNull(); GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0, 'testExceptionInDestroyedObjectMethodGet'); @@ -67,7 +68,7 @@ describe('Access to destroyed GObject', function () { GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL, 'Object Gtk.Window (0x*'); - destroyedWindow.connect('foo-signal', () => {}); + expect(destroyedWindow.connect('foo-signal', () => {})).toBe(0); GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0, 'testExceptionInDestroyedObjectConnect'); @@ -77,7 +78,7 @@ describe('Access to destroyed GObject', function () { GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL, 'Object Gtk.Window (0x*'); - destroyedWindow.connect_after('foo-signal', () => {}); + expect(destroyedWindow.connect_after('foo-signal', () => {})).toBe(0); GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0, 'testExceptionInDestroyedObjectConnectAfter'); @@ -87,12 +88,42 @@ describe('Access to destroyed GObject', function () { GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL, 'Object Gtk.Window (0x*'); - destroyedWindow.emit('foo-signal'); + expect(destroyedWindow.emit('foo-signal')).toBeUndefined(); GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0, 'testExceptionInDestroyedObjectEmit'); }); + it('Proto function signals_disconnect', function () { + GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL, + 'Object Gtk.Window (0x*'); + + expect(GObject.signal_handlers_disconnect_by_func(destroyedWindow, () => {})).toBe(0); + + GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0, + 'testExceptionInDestroyedObjectSignalsDisconnect'); + }); + + it('Proto function signals_block', function () { + GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL, + 'Object Gtk.Window (0x*'); + + expect(GObject.signal_handlers_block_by_func(destroyedWindow, () => {})).toBe(0); + + GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0, + 'testExceptionInDestroyedObjectSignalsBlock'); + }); + + it('Proto function signals_unblock', function () { + GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL, + 'Object Gtk.Window (0x*'); + + expect(GObject.signal_handlers_unblock_by_func(destroyedWindow, () => {})).toBe(0); + + GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0, + 'testExceptionInDestroyedObjectSignalsUnblock'); + }); + it('Proto function toString', function () { expect(destroyedWindow.toString()).toMatch( /\[object \(FINALIZED\) instance wrapper GIName:Gtk.Window jsobj@0x[a-f0-9]+ native@0x[a-f0-9]+\]/); |