[gjs/wip/ptomato/785657: 2/2] WIP - clean that stuff up



commit 7744c8ac4c8b35ebff98e213350d57b6c151707c
Author: Philip Chimento <philip endlessm com>
Date:   Tue Aug 22 20:46:30 2017 -0700

    WIP - clean that stuff up

 gi/closure.cpp        |    3 ++-
 gjs/context.cpp       |   16 ++++++++--------
 gjs/jsapi-util-root.h |   15 +++++++++++++++
 3 files changed, 25 insertions(+), 9 deletions(-)
---
diff --git a/gi/closure.cpp b/gi/closure.cpp
index 83e8d5a..88eb985 100644
--- a/gi/closure.cpp
+++ b/gi/closure.cpp
@@ -174,7 +174,8 @@ closure_set_invalid(gpointer  data,
     } else {
         gjs_debug_closure("Invalidating signal closure %p which calls object "
                           "%p", closure, self->obj.get());
-        JS::ExposeObjectToActiveJS(self->obj);
+        if (self->obj.is_valid())
+            JS::ExposeObjectToActiveJS(self->obj);
         self->obj.reset();
     }
 
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 3a0106c..c2d3b7b 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -225,6 +225,14 @@ gjs_context_dispose(GObject *object)
 
         warn_about_unhandled_promise_rejections(js_context);
 
+        js_context->destroying = true;
+
+        /* Now, release all native objects, to avoid recursion between
+         * the JS teardown and the C teardown.  The JSObject proxies
+         * still exist, but point to NULL.
+         */
+        gjs_object_prepare_shutdown();
+
         JS_BeginRequest(js_context->context);
 
         /* Do a full GC here before tearing down, since once we do
@@ -234,14 +242,6 @@ gjs_context_dispose(GObject *object)
         JS_GC(js_context->context);
         JS_EndRequest(js_context->context);
 
-        js_context->destroying = true;
-
-        /* Now, release all native objects, to avoid recursion between
-         * the JS teardown and the C teardown.  The JSObject proxies
-         * still exist, but point to NULL.
-         */
-        gjs_object_prepare_shutdown();
-
         if (js_context->auto_gc_id > 0) {
             g_source_remove (js_context->auto_gc_id);
             js_context->auto_gc_id = 0;
diff --git a/gjs/jsapi-util-root.h b/gjs/jsapi-util-root.h
index 33f748d..f5220b7 100644
--- a/gjs/jsapi-util-root.h
+++ b/gjs/jsapi-util-root.h
@@ -67,6 +67,7 @@
 template<typename T>
 struct GjsHeapOperation {
     static bool update_after_gc(JS::Heap<T> *location);
+    static bool is_valid(JS::Heap<T>& thing);
 };
 
 template<>
@@ -77,6 +78,12 @@ struct GjsHeapOperation<JSObject *> {
         JS_UpdateWeakPointerAfterGC(location);
         return (location->unbarrieredGet() == nullptr);
     }
+
+    static bool
+    is_valid(JS::Heap<JSObject *>& thing) {
+        JSObject *obj = thing.unbarrieredGet();
+        return obj && js::gc::detail::GetGCThingZone(uintptr_t(obj)) != nullptr;
+    }
 };
 
 template<>
@@ -249,6 +256,14 @@ public:
         m_heap = thing;
     }
 
+    bool
+    is_valid(void)
+    {
+        debug("is_valid()");
+        g_assert(!m_rooted);
+        return GjsHeapOperation<T>::is_valid(m_heap);
+    }
+
     void
     reset(void)
     {


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