[gjs/gnome-3-28] object: Move context dispose notify to GjsContext



commit bca20b4f367be3676684126b7c5b0fe65ee86377
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon May 21 12:42:59 2018 -0400

    object: Move context dispose notify to GjsContext
    
    This allows us to not deal with an "ensure_..." function, since the
    context dispose notify callback will always be there.
    
    See #144.

 gi/object.cpp   | 17 +++--------------
 gi/object.h     |  2 ++
 gjs/context.cpp |  2 ++
 3 files changed, 7 insertions(+), 14 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index f25e2685..e77942e3 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1043,9 +1043,9 @@ wrapped_gobj_dispose_notify(gpointer      data,
                         where_the_object_was);
 }
 
-static void
-context_dispose_notify(gpointer      data,
-                       GObject      *where_the_object_was)
+void
+gjs_object_context_dispose_notify(void    *data,
+                                  GObject *where_the_object_was)
 {
     ObjectInstance *priv = wrapped_gobject_list;
     while (priv) {
@@ -1367,16 +1367,6 @@ ensure_weak_pointer_callback(JSContext *cx)
     }
 }
 
-static void
-ensure_context_weak_pointer_callback(JSContext *cx)
-{
-    if (!context_weak_pointer_callback) {
-        auto gjs_cx = static_cast<GjsContext *>(JS_GetContextPrivate(cx));
-        g_object_weak_ref(G_OBJECT(gjs_cx), context_dispose_notify, NULL);
-        context_weak_pointer_callback = true;
-    }
-}
-
 static void
 associate_js_gobject (JSContext       *context,
                       JS::HandleObject object,
@@ -1394,7 +1384,6 @@ associate_js_gobject (JSContext       *context,
 
     priv->keep_alive = object;
     ensure_weak_pointer_callback(context);
-    ensure_context_weak_pointer_callback(context);
     object_instance_link(priv);
 
     g_object_weak_ref(gobj, wrapped_gobj_dispose_notify, priv);
diff --git a/gi/object.h b/gi/object.h
index 63aeb37f..1f1dce8c 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -61,6 +61,8 @@ bool      gjs_typecheck_is_object(JSContext       *context,
 void gjs_object_prepare_shutdown(void);
 void gjs_object_clear_toggles(void);
 void gjs_object_shutdown_toggle_queue(void);
+void gjs_object_context_dispose_notify(void    *data,
+                                       GObject *where_the_object_was);
 
 void gjs_object_define_static_methods(JSContext       *context,
                                       JS::HandleObject constructor,
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 4b26a985..fc887413 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -516,6 +516,8 @@ gjs_context_constructed(GObject *object)
     g_mutex_unlock (&contexts_lock);
 
     setup_dump_heap();
+
+    g_object_weak_ref(object, gjs_object_context_dispose_notify, nullptr);
 }
 
 static void


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