[gjs/gnome-3-34] object: Handle error from gjs_callback_trampoline_new()
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/gnome-3-34] object: Handle error from gjs_callback_trampoline_new()
- Date: Wed, 13 Nov 2019 00:31:10 +0000 (UTC)
commit cf8ca947647f395438eaddfb85458bc186ae1ab1
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Oct 27 17:47:19 2019 -0700
object: Handle error from gjs_callback_trampoline_new()
This fixes the crash mentioned in #72. The functionality of overriding
vfuncs with callbacks as parameters is still not supported, but now it
will throw an exception instead of crashing.
See: #72
gi/object.cpp | 2 ++
installed-tests/js/testGObjectClass.js | 8 ++++++++
2 files changed, 10 insertions(+)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 6012e5b2..048233db 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2316,6 +2316,8 @@ bool ObjectPrototype::hook_up_vfunc_impl(JSContext* cx,
JS::RootedFunction func(cx, JS_GetObjectFunction(function));
trampoline = gjs_callback_trampoline_new(
cx, func, vfunc, GI_SCOPE_TYPE_NOTIFIED, prototype, true);
+ if (!trampoline)
+ return false;
*((ffi_closure **)method_ptr) = trampoline->closure;
}
diff --git a/installed-tests/js/testGObjectClass.js b/installed-tests/js/testGObjectClass.js
index 77c6f3ab..a9d209e8 100644
--- a/installed-tests/js/testGObjectClass.js
+++ b/installed-tests/js/testGObjectClass.js
@@ -452,6 +452,14 @@ describe('GObject virtual function', function () {
expect(() => GObject.registerClass({GTypeName: 'SimpleTestClass3'}, _SimpleTestClass3)).toThrow();
});
+
+ it('gracefully bails out when overriding an unsupported vfunc type', function () {
+ expect(() => GObject.registerClass({
+ Implements: [Gio.AsyncInitable],
+ }, class Foo extends GObject.Object {
+ vfunc_init_async() {}
+ })).toThrow();
+ });
});
describe('GObject creation using base classes without registered GType', function () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]