Skip to content

Commit

Permalink
refactor: rename nogc to basic (nodejs/node#53830)
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Jul 28, 2024
1 parent 96ffffb commit 19ab28e
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 93 deletions.
51 changes: 26 additions & 25 deletions packages/emnapi/include/node/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions packages/emnapi/include/node/js_native_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
26 changes: 13 additions & 13 deletions packages/emnapi/include/node/node_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/emnapi/src/async_cleanup_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/emnapi/src/async_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/emnapi/src/emnapi_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/emnapi/src/js_native_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions packages/emnapi/src/node_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/emnapi/src/threadsafe_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 19ab28e

Please sign in to comment.