diff options
author | Marco Trevisan (TreviƱo) <mail@3v1n0.net> | 2021-05-16 18:02:10 +0200 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2021-08-01 15:54:59 -0700 |
commit | 2fc0d36062c805aaa28a8e63763fafbe4d25cf75 (patch) | |
tree | 7e498b0c41dabc1ee25200f19894211c70984b20 /test/gjs-test-rooting.cpp | |
parent | 41a6fa9c8d2c7bc077ae9e43bbb369ea675b2983 (diff) | |
download | gjs-2fc0d36062c805aaa28a8e63763fafbe4d25cf75.tar.gz |
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.
Diffstat (limited to 'test/gjs-test-rooting.cpp')
-rw-r--r-- | test/gjs-test-rooting.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
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 <config.h> -#include <glib-object.h> // for g_object_weak_unref, g_object_weak_ref #include <glib.h> #include <js/Class.h> @@ -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<GjsRootingFixture *>(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<JSObject *>(); - 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<JSObject *>(); - 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); |