From af62c8fff74574dad93e8f9c4d83b3d2e81a2bad Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Fri, 2 Mar 2018 09:41:12 -0500 Subject: [PATCH] n-api: update reference test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the necessity for allocating on the heap, and assert that the correct pointer gets passed to the finalizer. Backport-PR-URL: https://github.com/nodejs/node/pull/19447 PR-URL: https://github.com/nodejs/node/pull/19086 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Michael Dawson --- test/addons-napi/test_reference/test_reference.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/addons-napi/test_reference/test_reference.c b/test/addons-napi/test_reference/test_reference.c index 9f25eddb313bef..329d1bb18b6a09 100644 --- a/test/addons-napi/test_reference/test_reference.c +++ b/test/addons-napi/test_reference/test_reference.c @@ -1,6 +1,5 @@ #include #include "../common.h" -#include static int test_value = 1; static int finalize_count = 0; @@ -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++; } @@ -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));