summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2019-11-01 23:20:49 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2019-11-01 23:20:49 -0700
commit675bd1887fcfb20e7a65ed532f4c0a9480c4df5b (patch)
tree716bde0ff0a0521687c712f6b651f7eb788c356e
parentabc29ac58488a64fc23c3318dbaaf16fbdbeb3a8 (diff)
downloadgjs-675bd1887fcfb20e7a65ed532f4c0a9480c4df5b.tar.gz
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.
-rw-r--r--installed-tests/js/testGObjectInterface.js10
-rw-r--r--modules/overrides/GObject.js9
2 files changed, 19 insertions, 0 deletions
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 5cc26082..b22d63b3 100644
--- a/modules/overrides/GObject.js
+++ b/modules/overrides/GObject.js
@@ -199,6 +199,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