diff --git a/benchmark/napi/ref/addon.c b/benchmark/napi/ref/addon.c index 2a7d3c8b2df23e..bced905cab8bc6 100644 --- a/benchmark/napi/ref/addon.c +++ b/benchmark/napi/ref/addon.c @@ -33,7 +33,7 @@ SetCount(napi_env env, napi_callback_info info) { return NULL; } -static void IncrementCounter(node_api_nogc_env env, void* data, void* hint) { +static void IncrementCounter(node_api_basic_env env, void* data, void* hint) { size_t* count = data; (*count) = (*count) + 1; } diff --git a/doc/api/n-api.md b/doc/api/n-api.md index e0f91e6673be80..ac38710303ff8c 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -477,7 +477,7 @@ napiVersion: 6 --> ```c -napi_status napi_set_instance_data(node_api_nogc_env env, +napi_status napi_set_instance_data(node_api_basic_env env, void* data, napi_finalize finalize_cb, void* finalize_hint); @@ -509,7 +509,7 @@ napiVersion: 6 --> ```c -napi_status napi_get_instance_data(node_api_nogc_env env, +napi_status napi_get_instance_data(node_api_basic_env env, void** data); ``` @@ -611,16 +611,16 @@ when an instance of a native addon is unloaded. Notification of this event is delivered through the callbacks given to [`napi_add_env_cleanup_hook`][] and [`napi_set_instance_data`][]. -### `node_api_nogc_env` +### `node_api_basic_env` > Stability: 1 - Experimental This variant of `napi_env` is passed to synchronous finalizers -([`node_api_nogc_finalize`][]). There is a subset of Node-APIs which accept -a parameter of type `node_api_nogc_env` as their first argument. These APIs do +([`node_api_basic_finalize`][]). There is a subset of Node-APIs which accept +a parameter of type `node_api_basic_env` as their first argument. These APIs do not access the state of the JavaScript engine and are thus safe to call from synchronous finalizers. Passing a parameter of type `napi_env` to these APIs is -allowed, however, passing a parameter of type `node_api_nogc_env` to APIs that +allowed, however, passing a parameter of type `node_api_basic_env` to APIs that access the JavaScript engine state is not allowed. Attempting to do so without a cast will produce a compiler warning or an error when add-ons are compiled with flags which cause them to emit warnings and/or errors when incorrect @@ -791,7 +791,7 @@ typedef napi_value (*napi_callback)(napi_env, napi_callback_info); Unless for reasons discussed in [Object Lifetime Management][], creating a handle and/or callback scope inside a `napi_callback` is not necessary. -#### `node_api_nogc_finalize` +#### `node_api_basic_finalize` ```c -NODE_EXTERN napi_status napi_add_env_cleanup_hook(node_api_nogc_env env, +NODE_EXTERN napi_status napi_add_env_cleanup_hook(node_api_basic_env env, napi_cleanup_hook fun, void* arg); ``` @@ -1912,7 +1912,7 @@ napiVersion: 3 --> ```c -NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(node_api_nogc_env env, +NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(node_api_basic_env env, void (*fun)(void* arg), void* arg); ``` @@ -1941,7 +1941,7 @@ changes: ```c NAPI_EXTERN napi_status napi_add_async_cleanup_hook( - node_api_nogc_env env, + node_api_basic_env env, napi_async_cleanup_hook hook, void* arg, napi_async_cleanup_hook_handle* remove_handle); @@ -5524,7 +5524,7 @@ napiVersion: 5 napi_status 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); ``` @@ -5562,7 +5562,7 @@ added: v20.10.0 > Stability: 1 - Experimental ```c -napi_status node_api_post_finalizer(node_api_nogc_env env, +napi_status node_api_post_finalizer(node_api_basic_env env, napi_finalize finalize_cb, void* finalize_data, void* finalize_hint); @@ -5632,7 +5632,7 @@ Once created the async worker can be queued for execution using the [`napi_queue_async_work`][] function: ```c -napi_status napi_queue_async_work(node_api_nogc_env env, +napi_status napi_queue_async_work(node_api_basic_env env, napi_async_work work); ``` @@ -5724,7 +5724,7 @@ napiVersion: 1 --> ```c -napi_status napi_queue_async_work(node_api_nogc_env env, +napi_status napi_queue_async_work(node_api_basic_env env, napi_async_work work); ``` @@ -5745,7 +5745,7 @@ napiVersion: 1 --> ```c -napi_status napi_cancel_async_work(node_api_nogc_env env, +napi_status napi_cancel_async_work(node_api_basic_env env, napi_async_work work); ``` @@ -5949,7 +5949,7 @@ typedef struct { const char* release; } napi_node_version; -napi_status napi_get_node_version(node_api_nogc_env env, +napi_status napi_get_node_version(node_api_basic_env env, const napi_node_version** version); ``` @@ -5972,7 +5972,7 @@ napiVersion: 1 --> ```c -napi_status napi_get_version(node_api_nogc_env env, +napi_status napi_get_version(node_api_basic_env env, uint32_t* result); ``` @@ -6005,7 +6005,7 @@ napiVersion: 1 --> ```c -NAPI_EXTERN napi_status napi_adjust_external_memory(node_api_nogc_env env, +NAPI_EXTERN napi_status napi_adjust_external_memory(node_api_basic_env env, int64_t change_in_bytes, int64_t* result); ``` @@ -6222,7 +6222,7 @@ napiVersion: 2 --> ```c -NAPI_EXTERN napi_status napi_get_uv_event_loop(node_api_nogc_env env, +NAPI_EXTERN napi_status napi_get_uv_event_loop(node_api_basic_env env, struct uv_loop_s** loop); ``` @@ -6542,7 +6542,7 @@ napiVersion: 4 ```c NAPI_EXTERN napi_status -napi_ref_threadsafe_function(node_api_nogc_env env, napi_threadsafe_function func); +napi_ref_threadsafe_function(node_api_basic_env env, napi_threadsafe_function func); ``` * `[in] env`: The environment that the API is invoked under. @@ -6568,7 +6568,7 @@ napiVersion: 4 ```c NAPI_EXTERN napi_status -napi_unref_threadsafe_function(node_api_nogc_env env, napi_threadsafe_function func); +napi_unref_threadsafe_function(node_api_basic_env env, napi_threadsafe_function func); ``` * `[in] env`: The environment that the API is invoked under. @@ -6594,7 +6594,7 @@ napiVersion: 9 ```c NAPI_EXTERN napi_status -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); ``` @@ -6719,10 +6719,10 @@ the add-on's file name during loading. [`napi_wrap`]: #napi_wrap [`node-addon-api`]: https://github.com/nodejs/node-addon-api [`node_api.h`]: https://github.com/nodejs/node/blob/HEAD/src/node_api.h +[`node_api_basic_finalize`]: #node_api_basic_finalize [`node_api_create_external_string_latin1`]: #node_api_create_external_string_latin1 [`node_api_create_external_string_utf16`]: #node_api_create_external_string_utf16 [`node_api_create_syntax_error`]: #node_api_create_syntax_error -[`node_api_nogc_finalize`]: #node_api_nogc_finalize [`node_api_post_finalizer`]: #node_api_post_finalizer [`node_api_throw_syntax_error`]: #node_api_throw_syntax_error [`process.release`]: process.md#processrelease diff --git a/src/js_native_api.h b/src/js_native_api.h index c5114651dc6b00..1558a9f996a069 100644 --- a/src/js_native_api.h +++ b/src/js_native_api.h @@ -50,7 +50,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, @@ -94,19 +94,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); @@ -318,12 +318,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); @@ -333,7 +334,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, @@ -432,7 +433,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 @@ -474,7 +475,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 @@ -498,7 +499,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 @@ -520,7 +521,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); @@ -530,7 +531,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); @@ -575,13 +576,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/src/js_native_api_types.h b/src/js_native_api_types.h index 7cb5b080cc377a..43e7bb77ff94e7 100644 --- a/src/js_native_api_types.h +++ b/src/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/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 4a536c5c55098e..e3529f5b84f8c7 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -909,8 +909,8 @@ static const char* error_messages[] = { }; napi_status NAPI_CDECL napi_get_last_error_info( - node_api_nogc_env nogc_env, const napi_extended_error_info** result) { - napi_env env = const_cast(nogc_env); + node_api_basic_env basic_env, const napi_extended_error_info** result) { + napi_env env = const_cast(basic_env); CHECK_ENV(env); CHECK_ARG(env, result); @@ -1655,12 +1655,12 @@ napi_status NAPI_CDECL node_api_create_external_string_latin1( napi_env env, char* str, size_t length, - node_api_nogc_finalize nogc_finalize_callback, + node_api_basic_finalize basic_finalize_callback, void* finalize_hint, napi_value* result, bool* copied) { napi_finalize finalize_callback = - reinterpret_cast(nogc_finalize_callback); + reinterpret_cast(basic_finalize_callback); return v8impl::NewExternalString( env, str, @@ -1684,12 +1684,12 @@ napi_status NAPI_CDECL node_api_create_external_string_utf16( napi_env env, char16_t* str, size_t length, - node_api_nogc_finalize nogc_finalize_callback, + node_api_basic_finalize basic_finalize_callback, void* finalize_hint, napi_value* result, bool* copied) { napi_finalize finalize_callback = - reinterpret_cast(nogc_finalize_callback); + reinterpret_cast(basic_finalize_callback); return v8impl::NewExternalString( env, str, @@ -2567,10 +2567,11 @@ GEN_COERCE_FUNCTION(STRING, String, string) napi_status NAPI_CDECL napi_wrap(napi_env env, napi_value js_object, void* native_object, - node_api_nogc_finalize nogc_finalize_cb, + node_api_basic_finalize basic_finalize_cb, void* finalize_hint, napi_ref* result) { - napi_finalize finalize_cb = reinterpret_cast(nogc_finalize_cb); + napi_finalize finalize_cb = + reinterpret_cast(basic_finalize_cb); return v8impl::Wrap( env, js_object, native_object, finalize_cb, finalize_hint, result); } @@ -2590,10 +2591,11 @@ napi_status NAPI_CDECL napi_remove_wrap(napi_env env, napi_status NAPI_CDECL napi_create_external(napi_env env, void* data, - node_api_nogc_finalize nogc_finalize_cb, + node_api_basic_finalize basic_finalize_cb, void* finalize_hint, napi_value* result) { - napi_finalize finalize_cb = reinterpret_cast(nogc_finalize_cb); + napi_finalize finalize_cb = + reinterpret_cast(basic_finalize_cb); NAPI_PREAMBLE(env); CHECK_ARG(env, result); @@ -3034,7 +3036,7 @@ 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) { // The API contract here is that the cleanup function runs on the JS thread, @@ -3299,7 +3301,7 @@ napi_status NAPI_CDECL napi_get_dataview_info(napi_env env, return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_get_version(node_api_nogc_env env, +napi_status NAPI_CDECL napi_get_version(node_api_basic_env env, uint32_t* result) { CHECK_ENV(env); CHECK_ARG(env, result); @@ -3421,12 +3423,13 @@ napi_status NAPI_CDECL napi_add_finalizer(napi_env env, napi_value js_object, void* finalize_data, - node_api_nogc_finalize nogc_finalize_cb, + node_api_basic_finalize basic_finalize_cb, void* finalize_hint, napi_ref* result) { // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw // JS exceptions. - napi_finalize finalize_cb = reinterpret_cast(nogc_finalize_cb); + napi_finalize finalize_cb = + reinterpret_cast(basic_finalize_cb); CHECK_ENV_NOT_IN_GC(env); CHECK_ARG(env, js_object); CHECK_ARG(env, finalize_cb); @@ -3450,11 +3453,11 @@ napi_add_finalizer(napi_env env, #ifdef NAPI_EXPERIMENTAL -napi_status NAPI_CDECL node_api_post_finalizer(node_api_nogc_env nogc_env, +napi_status NAPI_CDECL node_api_post_finalizer(node_api_basic_env basic_env, napi_finalize finalize_cb, void* finalize_data, void* finalize_hint) { - napi_env env = const_cast(nogc_env); + napi_env env = const_cast(basic_env); CHECK_ENV(env); env->EnqueueFinalizer(v8impl::TrackedFinalizer::New( env, finalize_cb, finalize_data, finalize_hint)); @@ -3463,7 +3466,7 @@ napi_status NAPI_CDECL node_api_post_finalizer(node_api_nogc_env nogc_env, #endif -napi_status NAPI_CDECL napi_adjust_external_memory(node_api_nogc_env env, +napi_status NAPI_CDECL napi_adjust_external_memory(node_api_basic_env env, int64_t change_in_bytes, int64_t* adjusted_value) { CHECK_ENV(env); @@ -3475,11 +3478,11 @@ napi_status NAPI_CDECL napi_adjust_external_memory(node_api_nogc_env env, return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_set_instance_data(node_api_nogc_env nogc_env, +napi_status NAPI_CDECL napi_set_instance_data(node_api_basic_env basic_env, void* data, napi_finalize finalize_cb, void* finalize_hint) { - napi_env env = const_cast(nogc_env); + napi_env env = const_cast(basic_env); CHECK_ENV(env); v8impl::RefBase* old_data = static_cast(env->instance_data); @@ -3495,7 +3498,7 @@ napi_status NAPI_CDECL napi_set_instance_data(node_api_nogc_env nogc_env, return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_get_instance_data(node_api_nogc_env env, +napi_status NAPI_CDECL napi_get_instance_data(node_api_basic_env env, void** data) { CHECK_ENV(env); CHECK_ARG(env, data); diff --git a/src/js_native_api_v8.h b/src/js_native_api_v8.h index 1974c3f6873ef7..1817226b2daac4 100644 --- a/src/js_native_api_v8.h +++ b/src/js_native_api_v8.h @@ -4,7 +4,7 @@ #include "js_native_api_types.h" #include "js_native_api_v8_internals.h" -inline napi_status napi_clear_last_error(node_api_nogc_env env); +inline napi_status napi_clear_last_error(node_api_basic_env env); namespace v8impl { @@ -172,8 +172,8 @@ struct napi_env__ { virtual ~napi_env__() = default; }; -inline napi_status napi_clear_last_error(node_api_nogc_env nogc_env) { - napi_env env = const_cast(nogc_env); +inline napi_status napi_clear_last_error(node_api_basic_env basic_env) { + napi_env env = const_cast(basic_env); env->last_error.error_code = napi_ok; env->last_error.engine_error_code = 0; env->last_error.engine_reserved = nullptr; @@ -181,11 +181,11 @@ inline napi_status napi_clear_last_error(node_api_nogc_env nogc_env) { return napi_ok; } -inline napi_status napi_set_last_error(node_api_nogc_env nogc_env, +inline napi_status napi_set_last_error(node_api_basic_env basic_env, napi_status error_code, uint32_t engine_error_code = 0, void* engine_reserved = nullptr) { - napi_env env = const_cast(nogc_env); + napi_env env = const_cast(basic_env); env->last_error.error_code = error_code; env->last_error.engine_error_code = engine_error_code; env->last_error.engine_reserved = engine_reserved; diff --git a/src/node_api.cc b/src/node_api.cc index b79b4dd1d01db3..1bfb246ac75396 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -764,7 +764,7 @@ void NAPI_CDECL napi_module_register(napi_module* mod) { node::node_module_register(nm); } -napi_status NAPI_CDECL napi_add_env_cleanup_hook(node_api_nogc_env env, +napi_status NAPI_CDECL napi_add_env_cleanup_hook(node_api_basic_env env, napi_cleanup_hook fun, void* arg) { CHECK_ENV(env); @@ -775,7 +775,7 @@ napi_status NAPI_CDECL napi_add_env_cleanup_hook(node_api_nogc_env env, return napi_ok; } -napi_status NAPI_CDECL napi_remove_env_cleanup_hook(node_api_nogc_env env, +napi_status NAPI_CDECL napi_remove_env_cleanup_hook(node_api_basic_env env, napi_cleanup_hook fun, void* arg) { CHECK_ENV(env); @@ -822,11 +822,11 @@ struct napi_async_cleanup_hook_handle__ { }; napi_status NAPI_CDECL -napi_add_async_cleanup_hook(node_api_nogc_env nogc_env, +napi_add_async_cleanup_hook(node_api_basic_env basic_env, napi_async_cleanup_hook hook, void* arg, napi_async_cleanup_hook_handle* remove_handle) { - napi_env env = const_cast(nogc_env); + napi_env env = const_cast(basic_env); CHECK_ENV(env); CHECK_ARG(env, hook); @@ -1041,10 +1041,11 @@ napi_status NAPI_CDECL napi_create_external_buffer(napi_env env, size_t length, void* data, - node_api_nogc_finalize nogc_finalize_cb, + node_api_basic_finalize basic_finalize_cb, void* finalize_hint, napi_value* result) { - napi_finalize finalize_cb = reinterpret_cast(nogc_finalize_cb); + napi_finalize finalize_cb = + reinterpret_cast(basic_finalize_cb); NAPI_PREAMBLE(env); CHECK_ARG(env, result); @@ -1130,7 +1131,7 @@ napi_status NAPI_CDECL napi_get_buffer_info(napi_env env, return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_get_node_version(node_api_nogc_env env, +napi_status NAPI_CDECL napi_get_node_version(node_api_basic_env env, const napi_node_version** result) { CHECK_ENV(env); CHECK_ARG(env, result); @@ -1274,16 +1275,16 @@ napi_status NAPI_CDECL napi_delete_async_work(napi_env env, return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_get_uv_event_loop(node_api_nogc_env nogc_env, +napi_status NAPI_CDECL napi_get_uv_event_loop(node_api_basic_env basic_env, uv_loop_t** loop) { - napi_env env = const_cast(nogc_env); + napi_env env = const_cast(basic_env); CHECK_ENV(env); CHECK_ARG(env, loop); *loop = reinterpret_cast(env)->node_env()->event_loop(); return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_queue_async_work(node_api_nogc_env env, +napi_status NAPI_CDECL napi_queue_async_work(node_api_basic_env env, napi_async_work work) { CHECK_ENV(env); CHECK_ARG(env, work); @@ -1298,7 +1299,7 @@ napi_status NAPI_CDECL napi_queue_async_work(node_api_nogc_env env, return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_cancel_async_work(node_api_nogc_env env, +napi_status NAPI_CDECL napi_cancel_async_work(node_api_basic_env env, napi_async_work work) { CHECK_ENV(env); CHECK_ARG(env, work); @@ -1404,20 +1405,20 @@ napi_status NAPI_CDECL napi_release_threadsafe_function( } 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) { CHECK_NOT_NULL(func); return reinterpret_cast(func)->Unref(); } 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) { CHECK_NOT_NULL(func); return reinterpret_cast(func)->Ref(); } -napi_status NAPI_CDECL node_api_get_module_file_name(node_api_nogc_env nogc_env, - const char** result) { - napi_env env = const_cast(nogc_env); +napi_status NAPI_CDECL node_api_get_module_file_name( + node_api_basic_env basic_env, const char** result) { + napi_env env = const_cast(basic_env); CHECK_ENV(env); CHECK_ARG(env, result); diff --git a/src/node_api.h b/src/node_api.h index e94ee486392840..526cdd5d406eb6 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -131,7 +131,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 @@ -159,20 +159,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 @@ -182,10 +182,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, @@ -229,17 +229,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); @@ -252,7 +252,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/test/js-native-api/common.h b/test/js-native-api/common.h index 1308088e7872fb..49cdc066ea6f34 100644 --- a/test/js-native-api/common.h +++ b/test/js-native-api/common.h @@ -23,7 +23,7 @@ } \ } 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 { \ @@ -47,7 +47,7 @@ } \ } 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)) { \ fprintf(stderr, "assertion (" #assertion ") failed: " message); \ @@ -66,8 +66,8 @@ #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 { \ @@ -77,7 +77,7 @@ } \ } 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)); \ @@ -93,8 +93,8 @@ #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 { \ diff --git a/test/js-native-api/test_cannot_run_js/test_cannot_run_js.c b/test/js-native-api/test_cannot_run_js/test_cannot_run_js.c index 813e59918e7b3a..9a4b9547493505 100644 --- a/test/js-native-api/test_cannot_run_js/test_cannot_run_js.c +++ b/test/js-native-api/test_cannot_run_js/test_cannot_run_js.c @@ -7,10 +7,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 = @@ -23,12 +23,12 @@ static void Finalize(napi_env env, void* data, void* hint) { // 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"); @@ -36,9 +36,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); @@ -55,7 +55,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/test/js-native-api/test_finalizer/test_finalizer.c b/test/js-native-api/test_finalizer/test_finalizer.c index b9b046484a5288..721ca12c7bb9dc 100644 --- a/test/js-native-api/test_finalizer/test_finalizer.c +++ b/test/js-native-api/test_finalizer/test_finalizer.c @@ -11,17 +11,17 @@ 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, - napi_get_instance_data(env, (void**)&data)); - NODE_API_NOGC_ASSERT_RETURN_VOID(count = data->finalize_count, - "Expected to be the same FinalizerData"); + NODE_API_BASIC_CALL_RETURN_VOID(env, + napi_get_instance_data(env, (void**)&data)); + NODE_API_BASIC_ASSERT_RETURN_VOID(count = data->finalize_count, + "Expected to be the same FinalizerData"); } static void finalizerCallingJSCallback(napi_env env, @@ -40,20 +40,20 @@ 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 basic_env, void* finalize_data, void* finalize_hint) { // Intentionally cast to a napi_env to test the fatal failure. - napi_env env = (napi_env)nogc_env; + napi_env env = (napi_env)basic_env; napi_value obj; FinalizerData* data = (FinalizerData*)finalize_data; ++data->finalize_count; diff --git a/test/js-native-api/test_string/test_string.c b/test/js-native-api/test_string/test_string.c index 48d70bedde554b..57353b9f6303f2 100644 --- a/test/js-native-api/test_string/test_string.c +++ b/test/js-native-api/test_string/test_string.c @@ -87,7 +87,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); } diff --git a/test/node-api/test_reference_by_node_api_version/test_reference_by_node_api_version.c b/test/node-api/test_reference_by_node_api_version/test_reference_by_node_api_version.c index f9110303d2ded4..d1a871949951b2 100644 --- a/test/node-api/test_reference_by_node_api_version/test_reference_by_node_api_version.c +++ b/test/node-api/test_reference_by_node_api_version/test_reference_by_node_api_version.c @@ -4,12 +4,12 @@ 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; }