diff --git a/binding.c b/binding.c index eadea27..cf2faca 100644 --- a/binding.c +++ b/binding.c @@ -8,6 +8,13 @@ typedef struct { js_context_t *context; } bare_realm_t; +static void +on_realm_finalize (js_env_t *env, void *data, void *finalize_hint) { + bare_realm_t *realm = data; + + js_destroy_context(env, realm->context); +} + static js_value_t * bare_realm_create (js_env_t *env, js_callback_info_t *info) { int err; @@ -21,6 +28,9 @@ bare_realm_create (js_env_t *env, js_callback_info_t *info) { err = js_create_context(env, &realm->context); if (err < 0) return NULL; + err = js_add_finalizer(env, handle, (void *) realm, on_realm_finalize, NULL, NULL); + assert(err == 0); + return handle; } diff --git a/test.js b/test.js index 2b2d52c..a34d7d7 100644 --- a/test.js +++ b/test.js @@ -3,7 +3,6 @@ const Realm = require('.') test('basic', async (t) => { const realm = new Realm() - t.teardown(() => realm.destroy()) const globalThat = realm.evaluate('globalThis')