diff options
author | Evan Welsh <contact@evanwelsh.com> | 2022-07-22 10:46:14 -0700 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2022-08-07 16:42:03 -0700 |
commit | 1deacb549cc91a2e57aac0e484c4301a0a1b1e82 (patch) | |
tree | 83726201d779e05bf99cbe8545f68e017ba98702 | |
parent | a4f570f5fb76943b064e8867bacd3b4857841443 (diff) | |
download | gjs-1deacb549cc91a2e57aac0e484c4301a0a1b1e82.tar.gz |
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.
-rw-r--r-- | gi/object.cpp | 12 | ||||
-rw-r--r-- | gi/object.h | 11 | ||||
-rw-r--r-- | gjs/jsapi-util-root.h | 9 | ||||
-rw-r--r-- | test/gjs-test-rooting.cpp | 6 |
4 files changed, 21 insertions, 17 deletions
diff --git a/gi/object.cpp b/gi/object.cpp index f0f5c497..ed98ac50 100644 --- a/gi/object.cpp +++ b/gi/object.cpp @@ -1584,7 +1584,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, " @@ -1596,15 +1596,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; @@ -1615,7 +1615,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 c2fd4e5d..cb9af171 100644 --- a/gi/object.h +++ b/gi/object.h @@ -333,18 +333,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 6060e3eb..80f4d875 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 077f4508..d8109754 100644 --- a/test/gjs-test-rooting.cpp +++ b/test/gjs-test-rooting.cpp @@ -19,6 +19,8 @@ #include "gjs/jsapi-util.h" // for maybe_get_private #include "test/gjs-test-utils.h" +class JSTracer; + // COMPAT: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1553 #ifdef __clang_analyzer__ void g_assertion_message(const char*, const char*, int, const char*, @@ -148,10 +150,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( |