Skip to content

Commit

Permalink
Destroy automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
yassernasc committed Sep 30, 2024
1 parent bf21363 commit 649e14e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 649e14e

Please sign in to comment.