test: rename n-api to node-api

This renames the macros used in the tests from `NAPI_*` to
`NODE_API_*`.

PR-URL: https://github.com/nodejs/node/pull/37217
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Gabriel Schulhof 2021-02-03 12:01:28 -08:00 committed by Rich Trott
parent 2ff1c83518
commit 4b7f23f868
52 changed files with 1371 additions and 1448 deletions

View file

@ -9,13 +9,13 @@ static napi_ref test_reference = NULL;
static napi_value GetFinalizeCount(napi_env env, napi_callback_info info) {
napi_value result;
NAPI_CALL(env, napi_create_int32(env, finalize_count, &result));
NODE_API_CALL(env, napi_create_int32(env, finalize_count, &result));
return result;
}
static void FinalizeExternal(napi_env env, void* data, void* hint) {
int *actual_value = data;
NAPI_ASSERT_RETURN_VOID(env, actual_value == &test_value,
NODE_API_ASSERT_RETURN_VOID(env, actual_value == &test_value,
"The correct pointer was passed to the finalizer");
finalize_count++;
}
@ -24,7 +24,7 @@ static napi_value CreateExternal(napi_env env, napi_callback_info info) {
int* data = &test_value;
napi_value result;
NAPI_CALL(env,
NODE_API_CALL(env,
napi_create_external(env,
data,
NULL, /* finalize_cb */
@ -38,7 +38,7 @@ static napi_value CreateExternal(napi_env env, napi_callback_info info) {
static napi_value
CreateExternalWithFinalize(napi_env env, napi_callback_info info) {
napi_value result;
NAPI_CALL(env,
NODE_API_CALL(env,
napi_create_external(env,
&test_value,
FinalizeExternal,
@ -52,84 +52,84 @@ CreateExternalWithFinalize(napi_env env, napi_callback_info info) {
static napi_value CheckExternal(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value arg;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &arg, NULL, NULL));
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, &arg, NULL, NULL));
NAPI_ASSERT(env, argc == 1, "Expected one argument.");
NODE_API_ASSERT(env, argc == 1, "Expected one argument.");
napi_valuetype argtype;
NAPI_CALL(env, napi_typeof(env, arg, &argtype));
NODE_API_CALL(env, napi_typeof(env, arg, &argtype));
NAPI_ASSERT(env, argtype == napi_external, "Expected an external value.");
NODE_API_ASSERT(env, argtype == napi_external, "Expected an external value.");
void* data;
NAPI_CALL(env, napi_get_value_external(env, arg, &data));
NODE_API_CALL(env, napi_get_value_external(env, arg, &data));
NAPI_ASSERT(env, data != NULL && *(int*)data == test_value,
NODE_API_ASSERT(env, data != NULL && *(int*)data == test_value,
"An external data value of 1 was expected.");
return NULL;
}
static napi_value CreateReference(napi_env env, napi_callback_info info) {
NAPI_ASSERT(env, test_reference == NULL,
NODE_API_ASSERT(env, test_reference == NULL,
"The test allows only one reference at a time.");
size_t argc = 2;
napi_value args[2];
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
NAPI_ASSERT(env, argc == 2, "Expected two arguments.");
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
NODE_API_ASSERT(env, argc == 2, "Expected two arguments.");
uint32_t initial_refcount;
NAPI_CALL(env, napi_get_value_uint32(env, args[1], &initial_refcount));
NODE_API_CALL(env, napi_get_value_uint32(env, args[1], &initial_refcount));
NAPI_CALL(env,
NODE_API_CALL(env,
napi_create_reference(env, args[0], initial_refcount, &test_reference));
NAPI_ASSERT(env, test_reference != NULL,
NODE_API_ASSERT(env, test_reference != NULL,
"A reference should have been created.");
return NULL;
}
static napi_value DeleteReference(napi_env env, napi_callback_info info) {
NAPI_ASSERT(env, test_reference != NULL,
NODE_API_ASSERT(env, test_reference != NULL,
"A reference must have been created.");
NAPI_CALL(env, napi_delete_reference(env, test_reference));
NODE_API_CALL(env, napi_delete_reference(env, test_reference));
test_reference = NULL;
return NULL;
}
static napi_value IncrementRefcount(napi_env env, napi_callback_info info) {
NAPI_ASSERT(env, test_reference != NULL,
NODE_API_ASSERT(env, test_reference != NULL,
"A reference must have been created.");
uint32_t refcount;
NAPI_CALL(env, napi_reference_ref(env, test_reference, &refcount));
NODE_API_CALL(env, napi_reference_ref(env, test_reference, &refcount));
napi_value result;
NAPI_CALL(env, napi_create_uint32(env, refcount, &result));
NODE_API_CALL(env, napi_create_uint32(env, refcount, &result));
return result;
}
static napi_value DecrementRefcount(napi_env env, napi_callback_info info) {
NAPI_ASSERT(env, test_reference != NULL,
NODE_API_ASSERT(env, test_reference != NULL,
"A reference must have been created.");
uint32_t refcount;
NAPI_CALL(env, napi_reference_unref(env, test_reference, &refcount));
NODE_API_CALL(env, napi_reference_unref(env, test_reference, &refcount));
napi_value result;
NAPI_CALL(env, napi_create_uint32(env, refcount, &result));
NODE_API_CALL(env, napi_create_uint32(env, refcount, &result));
return result;
}
static napi_value GetReferenceValue(napi_env env, napi_callback_info info) {
NAPI_ASSERT(env, test_reference != NULL,
NODE_API_ASSERT(env, test_reference != NULL,
"A reference must have been created.");
napi_value result;
NAPI_CALL(env, napi_get_reference_value(env, test_reference, &result));
NODE_API_CALL(env, napi_get_reference_value(env, test_reference, &result));
return result;
}
@ -146,15 +146,12 @@ static void DeleteBeforeFinalizeFinalizer(
static napi_value ValidateDeleteBeforeFinalize(napi_env env, napi_callback_info info) {
napi_value wrapObject;
size_t argc = 1;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &wrapObject, NULL, NULL));
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, &wrapObject, NULL, NULL));
napi_ref* ref_t = malloc(sizeof(napi_ref));
NAPI_CALL(env, napi_wrap(env,
wrapObject,
ref_t,
DeleteBeforeFinalizeFinalizer,
NULL,
NULL));
NODE_API_CALL(env,
napi_wrap(
env, wrapObject, ref_t, DeleteBeforeFinalizeFinalizer, NULL, NULL));
// Create a reference that will be eligible for collection at the same
// time as the wrapped object by passing in the same wrapObject.
@ -165,28 +162,28 @@ static napi_value ValidateDeleteBeforeFinalize(napi_env env, napi_callback_info
// for the reference) calls napi_delete_reference validating that
// napi_delete_reference can be called before the finalizer for the
// reference runs.
NAPI_CALL(env, napi_create_reference(env, wrapObject, 0, ref_t));
NODE_API_CALL(env, napi_create_reference(env, wrapObject, 0, ref_t));
return wrapObject;
}
EXTERN_C_START
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_GETTER("finalizeCount", GetFinalizeCount),
DECLARE_NAPI_PROPERTY("createExternal", CreateExternal),
DECLARE_NAPI_PROPERTY("createExternalWithFinalize",
DECLARE_NODE_API_GETTER("finalizeCount", GetFinalizeCount),
DECLARE_NODE_API_PROPERTY("createExternal", CreateExternal),
DECLARE_NODE_API_PROPERTY("createExternalWithFinalize",
CreateExternalWithFinalize),
DECLARE_NAPI_PROPERTY("checkExternal", CheckExternal),
DECLARE_NAPI_PROPERTY("createReference", CreateReference),
DECLARE_NAPI_PROPERTY("deleteReference", DeleteReference),
DECLARE_NAPI_PROPERTY("incrementRefcount", IncrementRefcount),
DECLARE_NAPI_PROPERTY("decrementRefcount", DecrementRefcount),
DECLARE_NAPI_GETTER("referenceValue", GetReferenceValue),
DECLARE_NAPI_PROPERTY("validateDeleteBeforeFinalize",
ValidateDeleteBeforeFinalize),
DECLARE_NODE_API_PROPERTY("checkExternal", CheckExternal),
DECLARE_NODE_API_PROPERTY("createReference", CreateReference),
DECLARE_NODE_API_PROPERTY("deleteReference", DeleteReference),
DECLARE_NODE_API_PROPERTY("incrementRefcount", IncrementRefcount),
DECLARE_NODE_API_PROPERTY("decrementRefcount", DecrementRefcount),
DECLARE_NODE_API_GETTER("referenceValue", GetReferenceValue),
DECLARE_NODE_API_PROPERTY("validateDeleteBeforeFinalize",
ValidateDeleteBeforeFinalize),
};
NAPI_CALL(env, napi_define_properties(
NODE_API_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;