diff --git a/test/node-api/test_async/binding.gyp b/test/node-api/test_async/binding.gyp index cf8beb70c68e78..d8436e2b1d189f 100644 --- a/test/node-api/test_async/binding.gyp +++ b/test/node-api/test_async/binding.gyp @@ -2,7 +2,7 @@ "targets": [ { "target_name": "test_async", - "sources": [ "test_async.cc" ] + "sources": [ "test_async.c" ] } ] } diff --git a/test/node-api/test_async/test_async.cc b/test/node-api/test_async/test_async.c similarity index 79% rename from test/node-api/test_async/test_async.cc rename to test/node-api/test_async/test_async.c index ff3d2749a9d184..57348a878377d9 100644 --- a/test/node-api/test_async/test_async.cc +++ b/test/node-api/test_async/test_async.c @@ -22,29 +22,29 @@ typedef struct { carrier the_carrier; carrier async_carrier[MAX_CANCEL_THREADS]; -void Execute(napi_env env, void* data) { +static void Execute(napi_env env, void* data) { #if defined _WIN32 Sleep(1000); #else sleep(1); #endif - carrier* c = static_cast(data); + carrier* c = (carrier*)(data); assert(c == &the_carrier); c->_output = c->_input * 2; } -void Complete(napi_env env, napi_status status, void* data) { - carrier* c = static_cast(data); +static void Complete(napi_env env, napi_status status, void* data) { + carrier* c = (carrier*)(data); if (c != &the_carrier) { - napi_throw_type_error(env, nullptr, "Wrong data parameter to Complete."); + napi_throw_type_error(env, NULL, "Wrong data parameter to Complete."); return; } if (status != napi_ok) { - napi_throw_type_error(env, nullptr, "Execute callback failed."); + napi_throw_type_error(env, NULL, "Execute callback failed."); return; } @@ -66,7 +66,7 @@ void Complete(napi_env env, napi_status status, void* data) { NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, c->_request)); } -napi_value Test(napi_env env, napi_callback_info info) { +static napi_value Test(napi_env env, napi_callback_info info) { size_t argc = 3; napi_value argv[3]; napi_value _this; @@ -101,16 +101,16 @@ napi_value Test(napi_env env, napi_callback_info info) { NAPI_CALL(env, napi_queue_async_work(env, the_carrier._request)); - return nullptr; + return NULL; } -void BusyCancelComplete(napi_env env, napi_status status, void* data) { - carrier* c = static_cast(data); +static void BusyCancelComplete(napi_env env, napi_status status, void* data) { + carrier* c = (carrier*)(data); NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, c->_request)); } -void CancelComplete(napi_env env, napi_status status, void* data) { - carrier* c = static_cast(data); +static void CancelComplete(napi_env env, napi_status status, void* data) { + carrier* c = (carrier*)(data); if (status == napi_cancelled) { // ok we got the status we expected so make the callback to @@ -122,14 +122,14 @@ void CancelComplete(napi_env env, napi_status status, void* data) { NAPI_CALL_RETURN_VOID(env, napi_get_global(env, &global)); napi_value result; NAPI_CALL_RETURN_VOID(env, - napi_call_function(env, global, callback, 0, nullptr, &result)); + napi_call_function(env, global, callback, 0, NULL, &result)); } NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, c->_request)); NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, c->_callback)); } -void CancelExecute(napi_env env, void* data) { +static void CancelExecute(napi_env env, void* data) { #if defined _WIN32 Sleep(1000); #else @@ -137,7 +137,7 @@ void CancelExecute(napi_env env, void* data) { #endif } -napi_value TestCancel(napi_env env, napi_callback_info info) { +static napi_value TestCancel(napi_env env, napi_callback_info info) { size_t argc = 1; napi_value argv[1]; napi_value _this; @@ -150,7 +150,7 @@ napi_value TestCancel(napi_env env, napi_callback_info info) { // make sure the work we are going to cancel will not be // able to start by using all the threads in the pool for (int i = 1; i < MAX_CANCEL_THREADS; i++) { - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource_name, + NAPI_CALL(env, napi_create_async_work(env, NULL, resource_name, CancelExecute, BusyCancelComplete, &async_carrier[i], &async_carrier[i]._request)); NAPI_CALL(env, napi_queue_async_work(env, async_carrier[i]._request)); @@ -162,20 +162,20 @@ napi_value TestCancel(napi_env env, napi_callback_info info) { // workers above. NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &_this, &data)); - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource_name, + NAPI_CALL(env, napi_create_async_work(env, NULL, resource_name, CancelExecute, CancelComplete, &async_carrier[0], &async_carrier[0]._request)); NAPI_CALL(env, napi_create_reference(env, argv[0], 1, &async_carrier[0]._callback)); NAPI_CALL(env, napi_queue_async_work(env, async_carrier[0]._request)); NAPI_CALL(env, napi_cancel_async_work(env, async_carrier[0]._request)); - return nullptr; + return NULL; } struct { napi_ref ref; napi_async_work work; -} repeated_work_info = { nullptr, nullptr }; +} repeated_work_info = { NULL, NULL }; static void RepeatedWorkerThread(napi_env env, void* data) {} @@ -187,33 +187,33 @@ static void RepeatedWorkComplete(napi_env env, napi_status status, void* data) { napi_delete_async_work(env, repeated_work_info.work)); NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, repeated_work_info.ref)); - repeated_work_info.work = nullptr; - repeated_work_info.ref = nullptr; + repeated_work_info.work = NULL; + repeated_work_info.ref = NULL; NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, (uint32_t)status, &js_status)); NAPI_CALL_RETURN_VOID(env, - napi_call_function(env, cb, cb, 1, &js_status, nullptr)); + napi_call_function(env, cb, cb, 1, &js_status, NULL)); } static napi_value DoRepeatedWork(napi_env env, napi_callback_info info) { size_t argc = 1; napi_value cb, name; - NAPI_ASSERT(env, repeated_work_info.ref == nullptr, + NAPI_ASSERT(env, repeated_work_info.ref == NULL, "Reference left over from previous work"); - NAPI_ASSERT(env, repeated_work_info.work == nullptr, + NAPI_ASSERT(env, repeated_work_info.work == NULL, "Work pointer left over from previous work"); - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &cb, nullptr, nullptr)); + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &cb, NULL, NULL)); NAPI_CALL(env, napi_create_reference(env, cb, 1, &repeated_work_info.ref)); NAPI_CALL(env, napi_create_string_utf8(env, "Repeated Work", NAPI_AUTO_LENGTH, &name)); NAPI_CALL(env, - napi_create_async_work(env, nullptr, name, RepeatedWorkerThread, + napi_create_async_work(env, NULL, name, RepeatedWorkerThread, RepeatedWorkComplete, &repeated_work_info, &repeated_work_info.work)); NAPI_CALL(env, napi_queue_async_work(env, repeated_work_info.work)); - return nullptr; + return NULL; } -napi_value Init(napi_env env, napi_value exports) { +static napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor properties[] = { DECLARE_NAPI_PROPERTY("Test", Test), DECLARE_NAPI_PROPERTY("TestCancel", TestCancel), diff --git a/test/node-api/test_callback_scope/binding.cc b/test/node-api/test_callback_scope/binding.c similarity index 76% rename from test/node-api/test_callback_scope/binding.cc rename to test/node-api/test_callback_scope/binding.c index a8a755a016a7ee..d512219e7bfa58 100644 --- a/test/node-api/test_callback_scope/binding.cc +++ b/test/node-api/test_callback_scope/binding.c @@ -1,17 +1,16 @@ +#include #include "node_api.h" #include "uv.h" #include "../../js-native-api/common.h" -namespace { - -napi_value RunInCallbackScope(napi_env env, napi_callback_info info) { +static napi_value RunInCallbackScope(napi_env env, napi_callback_info info) { size_t argc; napi_value args[3]; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, nullptr, nullptr)); + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, NULL, NULL, NULL)); NAPI_ASSERT(env, argc == 3 , "Wrong number of arguments"); - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); napi_valuetype valuetype; NAPI_CALL(env, napi_typeof(env, args[0], &valuetype)); @@ -29,7 +28,7 @@ napi_value RunInCallbackScope(napi_env env, napi_callback_info info) { napi_async_context context; NAPI_CALL(env, napi_async_init(env, args[0], args[1], &context)); - napi_callback_scope scope = nullptr; + napi_callback_scope scope = NULL; NAPI_CALL( env, napi_open_callback_scope(env, @@ -39,9 +38,9 @@ napi_value RunInCallbackScope(napi_env env, napi_callback_info info) { // if the function has an exception pending after the call that is ok // so we don't use NAPI_CALL as we must close the callback scope regardless - napi_value result = nullptr; + napi_value result = NULL; napi_status function_call_result = - napi_call_function(env, args[0], args[2], 0, nullptr, &result); + napi_call_function(env, args[0], args[2], 0, NULL, &result); if (function_call_result != napi_ok) { GET_AND_THROW_LAST_ERROR((env)); } @@ -52,13 +51,13 @@ napi_value RunInCallbackScope(napi_env env, napi_callback_info info) { return result; } -static napi_env shared_env = nullptr; -static napi_deferred deferred = nullptr; +static napi_env shared_env = NULL; +static napi_deferred deferred = NULL; static void Callback(uv_work_t* req, int ignored) { napi_env env = shared_env; - napi_handle_scope handle_scope = nullptr; + napi_handle_scope handle_scope = NULL; NAPI_CALL_RETURN_VOID(env, napi_open_handle_scope(env, &handle_scope)); napi_value resource_name; @@ -66,7 +65,7 @@ static void Callback(uv_work_t* req, int ignored) { env, "test", NAPI_AUTO_LENGTH, &resource_name)); napi_async_context context; NAPI_CALL_RETURN_VOID(env, - napi_async_init(env, nullptr, resource_name, &context)); + napi_async_init(env, NULL, resource_name, &context)); napi_value resource_object; NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &resource_object)); @@ -74,7 +73,7 @@ static void Callback(uv_work_t* req, int ignored) { napi_value undefined_value; NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined_value)); - napi_callback_scope scope = nullptr; + napi_callback_scope scope = NULL; NAPI_CALL_RETURN_VOID(env, napi_open_callback_scope(env, resource_object, context, @@ -87,28 +86,30 @@ static void Callback(uv_work_t* req, int ignored) { NAPI_CALL_RETURN_VOID(env, napi_close_handle_scope(env, handle_scope)); NAPI_CALL_RETURN_VOID(env, napi_async_destroy(env, context)); - delete req; + free(req); } -napi_value TestResolveAsync(napi_env env, napi_callback_info info) { - napi_value promise = nullptr; - if (deferred == nullptr) { +static void NoopWork(uv_work_t* work) { (void) work; } + +static napi_value TestResolveAsync(napi_env env, napi_callback_info info) { + napi_value promise = NULL; + if (deferred == NULL) { shared_env = env; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - uv_loop_t* loop = nullptr; + uv_loop_t* loop = NULL; NAPI_CALL(env, napi_get_uv_event_loop(env, &loop)); - uv_work_t* req = new uv_work_t(); + uv_work_t* req = malloc(sizeof(*req)); uv_queue_work(loop, req, - [](uv_work_t*) {}, + NoopWork, Callback); } return promise; } -napi_value Init(napi_env env, napi_value exports) { +static napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("runInCallbackScope", RunInCallbackScope), DECLARE_NAPI_PROPERTY("testResolveAsync", TestResolveAsync) @@ -120,6 +121,4 @@ napi_value Init(napi_env env, napi_value exports) { return exports; } -} // anonymous namespace - NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/test/node-api/test_callback_scope/binding.gyp b/test/node-api/test_callback_scope/binding.gyp index 7ede63d94a0d77..23daf507916ff6 100644 --- a/test/node-api/test_callback_scope/binding.gyp +++ b/test/node-api/test_callback_scope/binding.gyp @@ -3,7 +3,7 @@ { 'target_name': 'binding', 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], - 'sources': [ 'binding.cc' ] + 'sources': [ 'binding.c' ] } ] } diff --git a/test/node-api/test_cleanup_hook/binding.cc b/test/node-api/test_cleanup_hook/binding.c similarity index 64% rename from test/node-api/test_cleanup_hook/binding.cc rename to test/node-api/test_cleanup_hook/binding.c index 9426716e674d22..981ab1e31ff11a 100644 --- a/test/node-api/test_cleanup_hook/binding.cc +++ b/test/node-api/test_cleanup_hook/binding.c @@ -2,23 +2,19 @@ #include "uv.h" #include "../../js-native-api/common.h" -namespace { - -void cleanup(void* arg) { - printf("cleanup(%d)\n", *static_cast(arg)); +static void cleanup(void* arg) { + printf("cleanup(%d)\n", *(int*)(arg)); } int secret = 42; int wrong_secret = 17; -napi_value Init(napi_env env, napi_value exports) { +static napi_value Init(napi_env env, napi_value exports) { napi_add_env_cleanup_hook(env, cleanup, &wrong_secret); napi_add_env_cleanup_hook(env, cleanup, &secret); napi_remove_env_cleanup_hook(env, cleanup, &wrong_secret); - return nullptr; + return NULL; } -} // anonymous namespace - NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/test/node-api/test_cleanup_hook/binding.gyp b/test/node-api/test_cleanup_hook/binding.gyp index 7ede63d94a0d77..23daf507916ff6 100644 --- a/test/node-api/test_cleanup_hook/binding.gyp +++ b/test/node-api/test_cleanup_hook/binding.gyp @@ -3,7 +3,7 @@ { 'target_name': 'binding', 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], - 'sources': [ 'binding.cc' ] + 'sources': [ 'binding.c' ] } ] } diff --git a/test/node-api/test_make_callback_recurse/binding.cc b/test/node-api/test_make_callback_recurse/binding.c similarity index 75% rename from test/node-api/test_make_callback_recurse/binding.cc rename to test/node-api/test_make_callback_recurse/binding.c index 93440ee4ce54c2..78f27e370babde 100644 --- a/test/node-api/test_make_callback_recurse/binding.cc +++ b/test/node-api/test_make_callback_recurse/binding.c @@ -1,10 +1,7 @@ #include #include "../../js-native-api/common.h" -#include -namespace { - -napi_value MakeCallback(napi_env env, napi_callback_info info) { +static napi_value MakeCallback(napi_env env, napi_callback_info info) { size_t argc = 2; napi_value args[2]; // NOLINTNEXTLINE (readability/null_usage) @@ -13,8 +10,8 @@ napi_value MakeCallback(napi_env env, napi_callback_info info) { napi_value recv = args[0]; napi_value func = args[1]; - napi_status status = napi_make_callback(env, nullptr /* async_context */, - recv, func, 0 /* argc */, nullptr /* argv */, nullptr /* result */); + napi_status status = napi_make_callback(env, NULL /* async_context */, + recv, func, 0 /* argc */, NULL /* argv */, NULL /* result */); bool isExceptionPending; NAPI_CALL(env, napi_is_exception_pending(env, &isExceptionPending)); @@ -25,14 +22,14 @@ napi_value MakeCallback(napi_env env, napi_callback_info info) { status = napi_get_and_clear_last_exception(env, &pending_error); NAPI_CALL(env, napi_throw_error((env), - nullptr, + NULL, "error when only pending exception expected")); } return recv; } -napi_value Init(napi_env env, napi_value exports) { +static napi_value Init(napi_env env, napi_value exports) { napi_value fn; NAPI_CALL(env, napi_create_function( // NOLINTNEXTLINE (readability/null_usage) @@ -41,6 +38,4 @@ napi_value Init(napi_env env, napi_value exports) { return exports; } -} // anonymous namespace - NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/test/node-api/test_make_callback_recurse/binding.gyp b/test/node-api/test_make_callback_recurse/binding.gyp index 7ede63d94a0d77..23daf507916ff6 100644 --- a/test/node-api/test_make_callback_recurse/binding.gyp +++ b/test/node-api/test_make_callback_recurse/binding.gyp @@ -3,7 +3,7 @@ { 'target_name': 'binding', 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], - 'sources': [ 'binding.cc' ] + 'sources': [ 'binding.c' ] } ] }