Subject: [gjs/wip/ptomato/mozjs38: 13/17] WIP - Use
PersistentRooted in GjsCallbackTrampoline



commit 749c4ceecc89e33d433a9dec57cc51fb775da69d
Author: Philip Chimento <[email protected]>
Date: Wed Jan 11 23:34:40 2017 -0800

WIP - Use PersistentRooted in GjsCallbackTrampoline

Instead of tracing. This is a good candidate for PersistentRooted because
...explanation...

Needs more scrutiny.

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 4deb18a..6d161c9 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);
@@ -208,7 +201,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);
@@ -219,7 +212,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(con...

text);

for (i = 0, n_jsargs = 0; i < n_args; i++) {
@@ -290,7 +282,7 @@ gjs_callback_closure(ffi_cif *cif,

if (!JS_CallFunctionValue(context,
this_object,
- rooted_function,
+ *trampoline->js_function,
jsargs,
&rval)) {
goto out;
@@ -453,9 +445,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 234b551..58e3922 100644
--- a/gi/function.h
+++ b/gi/function.h
@@ -45,7 +45,7 @@ typedef struct {
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;
_______________________________________________
commits-list mailing list (read only)

mailman/listinfo/commits-list">https://mail.gnome.org/mailman/listinfo/commits-list


Want to limit the commits to a few modules? Go to above URL, log in to edit
your options and select the modules ('topics') you want.



Programming list archiving by: Enterprise Git Hosting