[gjs: 8/11] object: Handle error from gjs_callback_trampoline_new()



commit b2e2ad7ccd7bacefe33555377ba43faf94b95a77
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 1191aac6..01af3363 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2314,6 +2314,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 a19cc43a..92d1ffdf 100644
--- a/installed-tests/js/testGObjectClass.js
+++ b/installed-tests/js/testGObjectClass.js
@@ -453,6 +453,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]