diff --git a/src/js_native_api.h b/src/js_native_api.h index ab2cbff60cf1bd..762aa296d6ff51 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_pure_env env, const napi_extended_error_info** result); + node_api_nogc_env env, const napi_extended_error_info** result); // Getters for defined singletons NAPI_EXTERN napi_status NAPI_CDECL napi_get_undefined(napi_env env, @@ -97,7 +97,7 @@ NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_latin1(napi_env env, char* str, size_t length, - node_api_pure_finalize finalize_callback, + node_api_nogc_finalize finalize_callback, void* finalize_hint, napi_value* result, bool* copied); @@ -105,7 +105,7 @@ NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_utf16(napi_env env, char16_t* str, size_t length, - node_api_pure_finalize finalize_callback, + node_api_nogc_finalize finalize_callback, void* finalize_hint, napi_value* result, bool* copied); @@ -289,7 +289,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_instanceof(napi_env env, // Gets all callback info in a single call. (Ugly, but faster.) NAPI_EXTERN napi_status NAPI_CDECL napi_get_cb_info( - node_api_pure_env env, // [in] NAPI environment handle + node_api_nogc_env env, // [in] Node-API environment handle napi_callback_info cbinfo, // [in] Opaque callback-info handle size_t* argc, // [in-out] Specifies the size of the provided argv array // and receives the actual count of args. @@ -313,7 +313,7 @@ napi_define_class(napi_env env, NAPI_EXTERN napi_status NAPI_CDECL napi_wrap(napi_env env, napi_value js_object, void* native_object, - node_api_pure_finalize finalize_cb, + node_api_nogc_finalize finalize_cb, void* finalize_hint, napi_ref* result); NAPI_EXTERN napi_status NAPI_CDECL napi_unwrap(napi_env env, @@ -325,7 +325,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_pure_finalize finalize_cb, + node_api_nogc_finalize finalize_cb, void* finalize_hint, napi_value* result); NAPI_EXTERN napi_status NAPI_CDECL napi_get_value_external(napi_env env, @@ -424,7 +424,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_external_arraybuffer(napi_env env, void* external_data, size_t byte_length, - node_api_pure_finalize finalize_cb, + node_api_nogc_finalize finalize_cb, void* finalize_hint, napi_value* result); #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED @@ -466,7 +466,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_pure_env env, +NAPI_EXTERN napi_status NAPI_CDECL napi_get_version(node_api_nogc_env env, uint32_t* result); // Promises @@ -490,7 +490,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_pure_env env, int64_t change_in_bytes, int64_t* adjusted_value); + node_api_nogc_env env, int64_t change_in_bytes, int64_t* adjusted_value); #if NAPI_VERSION >= 5 @@ -512,7 +512,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_add_finalizer(napi_env env, napi_value js_object, void* finalize_data, - node_api_pure_finalize finalize_cb, + node_api_nogc_finalize finalize_cb, void* finalize_hint, napi_ref* result); @@ -521,7 +521,7 @@ napi_add_finalizer(napi_env env, #ifdef NAPI_EXPERIMENTAL NAPI_EXTERN napi_status NAPI_CDECL -node_api_post_finalizer(node_api_pure_env env, +node_api_post_finalizer(node_api_nogc_env env, napi_finalize finalize_cb, void* finalize_data, void* finalize_hint); @@ -566,12 +566,12 @@ napi_get_all_property_names(napi_env env, // Instance data NAPI_EXTERN napi_status NAPI_CDECL -napi_set_instance_data(node_api_pure_env env, +napi_set_instance_data(node_api_nogc_env env, void* data, - node_api_pure_finalize finalize_cb, + node_api_nogc_finalize finalize_cb, void* finalize_hint); -NAPI_EXTERN napi_status NAPI_CDECL napi_get_instance_data(node_api_pure_env env, +NAPI_EXTERN napi_status NAPI_CDECL napi_get_instance_data(node_api_nogc_env env, void** data); #endif // NAPI_VERSION >= 6 diff --git a/src/js_native_api_types.h b/src/js_native_api_types.h index 54e0f38436a733..6288938a6a7a43 100644 --- a/src/js_native_api_types.h +++ b/src/js_native_api_types.h @@ -23,30 +23,31 @@ typedef uint16_t char16_t; // typedef undefined structs instead of void* for compile time type safety typedef struct napi_env__* napi_env; -// We need to mark APIs which are "pure", meaning that they do not interact -// with the JS engine, and can therefore be called synchronously from a -// finalizer that itself runs synchronously during garbage collection. Such -// "pure" APIs can receive either a `napi_env` or a `node_api_pure_env` as -// their first parameter, because we should be able to also call them during -// normal, non-garbage-collecting operations, whereas "non-pure" APIs can only -// receive a `napi_env` as their first parameter, because we must not call them -// during garbage collection. In lieu of inheritance, we use the properties of -// the const qualifier to accomplish this, because both a const and a non-const -// value can be passed to an API expecting a const value, but only a non-const -// value can be passed to an API expecting a non-const value. +// We need to mark APIs which can be called during garbage collection (GC), +// 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 +// 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 +// inheritance, we use the properties of the const qualifier to accomplish +// this, because both a const and a non-const value can be passed to an API +// expecting a const value, but only a non-const value can be passed to an API +// expecting a non-const value. // // In conjunction with appropriate CFLAGS to warn us if we're passing a const -// (pure) environment into an API that expects a non-const (non-pure) -// environment, and the definition of pure finalizer function pointer types -// below, which receive a pure environment as their first parameter, and can -// thus only call pure APIs (unless the user explicitly casts the environment), -// we achieve the ability to ensure at compile time that we do not call non- -// pure APIs from a synchronous (pure) finalizer. -#if defined(NAPI_EXPERIMENTAL) && defined(NODE_API_EXPERIMENTAL_PURE_ENV) -typedef const struct napi_env__* node_api_pure_env; +// (nogc) environment into an API that expects a non-const environment, and the +// definition of pure 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. +#if defined(NAPI_EXPERIMENTAL) && defined(NODE_API_EXPERIMENTAL_NOGC_ENV) +typedef const struct napi_env__* node_api_nogc_env; #else -typedef struct napi_env__* node_api_pure_env; -#endif // NAPI_EXPERIMENTAL && NODE_API_EXPERIMENTAL_PURE_ENV +typedef struct napi_env__* node_api_nogc_env; +#endif // NAPI_EXPERIMENTAL && NODE_API_EXPERIMENTAL_NOGC_ENV typedef struct napi_value__* napi_value; typedef struct napi_ref__* napi_ref; @@ -141,13 +142,13 @@ typedef napi_value(NAPI_CDECL* napi_callback)(napi_env env, typedef void(NAPI_CDECL* napi_finalize)(napi_env env, void* finalize_data, void* finalize_hint); -#if defined(NAPI_EXPERIMENTAL) && defined(NODE_API_EXPERIMENTAL_PURE_ENV) -typedef void(NAPI_CDECL* node_api_pure_finalize)(node_api_pure_env env, +#if defined(NAPI_EXPERIMENTAL) && defined(NODE_API_EXPERIMENTAL_NOGC_ENV) +typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env, void* finalize_data, void* finalize_hint); #else -typedef napi_finalize node_api_pure_finalize; -#endif // NAPI_EXPERIMENTAL && NODE_API_EXPERIMENTAL_PURE_ENV +typedef napi_finalize node_api_nogc_finalize; +#endif // NAPI_EXPERIMENTAL && NODE_API_EXPERIMENTAL_NOGC_ENV 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 be5eefbe722271..5582a0ea2dece5 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -849,8 +849,8 @@ static const char* error_messages[] = { }; napi_status NAPI_CDECL napi_get_last_error_info( - node_api_pure_env pure_env, const napi_extended_error_info** result) { - napi_env env = const_cast(pure_env); + node_api_nogc_env nogc_env, const napi_extended_error_info** result) { + napi_env env = const_cast(nogc_env); CHECK_ENV(env); CHECK_ARG(env, result); @@ -1602,12 +1602,12 @@ napi_status NAPI_CDECL node_api_create_external_string_latin1( napi_env env, char* str, size_t length, - node_api_pure_finalize pure_finalize_callback, + node_api_nogc_finalize nogc_finalize_callback, void* finalize_hint, napi_value* result, bool* copied) { napi_finalize finalize_callback = - reinterpret_cast(pure_finalize_callback); + reinterpret_cast(nogc_finalize_callback); return v8impl::NewExternalString( env, str, @@ -1631,12 +1631,12 @@ napi_status NAPI_CDECL node_api_create_external_string_utf16( napi_env env, char16_t* str, size_t length, - node_api_pure_finalize pure_finalize_callback, + node_api_nogc_finalize nogc_finalize_callback, void* finalize_hint, napi_value* result, bool* copied) { napi_finalize finalize_callback = - reinterpret_cast(pure_finalize_callback); + reinterpret_cast(nogc_finalize_callback); return v8impl::NewExternalString( env, str, @@ -1993,7 +1993,7 @@ napi_status NAPI_CDECL napi_get_null(napi_env env, napi_value* result) { // Gets all callback info in a single call. (Ugly, but faster.) napi_status NAPI_CDECL napi_get_cb_info( - node_api_pure_env env, // [in] NAPI environment handle + node_api_nogc_env env, // [in] NAPI environment handle napi_callback_info cbinfo, // [in] Opaque callback-info handle size_t* argc, // [in-out] Specifies the size of the provided argv array // and receives the actual count of args. @@ -2533,10 +2533,10 @@ GEN_COERCE_FUNCTION(STRING, String, string) napi_status NAPI_CDECL napi_wrap(napi_env env, napi_value js_object, void* native_object, - node_api_pure_finalize pure_finalize_cb, + node_api_nogc_finalize nogc_finalize_cb, void* finalize_hint, napi_ref* result) { - napi_finalize finalize_cb = reinterpret_cast(pure_finalize_cb); + napi_finalize finalize_cb = reinterpret_cast(nogc_finalize_cb); return v8impl::Wrap( env, js_object, native_object, finalize_cb, finalize_hint, result); } @@ -2556,10 +2556,10 @@ napi_status NAPI_CDECL napi_remove_wrap(napi_env env, napi_status NAPI_CDECL napi_create_external(napi_env env, void* data, - node_api_pure_finalize pure_finalize_cb, + node_api_nogc_finalize nogc_finalize_cb, void* finalize_hint, napi_value* result) { - napi_finalize finalize_cb = reinterpret_cast(pure_finalize_cb); + napi_finalize finalize_cb = reinterpret_cast(nogc_finalize_cb); NAPI_PREAMBLE(env); CHECK_ARG(env, result); @@ -2992,7 +2992,7 @@ napi_status NAPI_CDECL napi_create_external_arraybuffer(napi_env env, void* external_data, size_t byte_length, - node_api_pure_finalize finalize_cb, + node_api_nogc_finalize finalize_cb, void* finalize_hint, napi_value* result) { // The API contract here is that the cleanup function runs on the JS thread, @@ -3262,7 +3262,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_pure_env env, +napi_status NAPI_CDECL napi_get_version(node_api_nogc_env env, uint32_t* result) { CHECK_ENV(env); CHECK_ARG(env, result); @@ -3387,12 +3387,12 @@ napi_status NAPI_CDECL napi_add_finalizer(napi_env env, napi_value js_object, void* finalize_data, - node_api_pure_finalize pure_finalize_cb, + node_api_nogc_finalize nogc_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(pure_finalize_cb); + napi_finalize finalize_cb = reinterpret_cast(nogc_finalize_cb); CHECK_ENV(env); env->CheckGCAccess(); CHECK_ARG(env, js_object); @@ -3417,11 +3417,11 @@ napi_add_finalizer(napi_env env, #ifdef NAPI_EXPERIMENTAL -napi_status NAPI_CDECL node_api_post_finalizer(node_api_pure_env pure_env, +napi_status NAPI_CDECL node_api_post_finalizer(node_api_nogc_env nogc_env, napi_finalize finalize_cb, void* finalize_data, void* finalize_hint) { - napi_env env = const_cast(pure_env); + napi_env env = const_cast(nogc_env); CHECK_ENV(env); env->EnqueueFinalizer(v8impl::TrackedFinalizer::New( env, finalize_cb, finalize_data, finalize_hint)); @@ -3430,7 +3430,7 @@ napi_status NAPI_CDECL node_api_post_finalizer(node_api_pure_env pure_env, #endif -napi_status NAPI_CDECL napi_adjust_external_memory(node_api_pure_env env, +napi_status NAPI_CDECL napi_adjust_external_memory(node_api_nogc_env env, int64_t change_in_bytes, int64_t* adjusted_value) { CHECK_ENV(env); @@ -3443,12 +3443,12 @@ napi_status NAPI_CDECL napi_adjust_external_memory(node_api_pure_env env, } napi_status NAPI_CDECL -napi_set_instance_data(node_api_pure_env pure_env, +napi_set_instance_data(node_api_nogc_env nogc_env, void* data, - node_api_pure_finalize pure_finalize_cb, + node_api_nogc_finalize nogc_finalize_cb, void* finalize_hint) { - napi_env env = const_cast(pure_env); - napi_finalize finalize_cb = reinterpret_cast(pure_finalize_cb); + napi_env env = const_cast(nogc_env); + napi_finalize finalize_cb = reinterpret_cast(nogc_finalize_cb); CHECK_ENV(env); v8impl::RefBase* old_data = static_cast(env->instance_data); @@ -3464,7 +3464,7 @@ napi_set_instance_data(node_api_pure_env pure_env, return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_get_instance_data(node_api_pure_env env, +napi_status NAPI_CDECL napi_get_instance_data(node_api_nogc_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 1df0fce7dfb99c..aef1d78e3118b5 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_pure_env env); +inline napi_status napi_clear_last_error(node_api_nogc_env env); namespace v8impl { @@ -172,8 +172,8 @@ struct napi_env__ { virtual ~napi_env__() = default; }; -inline napi_status napi_clear_last_error(node_api_pure_env pure_env) { - napi_env env = const_cast(pure_env); +inline napi_status napi_clear_last_error(node_api_nogc_env nogc_env) { + napi_env env = const_cast(nogc_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_pure_env pure_env) { return napi_ok; } -inline napi_status napi_set_last_error(node_api_pure_env pure_env, +inline napi_status napi_set_last_error(node_api_nogc_env nogc_env, napi_status error_code, uint32_t engine_error_code = 0, void* engine_reserved = nullptr) { - napi_env env = const_cast(pure_env); + napi_env env = const_cast(nogc_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 835b7b9d24b6c0..7aff9119386d86 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -765,7 +765,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_pure_env env, +napi_status NAPI_CDECL napi_add_env_cleanup_hook(node_api_nogc_env env, napi_cleanup_hook fun, void* arg) { CHECK_ENV(env); @@ -776,7 +776,7 @@ napi_status NAPI_CDECL napi_add_env_cleanup_hook(node_api_pure_env env, return napi_ok; } -napi_status NAPI_CDECL napi_remove_env_cleanup_hook(node_api_pure_env env, +napi_status NAPI_CDECL napi_remove_env_cleanup_hook(node_api_nogc_env env, napi_cleanup_hook fun, void* arg) { CHECK_ENV(env); @@ -880,7 +880,7 @@ NAPI_NO_RETURN void NAPI_CDECL napi_fatal_error(const char* location, } napi_status NAPI_CDECL -napi_open_callback_scope(node_api_pure_env env, +napi_open_callback_scope(node_api_nogc_env env, napi_value /** ignored */, napi_async_context async_context_handle, napi_callback_scope* result) { @@ -897,11 +897,11 @@ napi_open_callback_scope(node_api_pure_env env, return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_close_callback_scope(node_api_pure_env pure_env, +napi_status NAPI_CDECL napi_close_callback_scope(node_api_nogc_env nogc_env, napi_callback_scope scope) { // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw // JS exceptions. - napi_env env = const_cast(pure_env); + napi_env env = const_cast(nogc_env); CHECK_ENV(env); CHECK_ARG(env, scope); if (env->open_callback_scopes == 0) { @@ -1044,10 +1044,10 @@ napi_status NAPI_CDECL napi_create_external_buffer(napi_env env, size_t length, void* data, - node_api_pure_finalize pure_finalize_cb, + node_api_nogc_finalize nogc_finalize_cb, void* finalize_hint, napi_value* result) { - napi_finalize finalize_cb = reinterpret_cast(pure_finalize_cb); + napi_finalize finalize_cb = reinterpret_cast(nogc_finalize_cb); NAPI_PREAMBLE(env); CHECK_ARG(env, result); @@ -1133,7 +1133,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_pure_env env, +napi_status NAPI_CDECL napi_get_node_version(node_api_nogc_env env, const napi_node_version** result) { CHECK_ENV(env); CHECK_ARG(env, result); @@ -1279,16 +1279,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_pure_env pure_env, +napi_status NAPI_CDECL napi_get_uv_event_loop(node_api_nogc_env nogc_env, uv_loop_t** loop) { - napi_env env = const_cast(pure_env); + napi_env env = const_cast(nogc_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_pure_env env, +napi_status NAPI_CDECL napi_queue_async_work(node_api_nogc_env env, napi_async_work work) { CHECK_ENV(env); CHECK_ARG(env, work); @@ -1303,7 +1303,7 @@ napi_status NAPI_CDECL napi_queue_async_work(node_api_pure_env env, return napi_clear_last_error(env); } -napi_status NAPI_CDECL napi_cancel_async_work(node_api_pure_env env, +napi_status NAPI_CDECL napi_cancel_async_work(node_api_nogc_env env, napi_async_work work) { CHECK_ENV(env); CHECK_ARG(env, work); @@ -1323,12 +1323,12 @@ napi_create_threadsafe_function(napi_env env, size_t max_queue_size, size_t initial_thread_count, void* thread_finalize_data, - node_api_pure_finalize pure_thread_finalize_cb, + node_api_nogc_finalize nogc_thread_finalize_cb, void* context, napi_threadsafe_function_call_js call_js_cb, napi_threadsafe_function* result) { napi_finalize thread_finalize_cb = - reinterpret_cast(pure_thread_finalize_cb); + reinterpret_cast(nogc_thread_finalize_cb); CHECK_ENV(env); env->CheckGCAccess(); CHECK_ARG(env, async_resource_name); @@ -1412,20 +1412,20 @@ napi_status NAPI_CDECL napi_release_threadsafe_function( } napi_status NAPI_CDECL napi_unref_threadsafe_function( - node_api_pure_env env, napi_threadsafe_function func) { + node_api_nogc_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_pure_env env, napi_threadsafe_function func) { + node_api_nogc_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_pure_env pure_env, +napi_status NAPI_CDECL node_api_get_module_file_name(node_api_nogc_env nogc_env, const char** result) { - napi_env env = const_cast(pure_env); + napi_env env = const_cast(nogc_env); CHECK_ENV(env); CHECK_ARG(env, result); diff --git a/src/node_api.h b/src/node_api.h index fdb5049a612c17..69afe52ba3aabf 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_pure_finalize finalize_cb, + node_api_nogc_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_pure_env env, +NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(node_api_nogc_env env, napi_async_work work); -NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(node_api_pure_env env, +NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(node_api_nogc_env env, napi_async_work work); // version management NAPI_EXTERN napi_status NAPI_CDECL -napi_get_node_version(node_api_pure_env env, const napi_node_version** version); +napi_get_node_version(node_api_nogc_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_pure_env env, struct uv_loop_s** loop); +napi_get_uv_event_loop(node_api_nogc_env env, struct uv_loop_s** loop); #endif // NAPI_VERSION >= 2 @@ -182,19 +182,19 @@ 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_pure_env env, napi_cleanup_hook fun, void* arg); + node_api_nogc_env env, napi_cleanup_hook fun, void* arg); NAPI_EXTERN napi_status NAPI_CDECL napi_remove_env_cleanup_hook( - node_api_pure_env env, napi_cleanup_hook fun, void* arg); + node_api_nogc_env env, napi_cleanup_hook fun, void* arg); NAPI_EXTERN napi_status NAPI_CDECL -napi_open_callback_scope(node_api_pure_env env, +napi_open_callback_scope(node_api_nogc_env env, napi_value resource_object, napi_async_context context, napi_callback_scope* result); NAPI_EXTERN napi_status NAPI_CDECL -napi_close_callback_scope(node_api_pure_env env, napi_callback_scope scope); +napi_close_callback_scope(node_api_nogc_env env, napi_callback_scope scope); #endif // NAPI_VERSION >= 3 @@ -209,7 +209,7 @@ napi_create_threadsafe_function(napi_env env, size_t max_queue_size, size_t initial_thread_count, void* thread_finalize_data, - node_api_pure_finalize thread_finalize_cb, + node_api_nogc_finalize thread_finalize_cb, void* context, napi_threadsafe_function_call_js call_js_cb, napi_threadsafe_function* result); @@ -229,10 +229,10 @@ 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_pure_env env, napi_threadsafe_function func); + node_api_nogc_env env, napi_threadsafe_function func); NAPI_EXTERN napi_status NAPI_CDECL napi_ref_threadsafe_function( - node_api_pure_env env, napi_threadsafe_function func); + node_api_nogc_env env, napi_threadsafe_function func); #endif // NAPI_VERSION >= 4 @@ -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_pure_env env, const char** result); +node_api_get_module_file_name(node_api_nogc_env env, const char** result); #endif // NAPI_VERSION >= 9 diff --git a/test/cctest/test_linked_binding.cc b/test/cctest/test_linked_binding.cc index 8a08a224030d60..475444ad538fde 100644 --- a/test/cctest/test_linked_binding.cc +++ b/test/cctest/test_linked_binding.cc @@ -239,9 +239,9 @@ TEST_F(LinkedBindingTest, LocallyDefinedLinkedBindingNapiRefExperimentalTest) { napi_value NapiLinkedWithInstanceData(napi_env env, napi_value exports) { int* instance_data = new int(0); CHECK_EQ(napi_set_instance_data( - static_cast(env), + static_cast(env), instance_data, - [](node_api_pure_env env, void* data, void* hint) { + [](node_api_nogc_env env, void* data, void* hint) { ++*static_cast(data); }, nullptr), diff --git a/test/js-native-api/common.h b/test/js-native-api/common.h index 3878a42160be8f..7822e55b2bd44a 100644 --- a/test/js-native-api/common.h +++ b/test/js-native-api/common.h @@ -47,7 +47,7 @@ } \ } while (0) -#define NODE_API_PURE_ASSERT_BASE(assertion, message, ret_val) \ +#define NODE_API_NOGC_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_PURE_ASSERT_RETURN_VOID(assertion, message) \ - NODE_API_PURE_ASSERT_BASE(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_CALL_BASE(env, the_call, ret_val) \ do { \ @@ -77,7 +77,7 @@ } \ } while (0) -#define NODE_API_PURE_CALL_BASE(env, the_call, ret_val) \ +#define NODE_API_NOGC_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_PURE_CALL_RETURN_VOID(env, the_call) \ - NODE_API_PURE_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_CHECK_STATUS(the_call) \ do { \ diff --git a/test/js-native-api/test_cannot_run_js/binding.gyp b/test/js-native-api/test_cannot_run_js/binding.gyp index c1353f2e1db111..408181240097da 100644 --- a/test/js-native-api/test_cannot_run_js/binding.gyp +++ b/test/js-native-api/test_cannot_run_js/binding.gyp @@ -5,7 +5,7 @@ "sources": [ "test_cannot_run_js.c" ], - "defines": [ "NAPI_EXPERIMENTAL", "NODE_API_EXPERIMENTAL_PURE_ENV" ], + "defines": [ "NAPI_EXPERIMENTAL", "NODE_API_EXPERIMENTAL_NOGC_ENV" ], }, { "target_name": "test_pending_exception", 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 1dc8ff2a0c10eb..be410389a054c9 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 @@ -20,13 +20,13 @@ static void Finalize(napi_env env, void* data, void* hint) { free(ref); } -static void PureFinalize(node_api_pure_env env, void* data, void* hint) { -#if defined(NAPI_EXPERIMENTAL) && defined(NODE_API_EXPERIMENTAL_PURE_ENV) - NODE_API_PURE_CALL_RETURN_VOID( +static void PureFinalize(node_api_nogc_env env, void* data, void* hint) { +#if defined(NAPI_EXPERIMENTAL) && defined(NODE_API_EXPERIMENTAL_NOGC_ENV) + NODE_API_NOGC_CALL_RETURN_VOID( env, node_api_post_finalizer(env, Finalize, data, hint)); #else Finalize(env, data, hint); -#endif // NAPI_EXPERIMENTAL && NODE_API_EXPERIMENTAL_PURE_ENV +#endif // NAPI_EXPERIMENTAL && NODE_API_EXPERIMENTAL_NOGC_ENV } static napi_value CreateRef(napi_env env, napi_callback_info info) { diff --git a/test/js-native-api/test_finalizer/binding.gyp b/test/js-native-api/test_finalizer/binding.gyp index d13ef210d9db25..6c9c8020e3ea95 100644 --- a/test/js-native-api/test_finalizer/binding.gyp +++ b/test/js-native-api/test_finalizer/binding.gyp @@ -2,7 +2,7 @@ "targets": [ { "target_name": "test_finalizer", - "defines": [ "NAPI_EXPERIMENTAL", "NODE_API_EXPERIMENTAL_PURE_ENV" ], + "defines": [ "NAPI_EXPERIMENTAL", "NODE_API_EXPERIMENTAL_NOGC_ENV" ], "sources": [ "test_finalizer.c" ] diff --git a/test/js-native-api/test_finalizer/test_finalizer.c b/test/js-native-api/test_finalizer/test_finalizer.c index 8782d132e410b6..e20fd13f36d5a4 100644 --- a/test/js-native-api/test_finalizer/test_finalizer.c +++ b/test/js-native-api/test_finalizer/test_finalizer.c @@ -11,16 +11,16 @@ typedef struct { napi_ref js_func; } FinalizerData; -static void finalizerOnlyCallback(node_api_pure_env env, +static void finalizerOnlyCallback(node_api_nogc_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_PURE_CALL_RETURN_VOID(env, + NODE_API_NOGC_CALL_RETURN_VOID(env, napi_get_instance_data(env, (void**)&data)); - NODE_API_PURE_ASSERT_RETURN_VOID(count = data->finalize_count, + NODE_API_NOGC_ASSERT_RETURN_VOID(count = data->finalize_count, "Expected to the same FinalizerData"); } @@ -40,16 +40,16 @@ static void finalizerCallingJSCallback(napi_env env, } // Schedule async finalizer to run JavaScript-touching code. -static void finalizerWithJSCallback(node_api_pure_env env, +static void finalizerWithJSCallback(node_api_nogc_env env, void* finalize_data, void* finalize_hint) { - NODE_API_PURE_CALL_RETURN_VOID( + NODE_API_NOGC_CALL_RETURN_VOID( env, node_api_post_finalizer( env, finalizerCallingJSCallback, finalize_data, finalize_hint)); } -static void finalizerWithFailedJSCallback(node_api_pure_env env, +static void finalizerWithFailedJSCallback(node_api_nogc_env env, void* finalize_data, void* finalize_hint) { napi_value obj; @@ -57,7 +57,7 @@ static void finalizerWithFailedJSCallback(node_api_pure_env env, ++data->finalize_count; // We intentionally cast to napi_env and call an API that cannot be called // during garbage collection. This will cause the process to fail. - NODE_API_PURE_CALL_RETURN_VOID(env, napi_create_object((napi_env)env, &obj)); + NODE_API_NOGC_CALL_RETURN_VOID(env, napi_create_object((napi_env)env, &obj)); } static napi_value addFinalizer(napi_env env, napi_callback_info info) { @@ -119,7 +119,7 @@ static napi_value getFinalizerCallCount(napi_env env, napi_callback_info info) { return result; } -static void finalizeData(node_api_pure_env env, void* data, void* hint) { +static void finalizeData(node_api_nogc_env env, void* data, void* hint) { free(data); } diff --git a/test/js-native-api/test_string/binding.gyp b/test/js-native-api/test_string/binding.gyp index 957bd0de394ead..7d29e61a2a9bda 100644 --- a/test/js-native-api/test_string/binding.gyp +++ b/test/js-native-api/test_string/binding.gyp @@ -7,7 +7,7 @@ "test_null.c", ], "defines": [ - "NAPI_EXPERIMENTAL", "NODE_API_EXPERIMENTAL_PURE_ENV" + "NAPI_EXPERIMENTAL", "NODE_API_EXPERIMENTAL_NOGC_ENV" ] } ] diff --git a/test/js-native-api/test_string/test_string.c b/test/js-native-api/test_string/test_string.c index 2b0496109470f0..81da3d61fe18ac 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_pure_env env, void* data, void* hint) { +static void free_string(node_api_nogc_env env, void* data, void* hint) { free(data); } diff --git a/test/node-api/test_env_teardown_gc/binding.c b/test/node-api/test_env_teardown_gc/binding.c index fd73d3326dee1c..08fb6de605d0d5 100644 --- a/test/node-api/test_env_teardown_gc/binding.c +++ b/test/node-api/test_env_teardown_gc/binding.c @@ -2,7 +2,7 @@ #include #include "../../js-native-api/common.h" -static void MyObject_fini(node_api_pure_env env, void* data, void* hint) { +static void MyObject_fini(node_api_nogc_env env, void* data, void* hint) { napi_ref* ref = data; napi_value global; napi_value cleanup; diff --git a/test/node-api/test_reference_by_node_api_version/binding.gyp b/test/node-api/test_reference_by_node_api_version/binding.gyp index 24292c74c29668..d246e970c74486 100644 --- a/test/node-api/test_reference_by_node_api_version/binding.gyp +++ b/test/node-api/test_reference_by_node_api_version/binding.gyp @@ -3,7 +3,7 @@ { "target_name": "test_reference_all_types", "sources": [ "test_reference_by_node_api_version.c" ], - "defines": [ "NAPI_EXPERIMENTAL", "NODE_API_EXPERIMENTAL_PURE_ENV" ], + "defines": [ "NAPI_EXPERIMENTAL", "NODE_API_EXPERIMENTAL_NOGC_ENV" ], }, { "target_name": "test_reference_obj_only", 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 60fa44752ef91b..59be4913f05946 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_pure_env env, void* data, void* hint) { - NODE_API_PURE_ASSERT_RETURN_VOID(data != NULL, "Expects non-NULL data."); +static void FreeData(node_api_nogc_env env, void* data, void* hint) { + NODE_API_NOGC_ASSERT_RETURN_VOID(data != NULL, "Expects non-NULL data."); free(data); } -static void Finalize(node_api_pure_env env, void* data, void* hint) { +static void Finalize(node_api_nogc_env env, void* data, void* hint) { ++finalizeCount; } diff --git a/test/node-api/test_threadsafe_function/binding.gyp b/test/node-api/test_threadsafe_function/binding.gyp index 346cec79c46233..a01d962057a8c4 100644 --- a/test/node-api/test_threadsafe_function/binding.gyp +++ b/test/node-api/test_threadsafe_function/binding.gyp @@ -14,7 +14,7 @@ { 'target_name': 'test_uncaught_exception', 'defines': [ - 'NAPI_EXPERIMENTAL', 'NODE_API_EXPERIMENTAL_PURE_ENV' + 'NAPI_EXPERIMENTAL', 'NODE_API_EXPERIMENTAL_NOGC_ENV' ], 'sources': ['test_uncaught_exception.c'] } diff --git a/test/node-api/test_threadsafe_function/test_uncaught_exception.c b/test/node-api/test_threadsafe_function/test_uncaught_exception.c index 11ea328d377f84..b7068c5f17b9e7 100644 --- a/test/node-api/test_threadsafe_function/test_uncaught_exception.c +++ b/test/node-api/test_threadsafe_function/test_uncaught_exception.c @@ -16,11 +16,11 @@ static void ThreadSafeFunctionJsCapableFinalize(napi_env env, NODE_API_CALL_RETURN_VOID(env, napi_delete_reference(env, js_func_ref)); } -static void ThreadSafeFunctionFinalize(node_api_pure_env env, +static void ThreadSafeFunctionFinalize(node_api_nogc_env env, void* finalize_data, void* finalize_hint) { -#if defined(NAPI_EXPERIMENTAL) && defined(NODE_API_EXPERIMENTAL_PURE_ENV) - NODE_API_PURE_CALL_RETURN_VOID( +#if defined(NAPI_EXPERIMENTAL) && defined(NODE_API_EXPERIMENTAL_NOGC_ENV) + NODE_API_NOGC_CALL_RETURN_VOID( env, node_api_post_finalizer(env, ThreadSafeFunctionJsCapableFinalize, @@ -28,7 +28,7 @@ static void ThreadSafeFunctionFinalize(node_api_pure_env env, finalize_hint)); #else ThreadSafeFunctionJsCapableFinalize(env, finalize_data, finalize_hint); -#endif // NAPI_EXPERIMENTAL && NODE_API_EXPERIMENTAL_PURE_ENV +#endif // NAPI_EXPERIMENTAL && NODE_API_EXPERIMENTAL_NOGC_ENV } // Testing calling into JavaScript