Skip to content

Commit b26410e

Browse files
Gabriel SchulhofMylesBorins
authored andcommitted
n-api: update reference test
Remove the necessity for allocating on the heap, and assert that the correct pointer gets passed to the finalizer. Backport-PR-URL: #19265 PR-URL: #19086 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 1abb168 commit b26410e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

‎test/addons-napi/test_reference/test_reference.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include<node_api.h>
22
#include"../common.h"
3-
#include<stdlib.h>
43

54
staticinttest_value=1;
65
staticintfinalize_count=0;
@@ -13,7 +12,9 @@ napi_value GetFinalizeCount(napi_env env, napi_callback_info info){
1312
}
1413

1514
voidFinalizeExternal(napi_envenv, void*data, void*hint){
16-
free(data);
15+
int*actual_value=data;
16+
NAPI_ASSERT_RETURN_VOID(env, actual_value==&test_value,
17+
"The correct pointer was passed to the finalizer");
1718
finalize_count++;
1819
}
1920

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

3536
napi_valueCreateExternalWithFinalize(napi_envenv, napi_callback_infoinfo){
36-
int*data=malloc(sizeof(int));
37-
*data=test_value;
38-
3937
napi_valueresult;
4038
NAPI_CALL(env,
4139
napi_create_external(env,
42-
data,
40+
&test_value,
4341
FinalizeExternal,
4442
NULL, /* finalize_hint */
4543
&result));

0 commit comments

Comments
(0)