[gjs: 1/3] function: Refactor "callback blocked" message into helper function
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/3] function: Refactor "callback blocked" message into helper function
- Date: Sun, 25 Feb 2018 04:02:27 +0000 (UTC)
commit 1d2b3df72ac46bd63e6f88da5ba98e38f213537c
Author: Philip Chimento <philip chimento gmail com>
Date: Tue Feb 20 23:03:19 2018 -0800
function: Refactor "callback blocked" message into helper function
We're going to reuse this for the next commit.
gi/function.cpp | 32 ++++++++++++++++++++------------
installed-tests/js/testGtk.js | 2 +-
2 files changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 56f6da9..913cde3 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -158,6 +158,23 @@ set_return_ffi_arg_from_giargument (GITypeInfo *ret_type,
}
}
+static void
+warn_about_illegal_js_callback(const GjsCallbackTrampoline *trampoline,
+ const char *when,
+ const char *reason)
+{
+ g_critical("Attempting to run a JS callback %s. This is most likely caused "
+ "by %s. Because it would crash the application, it has been "
+ "blocked.", when, reason);
+ if (trampoline->info) {
+ const char *name = g_base_info_get_name(trampoline->info);
+ g_critical("The offending callback was %s()%s.", name,
+ trampoline->is_vfunc ? ", a vfunc" : "");
+ }
+ gjs_dumpstack();
+ return;
+}
+
/* This is our main entry point for ffi_closure callbacks.
* ffi_prep_closure is doing pure magic and replaces the original
* function call with this one which gives us the ffi arguments,
@@ -185,18 +202,9 @@ gjs_callback_closure(ffi_cif *cif,
context = gjs_closure_get_context(trampoline->js_function);
if (G_UNLIKELY(_gjs_context_is_sweeping(context))) {
- g_critical("Attempting to call back into JSAPI during the sweeping phase of GC. "
- "This is most likely caused by not destroying a Clutter actor or Gtk+ "
- "widget with ::destroy signals connected, but can also be caused by "
- "using the destroy(), dispose(), or remove() vfuncs. "
- "Because it would crash the application, it has been "
- "blocked and the JS callback not invoked.");
- if (trampoline->info) {
- const char *name = g_base_info_get_name(static_cast<GIBaseInfo *>(trampoline->info));
- g_critical("The offending callback was %s()%s.", name,
- trampoline->is_vfunc ? ", a vfunc" : "");
- }
- gjs_dumpstack();
+ warn_about_illegal_js_callback(trampoline, "during garbage collection",
+ "destroying a Clutter actor or GTK widget with ::destroy signal "
+ "connected, or using the destroy(), dispose(), or remove() vfuncs");
gjs_callback_trampoline_unref(trampoline);
return;
}
diff --git a/installed-tests/js/testGtk.js b/installed-tests/js/testGtk.js
index 736772e..fdc7ab3 100755
--- a/installed-tests/js/testGtk.js
+++ b/installed-tests/js/testGtk.js
@@ -112,7 +112,7 @@ describe('Gtk overrides', function () {
it('avoid crashing when GTK vfuncs are called in garbage collection', function () {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
- '*during the sweeping phase of GC*');
+ '*during garbage collection*');
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
'*destroy*');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]