[gjs: 2/3] function: Don't call into JS if on the wrong thread
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 2/3] function: Don't call into JS if on the wrong thread
- Date: Sun, 25 Feb 2018 04:02:32 +0000 (UTC)
commit 6f26113aafc2602090c8c0ef70410aaad9395572
Author: Philip Chimento <philip chimento gmail com>
Date: Tue Feb 20 23:03:51 2018 -0800
function: Don't call into JS if on the wrong thread
Checks that the current thread is the same thread as the JSContext was
started on. If not, refuses to call into JS.
Fixes #75.
gi/function.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 913cde3..9412980 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -209,6 +209,14 @@ gjs_callback_closure(ffi_cif *cif,
return;
}
+ auto gjs_cx = static_cast<GjsContext *>(JS_GetContextPrivate(context));
+ if (G_UNLIKELY (!_gjs_context_get_is_owner_thread(gjs_cx))) {
+ warn_about_illegal_js_callback(trampoline, "on a different thread",
+ "an API not intended to be used in JS");
+ gjs_callback_trampoline_unref(trampoline);
+ return;
+ }
+
JS_BeginRequest(context);
JSAutoCompartment ac(context,
gjs_closure_get_callable(trampoline->js_function));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]