[gjs: 11/22] testGObjectDestructionAccess: Verify that disposed object is monitored
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 11/22] testGObjectDestructionAccess: Verify that disposed object is monitored
- Date: Fri, 23 Apr 2021 04:56:06 +0000 (UTC)
commit a1bbcdae30df3d3c30aa3833366ded062c01d483
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Thu Mar 25 21:42:24 2021 +0100
testGObjectDestructionAccess: Verify that disposed object is monitored
Thanks to the evil hacks we have now we can perform a delayed unref
without having to rely on pure JS code.
So we can test the case in which a JS-disposed (only) object is later
finalized by C code.
installed-tests/js/testGObjectDestructionAccess.js | 31 ++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/installed-tests/js/testGObjectDestructionAccess.js
b/installed-tests/js/testGObjectDestructionAccess.js
index 423da44e..c5d86ccb 100644
--- a/installed-tests/js/testGObjectDestructionAccess.js
+++ b/installed-tests/js/testGObjectDestructionAccess.js
@@ -4,7 +4,7 @@
imports.gi.versions.Gtk = '3.0';
-const {GLib, Gio, GObject, Gtk} = imports.gi;
+const {GLib, Gio, GjsTestTools, GObject, Gtk} = imports.gi;
const {system: System} = imports;
describe('Access to destroyed GObject', function () {
@@ -164,6 +164,14 @@ describe('Access to destroyed GObject', function () {
});
describe('Disposed or finalized GObject', function () {
+ beforeAll(function () {
+ GjsTestTools.init();
+ });
+
+ afterEach(function () {
+ GjsTestTools.reset();
+ });
+
it('is marked as disposed when it is a manually disposed property', function () {
const emblem = new Gio.EmblemedIcon({
gicon: new Gio.ThemedIcon({name: 'alarm'}),
@@ -223,11 +231,30 @@ describe('Disposed or finalized GObject', function () {
expect(file.toString()).toMatch(
/\[object \(FINALIZED\) instance wrapper GType:GLocalFile jsobj@0x[a-f0-9]+
native@0x[a-f0-9]+\]/);
file = null;
+ GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
+ '*Object 0x* has been finalized *');
+ System.gc();
+ GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0,
+ 'generates a warn on object garbage collection if has expando property');
+ });
+
+ it('generates a warn if already disposed at garbage collection', function () {
+ const loop = new GLib.MainLoop(null, false);
+
+ let file = Gio.File.new_for_path('/');
+ GjsTestTools.delayed_unref(file, 1); // Will happen after dispose
+ file.run_dispose();
+
+ let done = false;
+ GLib.timeout_add(GLib.PRIORITY_DEFAULT, 50, () => (done = true));
+ while (!done)
+ loop.get_context().iteration(true);
+ file = null;
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
'*Object 0x* has been finalized *');
System.gc();
GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0,
- 'generates a warn on object garbage collection');
+ 'generates a warn if already disposed at garbage collection');
});
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]