xref: /third_party/node/test/node-api/test_instance_data/addon.c
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/node-api/test_instance_data/
11cb0ef41Sopenharmony_ci#include <stdio.h>
21cb0ef41Sopenharmony_ci#include <stdlib.h>
31cb0ef41Sopenharmony_ci#include <node_api.h>
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cistatic void addon_free(napi_env env, void* data, void* hint) {
61cb0ef41Sopenharmony_ci  napi_ref* ref = data;
71cb0ef41Sopenharmony_ci  napi_delete_reference(env, *ref);
81cb0ef41Sopenharmony_ci  free(ref);
91cb0ef41Sopenharmony_ci  fprintf(stderr, "addon_free");
101cb0ef41Sopenharmony_ci}
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinapi_value addon_new(napi_env env, napi_value exports, bool ref_first) {
131cb0ef41Sopenharmony_ci  napi_ref* ref = malloc(sizeof(*ref));
141cb0ef41Sopenharmony_ci  if (ref_first) {
151cb0ef41Sopenharmony_ci    napi_create_reference(env, exports, 1, ref);
161cb0ef41Sopenharmony_ci    napi_set_instance_data(env, ref, addon_free, NULL);
171cb0ef41Sopenharmony_ci  } else {
181cb0ef41Sopenharmony_ci    napi_set_instance_data(env, ref, addon_free, NULL);
191cb0ef41Sopenharmony_ci    napi_create_reference(env, exports, 1, ref);
201cb0ef41Sopenharmony_ci  }
211cb0ef41Sopenharmony_ci  return exports;
221cb0ef41Sopenharmony_ci}
23

Indexes created Thu Nov 07 10:32:03 CST 2024