node/test/node-api/test_instance_data/addon.c
Gabriel Schulhof c0c81ed204 n-api: define release 6
Mark all N-APIs that have been added since version 5 as stable.

PR-URL: https://github.com/nodejs/node/pull/32058
Fixes: https://github.com/nodejs/abi-stable-node/issues/393
Co-Authored-By: legendecas <legendecas@gmail.com>
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2020-03-09 11:58:51 -07:00

23 lines
611 B
C

#include <stdio.h>
#include <stdlib.h>
#include <node_api.h>
static void addon_free(napi_env env, void* data, void* hint) {
napi_ref* ref = data;
napi_delete_reference(env, *ref);
free(ref);
fprintf(stderr, "addon_free");
}
napi_value addon_new(napi_env env, napi_value exports, bool ref_first) {
napi_ref* ref = malloc(sizeof(*ref));
if (ref_first) {
napi_create_reference(env, exports, 1, ref);
napi_set_instance_data(env, ref, addon_free, NULL);
} else {
napi_set_instance_data(env, ref, addon_free, NULL);
napi_create_reference(env, exports, 1, ref);
}
return exports;
}