[gjs/gnome-3-34] GObject: Check implementing Gio.AsyncInitable
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/gnome-3-34] GObject: Check implementing Gio.AsyncInitable
- Date: Wed, 13 Nov 2019 00:31:20 +0000 (UTC)
commit ea19d16b0c497da509a41cf80889e771c4c3ce1c
Author: Philip Chimento <philip chimento gmail com>
Date: Fri Nov 1 23:20:49 2019 -0700
GObject: Check implementing Gio.AsyncInitable
We want to avoid the situation in #287 altogether by making sure that
you can't implement Gio.AsyncInitable in your object without
implementing vfunc_init_async(), and print an error message that is more
likely to tell you what the problem is.
Since you _also_ can't implement vfunc_init_async() due to #72, we make
the error message more broad than it needs to be; the error message
should be changed to something like "You must define vfunc_init_async()
in order to implement Gio.AsyncInitable."
See #287.
installed-tests/js/testGObjectInterface.js | 10 ++++++++++
modules/overrides/GObject.js | 9 +++++++++
2 files changed, 19 insertions(+)
---
diff --git a/installed-tests/js/testGObjectInterface.js b/installed-tests/js/testGObjectInterface.js
index a6e0ffa2..2574d936 100644
--- a/installed-tests/js/testGObjectInterface.js
+++ b/installed-tests/js/testGObjectInterface.js
@@ -300,3 +300,13 @@ describe('GObject interface', function () {
/\[object instance wrapper GType:Gjs_GObjectImplementingGObjectInterface jsobj@0x[a-f0-9]+
native@0x[a-f0-9]+\]/);
});
});
+
+describe('Specific class and interface checks', function () {
+ it('Gio.AsyncInitable must implement vfunc_async_init', function () {
+ expect(() => GObject.registerClass({
+ Implements: [Gio.Initable, Gio.AsyncInitable],
+ }, class BadAsyncInitable extends GObject.Object {
+ vfunc_init() {}
+ })).toThrow();
+ });
+});
diff --git a/modules/overrides/GObject.js b/modules/overrides/GObject.js
index 658d8fe6..0aece542 100644
--- a/modules/overrides/GObject.js
+++ b/modules/overrides/GObject.js
@@ -147,6 +147,15 @@ function _interfacePresent(required, klass) {
}
function _checkInterface(iface, proto) {
+ // Checks for specific interfaces
+
+ // Default vfunc_async_init() will run vfunc_init() in a thread and crash.
+ // Change error message when https://gitlab.gnome.org/GNOME/gjs/issues/72
+ // has been solved.
+ if (iface.$gtype.name === 'GAsyncInitable' &&
+ !Object.getOwnPropertyNames(proto).includes('vfunc_init_async'))
+ throw new Error("It's not currently possible to implement Gio.AsyncInitable.");
+
// Check that proto implements all of this interface's required interfaces.
// "proto" refers to the object's prototype (which implements the interface)
// whereas "iface.prototype" is the interface's prototype (which may still
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]