summaryrefslogtreecommitdiff
path: root/test/gjs-test-utils.h
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2017-01-11 23:34:40 -0800
committerPhilip Chimento <philip@endlessm.com>2017-02-08 09:34:56 -0800
commitcc71606f57599bb34ab5462cf2fab5ba3e810d6c (patch)
tree2764b831a5dd077215c4f19cbe775e444db4fd4b /test/gjs-test-utils.h
parentf4e5ef6f8358d17719aeeb02bfdb5ae1237c7224 (diff)
downloadgjs-cc71606f57599bb34ab5462cf2fab5ba3e810d6c.tar.gz
js: Refactor dual use of JS::Heap wrapper
The previous situation was that a JS::Heap wrapper was used to root a GC thing under some conditions using JS::AddFooRoot() or the keep-alive object, and trace or maintain a weak pointer otherwise. This will not be possible anymore in SpiderMonkey 38. JS::AddFooRoot() and JS::RemoveFooRoot() are going away, in favour of JS::PersistentRootedFoo. The keep-alive object has its own problems, because the SpiderMonkey 38 garbage collector will move GC things around, so anything referring to a GC thing on the keep-alive object will have to know when to update its JS::Heap wrapper when the GC thing moves. This previous situation existed in two places. (1) The JS::Value holding a trampoline's function. If the function was owned by the trampoline (the normal case), then it was rooted. If the function was a vfunc, in which case it was owned by the GObject class prototype and the trampoline was essentially leaked, then it remained a weak pointer. (2) The JSObject associated with a closure. In the normal case the object and the closure had the same lifetime and the object was rooted. Similar to above, if the closure was a signal it was owned by the GObject class, and traced. For both of these places we now use GjsMaybeOwned, a wrapper that sticks its GC thing in either a JS::PersistentRootedFoo, if the thing is intended to be rooted, or a JS::Heap<Foo>, if it is not. If rooted, the GjsMaybeOwned holds a weak reference to the GjsContext, and therefore can send out a notification when the context's dispose function is run, similar to existing functionality of the keep-alive object. This will still need to change further after the switch to SpiderMonkey 38, since weak pointers must be updated when they are moved by the GC. (This is technically already the case in SpiderMonkey 31, but the API makes it difficult to do correctly, and in practice it isn't necessary.) https://bugzilla.gnome.org/show_bug.cgi?id=776966
Diffstat (limited to 'test/gjs-test-utils.h')
-rw-r--r--test/gjs-test-utils.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/gjs-test-utils.h b/test/gjs-test-utils.h
index f25483a3..12cd9a0f 100644
--- a/test/gjs-test-utils.h
+++ b/test/gjs-test-utils.h
@@ -20,6 +20,9 @@
#ifndef GJS_TEST_UTILS_H
#define GJS_TEST_UTILS_H
+#include "gjs/context.h"
+#include "gjs/jsapi-wrapper.h"
+
typedef struct _GjsUnitTestFixture GjsUnitTestFixture;
struct _GjsUnitTestFixture {
GjsContext *gjs_context;
@@ -31,6 +34,10 @@ struct _GjsUnitTestFixture {
void gjs_unit_test_fixture_setup(GjsUnitTestFixture *fx,
gconstpointer unused);
+void gjs_unit_test_destroy_context(GjsUnitTestFixture *fx);
+
+void gjs_unit_test_teardown_context_already_destroyed(GjsUnitTestFixture *fx);
+
void gjs_unit_test_fixture_teardown(GjsUnitTestFixture *fx,
gconstpointer unused);
@@ -40,4 +47,6 @@ void gjs_test_add_tests_for_coverage ();
void gjs_test_add_tests_for_parse_call_args(void);
+void gjs_test_add_tests_for_rooting(void);
+
#endif