From 2fc0d36062c805aaa28a8e63763fafbe4d25cf75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 16 May 2021 18:02:10 +0200 Subject: GjsMaybeOwned: Remove notifier support and move it into GjsPrivateContext GjsMaybeOwned had a notification support that was used only by Closures (other than tests), this was causing adding an extra pointer to all the types using it (including Object) that was mostly unused. So, move this into private context, re-implementing it using our own notifier (instead of relying on GObject's that needs a specific order) and use it in closures. Also add an hook to handle gc events on private context that will be in later changes to cleanup more things, but for now is used to shrink the closures vector once we've done. --- test/gjs-test-rooting.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test/gjs-test-rooting.cpp') diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp index cb878554..c3c89eb3 100644 --- a/test/gjs-test-rooting.cpp +++ b/test/gjs-test-rooting.cpp @@ -3,7 +3,6 @@ #include -#include // for g_object_weak_unref, g_object_weak_ref #include #include @@ -224,7 +223,7 @@ static void test_maybe_owned_switch_to_unrooted_allows_collection( delete obj; } -static void context_destroyed(JS::HandleObject, void* data) { +static void context_destroyed(JSContext*, void* data) { auto fx = static_cast(data); g_assert_false(fx->notify_called); g_assert_false(fx->finalized); @@ -234,8 +233,10 @@ static void context_destroyed(JS::HandleObject, void* data) { static void test_maybe_owned_notify_callback_called_on_context_destroy( GjsRootingFixture* fx, const void*) { + auto* gjs = GjsContextPrivate::from_cx(PARENT(fx)->cx); fx->obj = new GjsMaybeOwned(); - fx->obj->root(PARENT(fx)->cx, test_obj_new(fx), context_destroyed, fx); + fx->obj->root(PARENT(fx)->cx, test_obj_new(fx)); + gjs->register_notifier(context_destroyed, fx); gjs_unit_test_destroy_context(PARENT(fx)); g_assert_true(fx->notify_called); @@ -244,8 +245,10 @@ static void test_maybe_owned_notify_callback_called_on_context_destroy( static void test_maybe_owned_object_destroyed_after_notify( GjsRootingFixture* fx, const void*) { + auto* gjs = GjsContextPrivate::from_cx(PARENT(fx)->cx); fx->obj = new GjsMaybeOwned(); - fx->obj->root(PARENT(fx)->cx, test_obj_new(fx), context_destroyed, fx); + fx->obj->root(PARENT(fx)->cx, test_obj_new(fx)); + gjs->register_notifier(context_destroyed, fx); gjs_unit_test_destroy_context(PARENT(fx)); g_assert_true(fx->finalized); -- cgit v1.2.1