From 19ab28e3752e61681e92adb7c72de033ef719146 Mon Sep 17 00:00:00 2001 From: toyobayashi Date: Sun, 28 Jul 2024 18:05:36 +0800 Subject: [PATCH] refactor: rename nogc to basic (nodejs/node#53830) --- packages/emnapi/include/node/js_native_api.h | 51 ++++++++++--------- .../emnapi/include/node/js_native_api_types.h | 22 ++++---- packages/emnapi/include/node/node_api.h | 26 +++++----- packages/emnapi/src/async_cleanup_hook.c | 2 +- packages/emnapi/src/async_work.c | 4 +- packages/emnapi/src/emnapi_internal.h | 4 +- packages/emnapi/src/js_native_api.c | 3 +- packages/emnapi/src/node_api.c | 6 +-- packages/emnapi/src/threadsafe_function.c | 4 +- packages/test/common.h | 34 ++++++------- packages/test/finalizer/binding.c | 12 ++--- .../test/ref_by_node_api_version/binding.c | 8 +-- packages/test/runjs/binding.c | 15 +++--- packages/test/string/binding.c | 2 +- 14 files changed, 100 insertions(+), 93 deletions(-) diff --git a/packages/emnapi/include/node/js_native_api.h b/packages/emnapi/include/node/js_native_api.h index 681d32c6..d17afa0a 100644 --- a/packages/emnapi/include/node/js_native_api.h +++ b/packages/emnapi/include/node/js_native_api.h @@ -56,7 +56,7 @@ EXTERN_C_START NAPI_EXTERN napi_status NAPI_CDECL napi_get_last_error_info( - node_api_nogc_env env, const napi_extended_error_info** result); + node_api_basic_env env, const napi_extended_error_info** result); // Getters for defined singletons NAPI_EXTERN napi_status NAPI_CDECL napi_get_undefined(napi_env env, @@ -100,19 +100,19 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_string_utf16(napi_env env, napi_value* result); #ifdef NAPI_EXPERIMENTAL #define NODE_API_EXPERIMENTAL_HAS_EXTERNAL_STRINGS -NAPI_EXTERN napi_status NAPI_CDECL -node_api_create_external_string_latin1(napi_env env, - char* str, - size_t length, - node_api_nogc_finalize finalize_callback, - void* finalize_hint, - napi_value* result, - bool* copied); +NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_latin1( + napi_env env, + char* str, + size_t length, + node_api_basic_finalize finalize_callback, + void* finalize_hint, + napi_value* result, + bool* copied); NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_utf16(napi_env env, char16_t* str, size_t length, - node_api_nogc_finalize finalize_callback, + node_api_basic_finalize finalize_callback, void* finalize_hint, napi_value* result, bool* copied); @@ -324,12 +324,13 @@ napi_define_class(napi_env env, napi_value* result); // Methods to work with external data objects -NAPI_EXTERN napi_status NAPI_CDECL napi_wrap(napi_env env, - napi_value js_object, - void* native_object, - node_api_nogc_finalize finalize_cb, - void* finalize_hint, - napi_ref* result); +NAPI_EXTERN napi_status NAPI_CDECL +napi_wrap(napi_env env, + napi_value js_object, + void* native_object, + node_api_basic_finalize finalize_cb, + void* finalize_hint, + napi_ref* result); NAPI_EXTERN napi_status NAPI_CDECL napi_unwrap(napi_env env, napi_value js_object, void** result); @@ -339,7 +340,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_remove_wrap(napi_env env, NAPI_EXTERN napi_status NAPI_CDECL napi_create_external(napi_env env, void* data, - node_api_nogc_finalize finalize_cb, + node_api_basic_finalize finalize_cb, void* finalize_hint, napi_value* result); NAPI_EXTERN napi_status NAPI_CDECL napi_get_value_external(napi_env env, @@ -438,7 +439,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_external_arraybuffer(napi_env env, void* external_data, size_t byte_length, - node_api_nogc_finalize finalize_cb, + node_api_basic_finalize finalize_cb, void* finalize_hint, napi_value* result); #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED @@ -480,7 +481,7 @@ napi_get_dataview_info(napi_env env, size_t* byte_offset); // version management -NAPI_EXTERN napi_status NAPI_CDECL napi_get_version(node_api_nogc_env env, +NAPI_EXTERN napi_status NAPI_CDECL napi_get_version(node_api_basic_env env, uint32_t* result); // Promises @@ -504,7 +505,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_run_script(napi_env env, // Memory management NAPI_EXTERN napi_status NAPI_CDECL napi_adjust_external_memory( - node_api_nogc_env env, int64_t change_in_bytes, int64_t* adjusted_value); + node_api_basic_env env, int64_t change_in_bytes, int64_t* adjusted_value); #if NAPI_VERSION >= 5 @@ -526,7 +527,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_add_finalizer(napi_env env, napi_value js_object, void* finalize_data, - node_api_nogc_finalize finalize_cb, + node_api_basic_finalize finalize_cb, void* finalize_hint, napi_ref* result); @@ -536,7 +537,7 @@ napi_add_finalizer(napi_env env, #define NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER NAPI_EXTERN napi_status NAPI_CDECL -node_api_post_finalizer(node_api_nogc_env env, +node_api_post_finalizer(node_api_basic_env env, napi_finalize finalize_cb, void* finalize_data, void* finalize_hint); @@ -581,13 +582,13 @@ napi_get_all_property_names(napi_env env, // Instance data NAPI_EXTERN napi_status NAPI_CDECL -napi_set_instance_data(node_api_nogc_env env, +napi_set_instance_data(node_api_basic_env env, void* data, napi_finalize finalize_cb, void* finalize_hint); -NAPI_EXTERN napi_status NAPI_CDECL napi_get_instance_data(node_api_nogc_env env, - void** data); +NAPI_EXTERN napi_status NAPI_CDECL +napi_get_instance_data(node_api_basic_env env, void** data); #endif // NAPI_VERSION >= 6 #if NAPI_VERSION >= 7 diff --git a/packages/emnapi/include/node/js_native_api_types.h b/packages/emnapi/include/node/js_native_api_types.h index 7cb5b080..43e7bb77 100644 --- a/packages/emnapi/include/node/js_native_api_types.h +++ b/packages/emnapi/include/node/js_native_api_types.h @@ -27,7 +27,7 @@ typedef struct napi_env__* napi_env; // meaning that they do not affect the state of the JS engine, and can // therefore be called synchronously from a finalizer that itself runs // synchronously during GC. Such APIs can receive either a `napi_env` or a -// `node_api_nogc_env` as their first parameter, because we should be able to +// `node_api_basic_env` as their first parameter, because we should be able to // also call them during normal, non-garbage-collecting operations, whereas // APIs that affect the state of the JS engine can only receive a `napi_env` as // their first parameter, because we must not call them during GC. In lieu of @@ -37,19 +37,21 @@ typedef struct napi_env__* napi_env; // expecting a non-const value. // // In conjunction with appropriate CFLAGS to warn us if we're passing a const -// (nogc) environment into an API that expects a non-const environment, and the -// definition of nogc finalizer function pointer types below, which receive a -// nogc environment as their first parameter, and can thus only call nogc APIs -// (unless the user explicitly casts the environment), we achieve the ability -// to ensure at compile time that we do not call APIs that affect the state of -// the JS engine from a synchronous (nogc) finalizer. +// (basic) environment into an API that expects a non-const environment, and +// the definition of basic finalizer function pointer types below, which +// receive a basic environment as their first parameter, and can thus only call +// basic APIs (unless the user explicitly casts the environment), we achieve +// the ability to ensure at compile time that we do not call APIs that affect +// the state of the JS engine from a synchronous (basic) finalizer. #if !defined(NAPI_EXPERIMENTAL) || \ (defined(NAPI_EXPERIMENTAL) && \ - defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT)) + (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \ + defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT))) typedef struct napi_env__* node_api_nogc_env; #else typedef const struct napi_env__* node_api_nogc_env; #endif +typedef node_api_nogc_env node_api_basic_env; typedef struct napi_value__* napi_value; typedef struct napi_ref__* napi_ref; @@ -147,13 +149,15 @@ typedef void(NAPI_CDECL* napi_finalize)(napi_env env, #if !defined(NAPI_EXPERIMENTAL) || \ (defined(NAPI_EXPERIMENTAL) && \ - defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT)) + (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \ + defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT))) typedef napi_finalize node_api_nogc_finalize; #else typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env, void* finalize_data, void* finalize_hint); #endif +typedef node_api_nogc_finalize node_api_basic_finalize; typedef struct { // One of utf8name or name should be NULL. diff --git a/packages/emnapi/include/node/node_api.h b/packages/emnapi/include/node/node_api.h index 02987473..7fa08bf4 100644 --- a/packages/emnapi/include/node/node_api.h +++ b/packages/emnapi/include/node/node_api.h @@ -141,7 +141,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_external_buffer(napi_env env, size_t length, void* data, - node_api_nogc_finalize finalize_cb, + node_api_basic_finalize finalize_cb, void* finalize_hint, napi_value* result); #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED @@ -169,20 +169,20 @@ napi_create_async_work(napi_env env, napi_async_work* result); NAPI_EXTERN napi_status NAPI_CDECL napi_delete_async_work(napi_env env, napi_async_work work); -NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(node_api_nogc_env env, +NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(node_api_basic_env env, napi_async_work work); -NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(node_api_nogc_env env, - napi_async_work work); +NAPI_EXTERN napi_status NAPI_CDECL +napi_cancel_async_work(node_api_basic_env env, napi_async_work work); // version management -NAPI_EXTERN napi_status NAPI_CDECL -napi_get_node_version(node_api_nogc_env env, const napi_node_version** version); +NAPI_EXTERN napi_status NAPI_CDECL napi_get_node_version( + node_api_basic_env env, const napi_node_version** version); #if NAPI_VERSION >= 2 // Return the current libuv event loop for a given environment NAPI_EXTERN napi_status NAPI_CDECL -napi_get_uv_event_loop(node_api_nogc_env env, struct uv_loop_s** loop); +napi_get_uv_event_loop(node_api_basic_env env, struct uv_loop_s** loop); #endif // NAPI_VERSION >= 2 @@ -192,10 +192,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_fatal_exception(napi_env env, napi_value err); NAPI_EXTERN napi_status NAPI_CDECL napi_add_env_cleanup_hook( - node_api_nogc_env env, napi_cleanup_hook fun, void* arg); + node_api_basic_env env, napi_cleanup_hook fun, void* arg); NAPI_EXTERN napi_status NAPI_CDECL napi_remove_env_cleanup_hook( - node_api_nogc_env env, napi_cleanup_hook fun, void* arg); + node_api_basic_env env, napi_cleanup_hook fun, void* arg); NAPI_EXTERN napi_status NAPI_CDECL napi_open_callback_scope(napi_env env, @@ -239,17 +239,17 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_release_threadsafe_function( napi_threadsafe_function func, napi_threadsafe_function_release_mode mode); NAPI_EXTERN napi_status NAPI_CDECL napi_unref_threadsafe_function( - node_api_nogc_env env, napi_threadsafe_function func); + node_api_basic_env env, napi_threadsafe_function func); NAPI_EXTERN napi_status NAPI_CDECL napi_ref_threadsafe_function( - node_api_nogc_env env, napi_threadsafe_function func); + node_api_basic_env env, napi_threadsafe_function func); #endif // NAPI_VERSION >= 4 #if NAPI_VERSION >= 8 NAPI_EXTERN napi_status NAPI_CDECL -napi_add_async_cleanup_hook(node_api_nogc_env env, +napi_add_async_cleanup_hook(node_api_basic_env env, napi_async_cleanup_hook hook, void* arg, napi_async_cleanup_hook_handle* remove_handle); @@ -262,7 +262,7 @@ napi_remove_async_cleanup_hook(napi_async_cleanup_hook_handle remove_handle); #if NAPI_VERSION >= 9 NAPI_EXTERN napi_status NAPI_CDECL -node_api_get_module_file_name(node_api_nogc_env env, const char** result); +node_api_get_module_file_name(node_api_basic_env env, const char** result); #endif // NAPI_VERSION >= 9 diff --git a/packages/emnapi/src/async_cleanup_hook.c b/packages/emnapi/src/async_cleanup_hook.c index 2d5f6935..e965b736 100644 --- a/packages/emnapi/src/async_cleanup_hook.c +++ b/packages/emnapi/src/async_cleanup_hook.c @@ -101,7 +101,7 @@ _emnapi_ach_handle_delete(napi_async_cleanup_hook_handle handle) { } napi_status -napi_add_async_cleanup_hook(napi_env env, +napi_add_async_cleanup_hook(node_api_basic_env env, napi_async_cleanup_hook hook, void* arg, napi_async_cleanup_hook_handle* remove_handle) { diff --git a/packages/emnapi/src/async_work.c b/packages/emnapi/src/async_work.c index a439b771..91bcba93 100644 --- a/packages/emnapi/src/async_work.c +++ b/packages/emnapi/src/async_work.c @@ -198,7 +198,7 @@ napi_status napi_delete_async_work(napi_env env, napi_async_work work) { #endif } -napi_status napi_queue_async_work(napi_env env, napi_async_work work) { +napi_status napi_queue_async_work(node_api_basic_env env, napi_async_work work) { #if EMNAPI_HAVE_THREADS CHECK_ENV(env); CHECK_ARG(env, work); @@ -220,7 +220,7 @@ napi_status napi_queue_async_work(napi_env env, napi_async_work work) { } \ } while (0) -napi_status napi_cancel_async_work(napi_env env, napi_async_work work) { +napi_status napi_cancel_async_work(node_api_basic_env env, napi_async_work work) { #if EMNAPI_HAVE_THREADS CHECK_ENV(env); CHECK_ARG(env, work); diff --git a/packages/emnapi/src/emnapi_internal.h b/packages/emnapi/src/emnapi_internal.h index 1901047a..8eec580d 100644 --- a/packages/emnapi/src/emnapi_internal.h +++ b/packages/emnapi/src/emnapi_internal.h @@ -72,11 +72,11 @@ EXTERN_C_END EXTERN_C_START -EMNAPI_INTERNAL_EXTERN napi_status napi_set_last_error(node_api_nogc_env env, +EMNAPI_INTERNAL_EXTERN napi_status napi_set_last_error(node_api_basic_env env, napi_status error_code, uint32_t engine_error_code, void* engine_reserved); -EMNAPI_INTERNAL_EXTERN napi_status napi_clear_last_error(node_api_nogc_env env); +EMNAPI_INTERNAL_EXTERN napi_status napi_clear_last_error(node_api_basic_env env); #ifdef __EMSCRIPTEN__ #if __EMSCRIPTEN_major__ * 10000 + __EMSCRIPTEN_minor__ * 100 + __EMSCRIPTEN_tiny__ >= 30114 // NOLINT diff --git a/packages/emnapi/src/js_native_api.c b/packages/emnapi/src/js_native_api.c index bbaf2087..0aa38ce8 100644 --- a/packages/emnapi/src/js_native_api.c +++ b/packages/emnapi/src/js_native_api.c @@ -35,8 +35,9 @@ EMNAPI_INTERNAL_EXTERN void _emnapi_get_last_error_info(napi_env env, void** engine_reserved); napi_status napi_get_last_error_info( - napi_env env, const napi_extended_error_info** result) { + node_api_basic_env basic_env, const napi_extended_error_info** result) { static napi_extended_error_info last_error; + napi_env env = (napi_env) basic_env; CHECK_ENV(env); CHECK_ARG(env, result); diff --git a/packages/emnapi/src/node_api.c b/packages/emnapi/src/node_api.c index c48744a6..69216ab8 100644 --- a/packages/emnapi/src/node_api.c +++ b/packages/emnapi/src/node_api.c @@ -12,7 +12,7 @@ EMNAPI_INTERNAL_EXTERN void _emnapi_get_node_version(uint32_t* major, uint32_t* patch); napi_status -napi_get_node_version(napi_env env, +napi_get_node_version(node_api_basic_env env, const napi_node_version** version) { CHECK_ENV(env); CHECK_ARG(env, version); @@ -29,7 +29,7 @@ napi_get_node_version(napi_env env, return napi_clear_last_error(env); } -napi_status napi_get_uv_event_loop(napi_env env, +napi_status napi_get_uv_event_loop(node_api_basic_env env, struct uv_loop_s** loop) { #if EMNAPI_HAVE_THREADS CHECK_ENV(env); @@ -44,7 +44,7 @@ napi_status napi_get_uv_event_loop(napi_env env, EMNAPI_INTERNAL_EXTERN int _emnapi_get_filename(napi_env env, char* buf, int len); -napi_status node_api_get_module_file_name(napi_env env, +napi_status node_api_get_module_file_name(node_api_basic_env env, const char** result) { CHECK_ENV(env); CHECK_ARG(env, result); diff --git a/packages/emnapi/src/threadsafe_function.c b/packages/emnapi/src/threadsafe_function.c index 6ac0e298..3637d0d3 100644 --- a/packages/emnapi/src/threadsafe_function.c +++ b/packages/emnapi/src/threadsafe_function.c @@ -584,7 +584,7 @@ napi_release_threadsafe_function(napi_threadsafe_function func, } napi_status -napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func) { +napi_unref_threadsafe_function(node_api_basic_env env, napi_threadsafe_function func) { #if EMNAPI_HAVE_THREADS if (func->async_ref) { EMNAPI_KEEPALIVE_POP(); @@ -598,7 +598,7 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func) { } napi_status -napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func) { +napi_ref_threadsafe_function(node_api_basic_env env, napi_threadsafe_function func) { #if EMNAPI_HAVE_THREADS if (!func->async_ref) { EMNAPI_KEEPALIVE_PUSH(); diff --git a/packages/test/common.h b/packages/test/common.h index ff370c6f..30f7e547 100644 --- a/packages/test/common.h +++ b/packages/test/common.h @@ -24,7 +24,7 @@ void console_error(const char* fmt, const char* str); const napi_extended_error_info *error_info; \ napi_get_last_error_info((env), &error_info); \ bool is_pending; \ - const char* err_message = error_info->error_message; \ + const char* err_message = error_info->error_message; \ napi_is_exception_pending((env), &is_pending); \ /* If an exception is already pending, don't rethrow it */ \ if (!is_pending) { \ @@ -35,7 +35,7 @@ void console_error(const char* fmt, const char* str); } \ } while (0) -// The nogc version of GET_AND_THROW_LAST_ERROR. We cannot access any +// The basic version of GET_AND_THROW_LAST_ERROR. We cannot access any // exceptions and we cannot fail by way of JS exception, so we abort. #define FATALLY_FAIL_WITH_LAST_ERROR(env) \ do { \ @@ -44,7 +44,7 @@ void console_error(const char* fmt, const char* str); const char* err_message = error_info->error_message; \ const char* error_message = \ err_message != NULL ? err_message : "empty error message"; \ - EPRINT(error_message); \ + fprintf(stderr, "%s\n", error_message); \ abort(); \ } while (0) @@ -59,10 +59,10 @@ void console_error(const char* fmt, const char* str); } \ } while (0) -#define NODE_API_NOGC_ASSERT_BASE(assertion, message, ret_val) \ +#define NODE_API_BASIC_ASSERT_BASE(assertion, message, ret_val) \ do { \ if (!(assertion)) { \ - EPRINT("assertion (" #assertion ") failed: " message); \ + fprintf(stderr, "assertion (" #assertion ") failed: " message); \ abort(); \ return ret_val; \ } \ @@ -78,8 +78,8 @@ void console_error(const char* fmt, const char* str); #define NODE_API_ASSERT_RETURN_VOID(env, assertion, message) \ NODE_API_ASSERT_BASE(env, assertion, message, NODE_API_RETVAL_NOTHING) -#define NODE_API_NOGC_ASSERT_RETURN_VOID(assertion, message) \ - NODE_API_NOGC_ASSERT_BASE(assertion, message, NODE_API_RETVAL_NOTHING) +#define NODE_API_BASIC_ASSERT_RETURN_VOID(assertion, message) \ + NODE_API_BASIC_ASSERT_BASE(assertion, message, NODE_API_RETVAL_NOTHING) #define NODE_API_CALL_BASE(env, the_call, ret_val) \ do { \ @@ -89,7 +89,7 @@ void console_error(const char* fmt, const char* str); } \ } while (0) -#define NODE_API_NOGC_CALL_BASE(env, the_call, ret_val) \ +#define NODE_API_BASIC_CALL_BASE(env, the_call, ret_val) \ do { \ if ((the_call) != napi_ok) { \ FATALLY_FAIL_WITH_LAST_ERROR((env)); \ @@ -105,18 +105,18 @@ void console_error(const char* fmt, const char* str); #define NODE_API_CALL_RETURN_VOID(env, the_call) \ NODE_API_CALL_BASE(env, the_call, NODE_API_RETVAL_NOTHING) -#define NODE_API_NOGC_CALL_RETURN_VOID(env, the_call) \ - NODE_API_NOGC_CALL_BASE(env, the_call, NODE_API_RETVAL_NOTHING) +#define NODE_API_BASIC_CALL_RETURN_VOID(env, the_call) \ + NODE_API_BASIC_CALL_BASE(env, the_call, NODE_API_RETVAL_NOTHING) -#define NODE_API_CHECK_STATUS(the_call) \ - do { \ - napi_status status = (the_call); \ - if (status != napi_ok) { \ - return status; \ - } \ +#define NODE_API_CHECK_STATUS(the_call) \ + do { \ + napi_status status = (the_call); \ + if (status != napi_ok) { \ + return status; \ + } \ } while (0) -#define NODE_API_ASSERT_STATUS(env, assertion, message) \ +#define NODE_API_ASSERT_STATUS(env, assertion, message) \ NODE_API_ASSERT_BASE(env, assertion, message, napi_generic_failure) #define DECLARE_NODE_API_PROPERTY(name, func) \ diff --git a/packages/test/finalizer/binding.c b/packages/test/finalizer/binding.c index 8326ccbd..1ef32676 100644 --- a/packages/test/finalizer/binding.c +++ b/packages/test/finalizer/binding.c @@ -18,16 +18,16 @@ typedef struct { napi_ref js_func; } FinalizerData; -static void finalizerOnlyCallback(node_api_nogc_env env, +static void finalizerOnlyCallback(node_api_basic_env env, void* finalize_data, void* finalize_hint) { FinalizerData* data = (FinalizerData*)finalize_data; int32_t count = ++data->finalize_count; // It is safe to access instance data - NODE_API_NOGC_CALL_RETURN_VOID(env, + NODE_API_BASIC_CALL_RETURN_VOID(env, napi_get_instance_data(env, (void**)&data)); - NODE_API_NOGC_ASSERT_RETURN_VOID(count = data->finalize_count, + NODE_API_BASIC_ASSERT_RETURN_VOID(count = data->finalize_count, "Expected to be the same FinalizerData"); } @@ -47,16 +47,16 @@ static void finalizerCallingJSCallback(napi_env env, } // Schedule async finalizer to run JavaScript-touching code. -static void finalizerWithJSCallback(node_api_nogc_env env, +static void finalizerWithJSCallback(node_api_basic_env env, void* finalize_data, void* finalize_hint) { - NODE_API_NOGC_CALL_RETURN_VOID( + NODE_API_BASIC_CALL_RETURN_VOID( env, node_api_post_finalizer( env, finalizerCallingJSCallback, finalize_data, finalize_hint)); } -static void finalizerWithFailedJSCallback(node_api_nogc_env nogc_env, +static void finalizerWithFailedJSCallback(node_api_basic_env nogc_env, void* finalize_data, void* finalize_hint) { // Intentionally cast to a napi_env to test the fatal failure. diff --git a/packages/test/ref_by_node_api_version/binding.c b/packages/test/ref_by_node_api_version/binding.c index cd289310..0105450c 100644 --- a/packages/test/ref_by_node_api_version/binding.c +++ b/packages/test/ref_by_node_api_version/binding.c @@ -9,12 +9,12 @@ void free(void* p); static uint32_t finalizeCount = 0; -static void FreeData(node_api_nogc_env env, void* data, void* hint) { - NODE_API_NOGC_ASSERT_RETURN_VOID(data != NULL, "Expects non-NULL data."); +static void FreeData(node_api_basic_env env, void* data, void* hint) { + NODE_API_BASIC_ASSERT_RETURN_VOID(data != NULL, "Expects non-NULL data."); free(data); } -static void Finalize(node_api_nogc_env env, void* data, void* hint) { +static void Finalize(node_api_basic_env env, void* data, void* hint) { ++finalizeCount; } @@ -63,7 +63,7 @@ static napi_value ToUInt32Value(napi_env env, uint32_t value) { return result; } -static napi_status InitRefArray(node_api_nogc_env env) { +static napi_status InitRefArray(node_api_basic_env env) { // valueRefs array has one entry per napi_valuetype napi_ref* valueRefs = malloc(sizeof(napi_ref) * ((int)napi_bigint + 1)); return napi_set_instance_data(env, valueRefs, (napi_finalize)&FreeData, NULL); diff --git a/packages/test/runjs/binding.c b/packages/test/runjs/binding.c index ee5daf52..919d1d1e 100644 --- a/packages/test/runjs/binding.c +++ b/packages/test/runjs/binding.c @@ -12,10 +12,10 @@ static void Finalize(napi_env env, void* data, void* hint) { napi_value global, set_timeout; napi_ref* ref = data; - NODE_API_NOGC_ASSERT_RETURN_VOID( + NODE_API_BASIC_ASSERT_RETURN_VOID( napi_delete_reference(env, *ref) == napi_ok, "deleting reference in finalizer should succeed"); - NODE_API_NOGC_ASSERT_RETURN_VOID( + NODE_API_BASIC_ASSERT_RETURN_VOID( napi_get_global(env, &global) == napi_ok, "getting global reference in finalizer should succeed"); napi_status result = @@ -27,12 +27,12 @@ static void Finalize(napi_env env, void* data, void* hint) { // napi_pending_exception is returned). This is not deterministic from // the point of view of the addon. #ifdef NAPI_EXPERIMENTAL - NODE_API_NOGC_ASSERT_RETURN_VOID( + NODE_API_BASIC_ASSERT_RETURN_VOID( result == napi_cannot_run_js || result == napi_ok, "getting named property from global in finalizer should succeed " "or return napi_cannot_run_js"); #else - NODE_API_NOGC_ASSERT_RETURN_VOID( + NODE_API_BASIC_ASSERT_RETURN_VOID( result == napi_pending_exception || result == napi_ok, "getting named property from global in finalizer should succeed " "or return napi_pending_exception"); @@ -40,9 +40,9 @@ static void Finalize(napi_env env, void* data, void* hint) { free(ref); } -static void NogcFinalize(node_api_nogc_env env, void* data, void* hint) { +static void BasicFinalize(node_api_basic_env env, void* data, void* hint) { #ifdef NAPI_EXPERIMENTAL - NODE_API_NOGC_CALL_RETURN_VOID( + NODE_API_BASIC_CALL_RETURN_VOID( env, node_api_post_finalizer(env, Finalize, data, hint)); #else Finalize(env, data, hint); @@ -59,7 +59,8 @@ static napi_value CreateRef(napi_env env, napi_callback_info info) { NODE_API_CALL(env, napi_typeof(env, cb, &value_type)); NODE_API_ASSERT( env, value_type == napi_function, "argument must be function"); - NODE_API_CALL(env, napi_add_finalizer(env, cb, ref, NogcFinalize, NULL, ref)); + NODE_API_CALL(env, + napi_add_finalizer(env, cb, ref, BasicFinalize, NULL, ref)); return cb; } diff --git a/packages/test/string/binding.c b/packages/test/string/binding.c index 95108c98..588cbe7a 100644 --- a/packages/test/string/binding.c +++ b/packages/test/string/binding.c @@ -111,7 +111,7 @@ static napi_value TestTwoByteImpl(napi_env env, return output; } -static void free_string(node_api_nogc_env env, void* data, void* hint) { +static void free_string(node_api_basic_env env, void* data, void* hint) { free(data); }