[gjs] Reference GjsCallbackTrampoline during callbacks to JS



commit 63632ac0ee5e1d7b5e5a2a864442b367898b3599
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Mar 13 12:13:01 2012 -0400

    Reference GjsCallbackTrampoline during callbacks to JS
    
    When we are calling back to Javascript, keep the GjsCallbackTrampoline
    object alive for the duration of the call, since we need to use information
    from it to process the return value even if the callback is removed during the
    callback.
    
    (This actually matters only for GI_SCOPE_TYPE_NOTIFIED, but we reference
    in all cases for simplicity.)
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=643014#c15 for an example
    of code triggering this problem.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672003

 gi/function.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
---
diff --git a/gi/function.c b/gi/function.c
index 0e3fc7f..51c90b9 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -214,6 +214,7 @@ gjs_callback_closure(ffi_cif *cif,
 
     trampoline = data;
     g_assert(trampoline);
+    gjs_callback_trampoline_ref(trampoline);
 
     context = gjs_runtime_get_current_context(trampoline->runtime);
     JS_BeginRequest(context);
@@ -409,6 +410,7 @@ out:
         completed_trampolines = g_slist_prepend(completed_trampolines, trampoline);
     }
 
+    gjs_callback_trampoline_unref(trampoline);
     JS_EndRequest(context);
 }
 



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