[gjs/338-fix-callback-crash] arg-cache: Associate callback closure with instance object




commit 0768193cc1cd591354be863fb371fc2755c65b43
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Aug 9 11:36:25 2020 -0700

    arg-cache: Associate callback closure with instance object
    
    I mistakenly left this out during a rebase of the argument cache
    patches.
    
    Closes: #338

 gi/arg-cache.cpp | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index 911d10e4..ab8c0f84 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -314,9 +314,22 @@ static bool gjs_marshal_callback_in(JSContext* cx, GjsArgumentCache* self,
         JS::RootedFunction func(cx, JS_GetObjectFunction(&value.toObject()));
         GjsAutoCallableInfo callable_info =
             g_type_info_get_interface(&self->type_info);
+        bool is_object_method = !!state->instance_object;
         trampoline = gjs_callback_trampoline_new(cx, func, callable_info,
                                                  self->contents.callback.scope,
-                                                 state->instance_object, false);
+                                                 is_object_method, false);
+        if (!trampoline)
+            return false;
+        if (self->contents.callback.scope == GI_SCOPE_TYPE_NOTIFIED &&
+            is_object_method) {
+            auto* priv = ObjectInstance::for_js(cx, state->instance_object);
+            if (!priv) {
+                gjs_throw(cx, "Signal connected to wrong type of object");
+                return false;
+            }
+
+            priv->associate_closure(cx, trampoline->js_function);
+        }
         closure = trampoline->closure;
     }
 


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