[gjs/mozjs102: 56/59] js: Add JSTracer* argument to JS_UpdateWeakPointerAfterGC()




commit 6c1b87d22e923605872d5cdcaddba28bfa09e227
Author: Evan Welsh <contact evanwelsh com>
Date:   Fri Jul 22 10:46:14 2022 -0700

    js: Add JSTracer* argument to JS_UpdateWeakPointerAfterGC()
    
    This has some cascade effects on the signatures of other methods, since
    we now need to pass the JSTracer in.

 gi/object.cpp             | 12 ++++++------
 gi/object.h               | 11 ++++++-----
 gjs/jsapi-util-root.h     |  9 +++++----
 test/gjs-test-rooting.cpp |  4 ++--
 4 files changed, 19 insertions(+), 17 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index a4292f32f..75950938d 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1581,7 +1581,7 @@ ObjectPrototype::ObjectPrototype(GIObjectInfo* info, GType gtype)
  * Private callback, called after the JS engine finishes garbage collection, and
  * notifies when weak pointers need to be either moved or swept.
  */
-void ObjectInstance::update_heap_wrapper_weak_pointers(JSContext*,
+void ObjectInstance::update_heap_wrapper_weak_pointers(JSTracer* trc,
                                                        JS::Compartment*,
                                                        void*) {
     gjs_debug_lifecycle(GJS_DEBUG_GOBJECT, "Weak pointer update callback, "
@@ -1593,15 +1593,15 @@ void ObjectInstance::update_heap_wrapper_weak_pointers(JSContext*,
     auto locked_queue = ToggleQueue::get_default();
 
     ObjectInstance::remove_wrapped_gobjects_if(
-        std::mem_fn(&ObjectInstance::weak_pointer_was_finalized),
+        [&trc](ObjectInstance* instance) -> bool {
+            return instance->weak_pointer_was_finalized(trc);
+        },
         std::mem_fn(&ObjectInstance::disassociate_js_gobject));
 
     s_wrapped_gobject_list.shrink_to_fit();
 }
 
-bool
-ObjectInstance::weak_pointer_was_finalized(void)
-{
+bool ObjectInstance::weak_pointer_was_finalized(JSTracer* trc) {
     if (has_wrapper() && !wrapper_is_rooted()) {
         bool toggle_down_queued, toggle_up_queued;
 
@@ -1612,7 +1612,7 @@ ObjectInstance::weak_pointer_was_finalized(void)
         if (!toggle_down_queued && toggle_up_queued)
             return false;
 
-        if (!update_after_gc())
+        if (!update_after_gc(trc))
             return false;
 
         if (toggle_down_queued)
diff --git a/gi/object.h b/gi/object.h
index 00e51d6fc..31ee50ebe 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -336,18 +336,19 @@ class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype,
     void discard_wrapper(void) { m_wrapper.reset(); }
     void switch_to_rooted(JSContext* cx) { m_wrapper.switch_to_rooted(cx); }
     void switch_to_unrooted(JSContext* cx) { m_wrapper.switch_to_unrooted(cx); }
-    [[nodiscard]] bool update_after_gc() { return m_wrapper.update_after_gc(); }
+    [[nodiscard]] bool update_after_gc(JSTracer* trc) {
+        return m_wrapper.update_after_gc(trc);
+    }
     [[nodiscard]] bool wrapper_is_rooted() const { return m_wrapper.rooted(); }
     void release_native_object(void);
     void associate_js_gobject(JSContext* cx, JS::HandleObject obj,
                               GObject* gobj);
     void disassociate_js_gobject(void);
     void handle_context_dispose(void);
-    [[nodiscard]] bool weak_pointer_was_finalized();
+    [[nodiscard]] bool weak_pointer_was_finalized(JSTracer* trc);
     static void ensure_weak_pointer_callback(JSContext* cx);
-    static void update_heap_wrapper_weak_pointers(JSContext* cx,
-                                                  JS::Compartment* compartment,
-                                                  void* data);
+    static void update_heap_wrapper_weak_pointers(JSTracer* trc,
+                                                  JS::Compartment*, void* data);
 
  public:
     void toggle_down(void);
diff --git a/gjs/jsapi-util-root.h b/gjs/jsapi-util-root.h
index 6060e3eba..80f4d875a 100644
--- a/gjs/jsapi-util-root.h
+++ b/gjs/jsapi-util-root.h
@@ -62,8 +62,9 @@ struct GjsHeapOperation {
 
 template<>
 struct GjsHeapOperation<JSObject *> {
-    [[nodiscard]] static bool update_after_gc(JS::Heap<JSObject*>* location) {
-        JS_UpdateWeakPointerAfterGC(location);
+    [[nodiscard]] static bool update_after_gc(JSTracer* trc,
+                                              JS::Heap<JSObject*>* location) {
+        JS_UpdateWeakPointerAfterGC(trc, location);
         return (location->unbarrieredGet() == nullptr);
     }
 
@@ -251,10 +252,10 @@ class GjsMaybeOwned {
     /* If not tracing, then you must call this method during GC in order to
      * update the object's location if it was moved, or null it out if it was
      * finalized. If the object was finalized, returns true. */
-    bool update_after_gc() {
+    bool update_after_gc(JSTracer* trc) {
         debug("update_after_gc()");
         g_assert(!m_root);
-        return GjsHeapOperation<T>::update_after_gc(&m_heap);
+        return GjsHeapOperation<T>::update_after_gc(trc, &m_heap);
     }
 
     [[nodiscard]] constexpr bool rooted() const { return m_root != nullptr; }
diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp
index 7a82f70df..a7fec3db0 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -145,10 +145,10 @@ static void test_maybe_owned_rooted_is_collected_after_reset(
     delete obj;
 }
 
-static void update_weak_pointer(JSContext*, JS::Compartment*, void* data) {
+static void update_weak_pointer(JSTracer* trc, JS::Compartment*, void* data) {
     auto* obj = static_cast<GjsMaybeOwned<JSObject*>*>(data);
     if (*obj)
-        obj->update_after_gc();
+        obj->update_after_gc(trc);
 }
 
 static void test_maybe_owned_weak_pointer_is_collected_by_gc(


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