[gjs/wip/ptomato/mozjs38: 29/32] WIP - Use PersistentRooted in GjsCallbackTrampoline



commit 716e142178570d68be9f1f13b10cd18a96429625
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 2fd1812..80b95b7 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(context);
 
     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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]