[gjs/wip/ptomato/mozjs38: 19/23] WIP - Use PersistentRooted in GjsCallbackTrampoline
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs38: 19/23] WIP - Use PersistentRooted in GjsCallbackTrampoline
- Date: Wed, 18 Jan 2017 07:39:43 +0000 (UTC)
commit 431f7e865ac81dd3a2514d2c35373faa51de35ec
Author: Philip Chimento <philip chimento gmail com>
Date: Wed Jan 11 23:34:40 2017 -0800
WIP - Use PersistentRooted in GjsCallbackTrampoline
Instead of tracing.
Needs more scrutiny. This doesn't quite work! Previously the value was
rooted if the closure wasn't a vfunc, and traced if it was, because it
was associated with the GObject class prototype.
gi/function.cpp | 18 ++++--------------
gi/function.h | 2 +-
2 files changed, 5 insertions(+), 15 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 6680e40..3999d29 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -83,14 +83,7 @@ gjs_callback_trampoline_unref(GjsCallbackTrampoline *trampoline)
trampoline->ref_count--;
if (trampoline->ref_count == 0) {
- JSContext *context = trampoline->context;
-
- if (!trampoline->is_vfunc) {
- JS_BeginRequest(context);
- JS::RemoveValueRoot(context, &trampoline->js_function);
- JS_EndRequest(context);
- }
-
+ delete trampoline->js_function;
g_callable_info_free_closure(trampoline->info, trampoline->closure);
g_base_info_unref( (GIBaseInfo*) trampoline->info);
g_free (trampoline->param_types);
@@ -209,7 +202,7 @@ gjs_callback_closure(ffi_cif *cif,
}
JS_BeginRequest(context);
- func_obj = &trampoline->js_function.toObject();
+ func_obj = &trampoline->js_function->toObject();
JSAutoCompartment ac(context, func_obj);
n_args = g_callable_info_get_n_args(trampoline->info);
@@ -220,7 +213,6 @@ gjs_callback_closure(ffi_cif *cif,
JS::AutoValueVector jsargs(context);
jsargs.reserve(n_args);
JS::RootedValue rval(context);
- JS::RootedValue rooted_function(context, trampoline->js_function);
JS::RootedObject this_object(context);
for (i = 0, n_jsargs = 0; i < n_args; i++) {
@@ -291,7 +283,7 @@ gjs_callback_closure(ffi_cif *cif,
if (!JS_CallFunctionValue(context,
this_object,
- rooted_function,
+ *trampoline->js_function,
jsargs,
&rval)) {
goto out;
@@ -455,9 +447,7 @@ gjs_callback_trampoline_new(JSContext *context,
trampoline->context = context;
trampoline->info = callable_info;
g_base_info_ref((GIBaseInfo*)trampoline->info);
- trampoline->js_function = function;
- if (!is_vfunc)
- JS::AddValueRoot(context, &trampoline->js_function);
+ trampoline->js_function = new JS::PersistentRootedValue(context, function);
/* Analyze param types and directions, similarly to init_cached_function_data */
n_args = g_callable_info_get_n_args(trampoline->info);
diff --git a/gi/function.h b/gi/function.h
index 8bc9cb1..e0e5ea3 100644
--- a/gi/function.h
+++ b/gi/function.h
@@ -45,7 +45,7 @@ struct GjsCallbackTrampoline {
gint ref_count;
JSContext *context;
GICallableInfo *info;
- JS::Heap<JS::Value> js_function;
+ JS::PersistentRootedValue *js_function;
ffi_cif cif;
ffi_closure *closure;
GIScopeType scope;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]