Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n-api: update reference test #19086

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions test/addons-napi/test_reference/test_reference.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <node_api.h>
#include "../common.h"
#include <stdlib.h>

static int test_value = 1;
static int finalize_count = 0;
Expand All @@ -13,7 +12,9 @@ napi_value GetFinalizeCount(napi_env env, napi_callback_info info) {
}

void FinalizeExternal(napi_env env, void* data, void* hint) {
free(data);
int *actual_value = data;
NAPI_ASSERT_RETURN_VOID(env, actual_value == &test_value,
"The correct pointer was passed to the finalizer");
finalize_count++;
}

Expand All @@ -33,13 +34,10 @@ napi_value CreateExternal(napi_env env, napi_callback_info info) {
}

napi_value CreateExternalWithFinalize(napi_env env, napi_callback_info info) {
int* data = malloc(sizeof(int));
*data = test_value;

napi_value result;
NAPI_CALL(env,
napi_create_external(env,
data,
&test_value,
FinalizeExternal,
NULL, /* finalize_hint */
&result));
Expand Down