From 4a5ff028eb949cc475f89b8148d3263b444ea9f9 Mon Sep 17 00:00:00 2001 From: legendecas Date: Wed, 6 Sep 2023 21:11:09 +0800 Subject: [PATCH 1/2] test: avoid copying test source files Converting the helper functions to be inlined and making the helper file header only. --- Makefile | 1 + .../2_function_arguments.c | 1 + .../2_function_arguments/binding.gyp | 1 - test/js-native-api/3_callbacks/3_callbacks.c | 3 +- test/js-native-api/3_callbacks/binding.gyp | 1 - .../4_object_factory/4_object_factory.c | 1 + .../4_object_factory/binding.gyp | 1 - .../5_function_factory/5_function_factory.c | 1 + .../5_function_factory/binding.gyp | 1 - .../6_object_wrap/6_object_wrap.cc | 1 + test/js-native-api/6_object_wrap/binding.gyp | 1 - .../7_factory_wrap/7_factory_wrap.cc | 3 +- test/js-native-api/7_factory_wrap/binding.gyp | 1 - .../8_passing_wrapped/8_passing_wrapped.cc | 3 +- .../8_passing_wrapped/binding.gyp | 1 - test/js-native-api/common-inl.h | 56 +++++++++++++++ test/js-native-api/common.c | 48 ------------- test/js-native-api/common.h | 23 +++++-- .../{entry_point.c => entry_point.h} | 5 ++ test/js-native-api/test_array/binding.gyp | 1 - test/js-native-api/test_array/test_array.c | 1 + test/js-native-api/test_bigint/binding.gyp | 1 - test/js-native-api/test_bigint/test_bigint.c | 5 +- .../test_cannot_run_js/binding.gyp | 14 ---- .../test_cannot_run_js/test_cannot_run_js.c | 1 + .../test_constructor/binding.gyp | 2 - .../test_constructor/test_constructor.c | 1 + .../test_conversions/binding.gyp | 2 - .../test_conversions/test_conversions.c | 1 + test/js-native-api/test_dataview/binding.gyp | 1 - .../test_dataview/test_dataview.c | 1 + test/js-native-api/test_date/binding.gyp | 1 - test/js-native-api/test_date/test_date.c | 1 + test/js-native-api/test_error/binding.gyp | 1 - test/js-native-api/test_error/test_error.c | 1 + test/js-native-api/test_exception/binding.gyp | 1 - .../test_exception/test_exception.c | 1 + test/js-native-api/test_function/binding.gyp | 2 - .../test_function/test_function.c | 1 + test/js-native-api/test_general/binding.gyp | 1 - .../js-native-api/test_general/test_general.c | 5 +- .../test_handle_scope/binding.gyp | 1 - .../test_handle_scope/test_handle_scope.c | 3 +- .../test_instance_data/binding.gyp | 1 - .../test_instance_data/test_instance_data.c | 3 +- .../js-native-api/test_new_target/binding.gyp | 1 - .../test_new_target/test_new_target.c | 1 + test/js-native-api/test_number/binding.gyp | 2 - test/js-native-api/test_number/test_number.c | 1 + test/js-native-api/test_object/binding.gyp | 2 - test/js-native-api/test_object/test_object.c | 3 +- test/js-native-api/test_promise/binding.gyp | 1 - .../js-native-api/test_promise/test_promise.c | 1 + .../js-native-api/test_properties/binding.gyp | 1 - .../test_properties/test_properties.c | 1 + test/js-native-api/test_reference/binding.gyp | 1 - .../test_reference/test_reference.c | 69 ++++++++++--------- .../test_reference_double_free/binding.gyp | 1 - .../test_reference_double_free.c | 3 +- test/js-native-api/test_string/binding.gyp | 2 - test/js-native-api/test_string/test_string.c | 1 + test/js-native-api/test_symbol/binding.gyp | 1 - test/js-native-api/test_symbol/test_symbol.c | 1 + .../js-native-api/test_typedarray/binding.gyp | 1 - .../test_typedarray/test_typedarray.c | 3 +- 65 files changed, 156 insertions(+), 148 deletions(-) create mode 100644 test/js-native-api/common-inl.h delete mode 100644 test/js-native-api/common.c rename test/js-native-api/{entry_point.c => entry_point.h} (55%) diff --git a/Makefile b/Makefile index b1c267ed5526fe..47eb7288ad36b0 100644 --- a/Makefile +++ b/Makefile @@ -1423,6 +1423,7 @@ FORMAT_CPP_FILES += $(LINT_CPP_FILES) # C source codes. FORMAT_CPP_FILES += $(wildcard \ benchmark/napi/*/*.c \ + test/js-native-api/*.h \ test/js-native-api/*/*.c \ test/js-native-api/*/*.h \ test/node-api/*/*.c \ diff --git a/test/js-native-api/2_function_arguments/2_function_arguments.c b/test/js-native-api/2_function_arguments/2_function_arguments.c index 2f7a196f65c0b3..123d9116b35c90 100644 --- a/test/js-native-api/2_function_arguments/2_function_arguments.c +++ b/test/js-native-api/2_function_arguments/2_function_arguments.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" static napi_value Add(napi_env env, napi_callback_info info) { size_t argc = 2; diff --git a/test/js-native-api/2_function_arguments/binding.gyp b/test/js-native-api/2_function_arguments/binding.gyp index 7e35a4c9d6dc05..77836418d4736e 100644 --- a/test/js-native-api/2_function_arguments/binding.gyp +++ b/test/js-native-api/2_function_arguments/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "2_function_arguments", "sources": [ - "../entry_point.c", "2_function_arguments.c" ] } diff --git a/test/js-native-api/3_callbacks/3_callbacks.c b/test/js-native-api/3_callbacks/3_callbacks.c index 3be18daff1d7a6..44bd2455749145 100644 --- a/test/js-native-api/3_callbacks/3_callbacks.c +++ b/test/js-native-api/3_callbacks/3_callbacks.c @@ -1,6 +1,7 @@ #include -#include "../common.h" #include +#include "../common.h" +#include "../entry_point.h" static napi_value RunCallback(napi_env env, napi_callback_info info) { size_t argc = 2; diff --git a/test/js-native-api/3_callbacks/binding.gyp b/test/js-native-api/3_callbacks/binding.gyp index 3cc662c4076dc1..0b3e2eb96cd903 100644 --- a/test/js-native-api/3_callbacks/binding.gyp +++ b/test/js-native-api/3_callbacks/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "3_callbacks", "sources": [ - "../entry_point.c", "3_callbacks.c" ] } diff --git a/test/js-native-api/4_object_factory/4_object_factory.c b/test/js-native-api/4_object_factory/4_object_factory.c index 5b06517744dd3e..8fd6090f22a37e 100644 --- a/test/js-native-api/4_object_factory/4_object_factory.c +++ b/test/js-native-api/4_object_factory/4_object_factory.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" static napi_value CreateObject(napi_env env, napi_callback_info info) { size_t argc = 1; diff --git a/test/js-native-api/4_object_factory/binding.gyp b/test/js-native-api/4_object_factory/binding.gyp index 6cb3a9fa68b48a..c1f2aca1498346 100644 --- a/test/js-native-api/4_object_factory/binding.gyp +++ b/test/js-native-api/4_object_factory/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "4_object_factory", "sources": [ - "../entry_point.c", "4_object_factory.c" ] } diff --git a/test/js-native-api/5_function_factory/5_function_factory.c b/test/js-native-api/5_function_factory/5_function_factory.c index 679f09fee9e49e..8c2bdac5bd5f94 100644 --- a/test/js-native-api/5_function_factory/5_function_factory.c +++ b/test/js-native-api/5_function_factory/5_function_factory.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" static napi_value MyFunction(napi_env env, napi_callback_info info) { napi_value str; diff --git a/test/js-native-api/5_function_factory/binding.gyp b/test/js-native-api/5_function_factory/binding.gyp index c621c29f185cab..183332d3441112 100644 --- a/test/js-native-api/5_function_factory/binding.gyp +++ b/test/js-native-api/5_function_factory/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "5_function_factory", "sources": [ - "../entry_point.c", "5_function_factory.c" ] } diff --git a/test/js-native-api/6_object_wrap/6_object_wrap.cc b/test/js-native-api/6_object_wrap/6_object_wrap.cc index 7ebe711a6dccf1..49b1241fb38caa 100644 --- a/test/js-native-api/6_object_wrap/6_object_wrap.cc +++ b/test/js-native-api/6_object_wrap/6_object_wrap.cc @@ -1,4 +1,5 @@ #include "../common.h" +#include "../entry_point.h" #include "assert.h" #include "myobject.h" diff --git a/test/js-native-api/6_object_wrap/binding.gyp b/test/js-native-api/6_object_wrap/binding.gyp index 2807d6a1572529..44c9c3f837b4a6 100644 --- a/test/js-native-api/6_object_wrap/binding.gyp +++ b/test/js-native-api/6_object_wrap/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "6_object_wrap", "sources": [ - "../entry_point.c", "6_object_wrap.cc" ] } diff --git a/test/js-native-api/7_factory_wrap/7_factory_wrap.cc b/test/js-native-api/7_factory_wrap/7_factory_wrap.cc index b1dbd8eee4945f..5fb7a6670d74d8 100644 --- a/test/js-native-api/7_factory_wrap/7_factory_wrap.cc +++ b/test/js-native-api/7_factory_wrap/7_factory_wrap.cc @@ -1,6 +1,7 @@ #include -#include "myobject.h" #include "../common.h" +#include "../entry_point.h" +#include "myobject.h" napi_value CreateObject(napi_env env, napi_callback_info info) { size_t argc = 1; diff --git a/test/js-native-api/7_factory_wrap/binding.gyp b/test/js-native-api/7_factory_wrap/binding.gyp index f9096674a70b5c..bb7c8aab1826a2 100644 --- a/test/js-native-api/7_factory_wrap/binding.gyp +++ b/test/js-native-api/7_factory_wrap/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "7_factory_wrap", "sources": [ - "../entry_point.c", "7_factory_wrap.cc", "myobject.cc" ] diff --git a/test/js-native-api/8_passing_wrapped/8_passing_wrapped.cc b/test/js-native-api/8_passing_wrapped/8_passing_wrapped.cc index 5b3b7909582e21..1a3e6d1072045b 100644 --- a/test/js-native-api/8_passing_wrapped/8_passing_wrapped.cc +++ b/test/js-native-api/8_passing_wrapped/8_passing_wrapped.cc @@ -1,6 +1,7 @@ #include -#include "myobject.h" #include "../common.h" +#include "../entry_point.h" +#include "myobject.h" extern size_t finalize_count; diff --git a/test/js-native-api/8_passing_wrapped/binding.gyp b/test/js-native-api/8_passing_wrapped/binding.gyp index f85cc4cc97ae45..206d106e52cf94 100644 --- a/test/js-native-api/8_passing_wrapped/binding.gyp +++ b/test/js-native-api/8_passing_wrapped/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "8_passing_wrapped", "sources": [ - "../entry_point.c", "8_passing_wrapped.cc", "myobject.cc" ] diff --git a/test/js-native-api/common-inl.h b/test/js-native-api/common-inl.h new file mode 100644 index 00000000000000..d4db4a3e58bdc6 --- /dev/null +++ b/test/js-native-api/common-inl.h @@ -0,0 +1,56 @@ +#ifndef JS_NATIVE_API_COMMON_INL_H_ +#define JS_NATIVE_API_COMMON_INL_H_ + +#include +#include "common.h" + +#include + +inline void add_returned_status(napi_env env, + const char* key, + napi_value object, + char* expected_message, + napi_status expected_status, + napi_status actual_status) { + char napi_message_string[100] = ""; + napi_value prop_value; + + if (actual_status != expected_status) { + snprintf(napi_message_string, + sizeof(napi_message_string), + "Invalid status [%d]", + actual_status); + } + + NODE_API_CALL_RETURN_VOID( + env, + napi_create_string_utf8( + env, + (actual_status == expected_status ? expected_message + : napi_message_string), + NAPI_AUTO_LENGTH, + &prop_value)); + NODE_API_CALL_RETURN_VOID( + env, napi_set_named_property(env, object, key, prop_value)); +} + +inline void add_last_status(napi_env env, + const char* key, + napi_value return_value) { + napi_value prop_value; + const napi_extended_error_info* p_last_error; + NODE_API_CALL_RETURN_VOID(env, napi_get_last_error_info(env, &p_last_error)); + + NODE_API_CALL_RETURN_VOID( + env, + napi_create_string_utf8( + env, + (p_last_error->error_message == NULL ? "napi_ok" + : p_last_error->error_message), + NAPI_AUTO_LENGTH, + &prop_value)); + NODE_API_CALL_RETURN_VOID( + env, napi_set_named_property(env, return_value, key, prop_value)); +} + +#endif // JS_NATIVE_API_COMMON_INL_H_ diff --git a/test/js-native-api/common.c b/test/js-native-api/common.c deleted file mode 100644 index 865d2064bdef85..00000000000000 --- a/test/js-native-api/common.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include "common.h" - -#include - -void add_returned_status(napi_env env, - const char* key, - napi_value object, - char* expected_message, - napi_status expected_status, - napi_status actual_status) { - - char napi_message_string[100] = ""; - napi_value prop_value; - - if (actual_status != expected_status) { - snprintf(napi_message_string, sizeof(napi_message_string), - "Invalid status [%d]", actual_status); - } - - NODE_API_CALL_RETURN_VOID(env, - napi_create_string_utf8( - env, - (actual_status == expected_status ? - expected_message : - napi_message_string), - NAPI_AUTO_LENGTH, - &prop_value)); - NODE_API_CALL_RETURN_VOID(env, - napi_set_named_property(env, object, key, prop_value)); -} - -void add_last_status(napi_env env, const char* key, napi_value return_value) { - napi_value prop_value; - const napi_extended_error_info* p_last_error; - NODE_API_CALL_RETURN_VOID(env, - napi_get_last_error_info(env, &p_last_error)); - - NODE_API_CALL_RETURN_VOID(env, - napi_create_string_utf8(env, - (p_last_error->error_message == NULL ? - "napi_ok" : - p_last_error->error_message), - NAPI_AUTO_LENGTH, - &prop_value)); - NODE_API_CALL_RETURN_VOID(env, - napi_set_named_property(env, return_value, key, prop_value)); -} diff --git a/test/js-native-api/common.h b/test/js-native-api/common.h index 25b26fb09137c5..fc6f4cb6c2e1db 100644 --- a/test/js-native-api/common.h +++ b/test/js-native-api/common.h @@ -1,3 +1,6 @@ +#ifndef JS_NATIVE_API_COMMON_H_ +#define JS_NATIVE_API_COMMON_H_ + #include // Empty value so that macros here are able to return NULL or void @@ -76,11 +79,17 @@ #define DECLARE_NODE_API_PROPERTY_VALUE(name, value) \ { (name), NULL, NULL, NULL, NULL, (value), napi_default, NULL } -void add_returned_status(napi_env env, - const char* key, - napi_value object, - char* expected_message, - napi_status expected_status, - napi_status actual_status); +static inline void add_returned_status(napi_env env, + const char* key, + napi_value object, + char* expected_message, + napi_status expected_status, + napi_status actual_status); + +static inline void add_last_status(napi_env env, + const char* key, + napi_value return_value); + +#include "common-inl.h" -void add_last_status(napi_env env, const char* key, napi_value return_value); +#endif // JS_NATIVE_API_COMMON_H_ diff --git a/test/js-native-api/entry_point.c b/test/js-native-api/entry_point.h similarity index 55% rename from test/js-native-api/entry_point.c rename to test/js-native-api/entry_point.h index 6b7b50a38c9535..5ba5aaffa62312 100644 --- a/test/js-native-api/entry_point.c +++ b/test/js-native-api/entry_point.h @@ -1,3 +1,6 @@ +#ifndef JS_NATIVE_API_ENTRY_POINT_H_ +#define JS_NATIVE_API_ENTRY_POINT_H_ + #include EXTERN_C_START @@ -5,3 +8,5 @@ napi_value Init(napi_env env, napi_value exports); EXTERN_C_END NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) + +#endif // JS_NATIVE_API_ENTRY_POINT_H_ diff --git a/test/js-native-api/test_array/binding.gyp b/test/js-native-api/test_array/binding.gyp index feb6bd37d88b28..ba19b16e397ad8 100644 --- a/test/js-native-api/test_array/binding.gyp +++ b/test/js-native-api/test_array/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_array", "sources": [ - "../entry_point.c", "test_array.c" ] } diff --git a/test/js-native-api/test_array/test_array.c b/test/js-native-api/test_array/test_array.c index 846755a97b7059..a4515025fc217c 100644 --- a/test/js-native-api/test_array/test_array.c +++ b/test/js-native-api/test_array/test_array.c @@ -1,6 +1,7 @@ #include #include #include "../common.h" +#include "../entry_point.h" static napi_value TestGetElement(napi_env env, napi_callback_info info) { size_t argc = 2; diff --git a/test/js-native-api/test_bigint/binding.gyp b/test/js-native-api/test_bigint/binding.gyp index 84db32bf3ea131..6ef04b4394ae8a 100644 --- a/test/js-native-api/test_bigint/binding.gyp +++ b/test/js-native-api/test_bigint/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_bigint", "sources": [ - "../entry_point.c", "test_bigint.c" ] } diff --git a/test/js-native-api/test_bigint/test_bigint.c b/test/js-native-api/test_bigint/test_bigint.c index c63c2f7fe29b44..2c61e0b217ecb4 100644 --- a/test/js-native-api/test_bigint/test_bigint.c +++ b/test/js-native-api/test_bigint/test_bigint.c @@ -1,8 +1,9 @@ -#include #include -#include #include +#include +#include #include "../common.h" +#include "../entry_point.h" static napi_value IsLossless(napi_env env, napi_callback_info info) { size_t argc = 2; 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 210417b47b17ec..0b827ff34d129f 100644 --- a/test/js-native-api/test_cannot_run_js/binding.gyp +++ b/test/js-native-api/test_cannot_run_js/binding.gyp @@ -1,32 +1,18 @@ { "targets": [ - { - "target_name": "copy_entry_point", - "type": "none", - "copies": [ - { - "destination": ".", - "files": [ "../entry_point.c" ] - } - ] - }, { "target_name": "test_cannot_run_js", "sources": [ - "entry_point.c", "test_cannot_run_js.c" ], "defines": [ "NAPI_EXPERIMENTAL" ], - "dependencies": [ "copy_entry_point" ], }, { "target_name": "test_pending_exception", "sources": [ - "entry_point.c", "test_cannot_run_js.c" ], "defines": [ "NAPI_VERSION=8" ], - "dependencies": [ "copy_entry_point" ], } ] } 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 6f2a6e71b8dc22..2cd25823c924c0 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 @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" #include "stdlib.h" static void Finalize(napi_env env, void* data, void* hint) { diff --git a/test/js-native-api/test_constructor/binding.gyp b/test/js-native-api/test_constructor/binding.gyp index 019114f64651c6..d796a9dbf1cf44 100644 --- a/test/js-native-api/test_constructor/binding.gyp +++ b/test/js-native-api/test_constructor/binding.gyp @@ -3,8 +3,6 @@ { "target_name": "test_constructor", "sources": [ - "../common.c", - "../entry_point.c", "test_constructor.c", "test_null.c", ] diff --git a/test/js-native-api/test_constructor/test_constructor.c b/test/js-native-api/test_constructor/test_constructor.c index 92b03985513d36..c706170bac4a8c 100644 --- a/test/js-native-api/test_constructor/test_constructor.c +++ b/test/js-native-api/test_constructor/test_constructor.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" #include "test_null.h" static double value_ = 1; diff --git a/test/js-native-api/test_conversions/binding.gyp b/test/js-native-api/test_conversions/binding.gyp index f1640c6638e41e..c286c3fd029203 100644 --- a/test/js-native-api/test_conversions/binding.gyp +++ b/test/js-native-api/test_conversions/binding.gyp @@ -3,8 +3,6 @@ { "target_name": "test_conversions", "sources": [ - "../entry_point.c", - "../common.c", "test_conversions.c", "test_null.c", ] diff --git a/test/js-native-api/test_conversions/test_conversions.c b/test/js-native-api/test_conversions/test_conversions.c index 500962d5144e0f..89b93ef0112513 100644 --- a/test/js-native-api/test_conversions/test_conversions.c +++ b/test/js-native-api/test_conversions/test_conversions.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" #include "test_null.h" static napi_value AsBool(napi_env env, napi_callback_info info) { diff --git a/test/js-native-api/test_dataview/binding.gyp b/test/js-native-api/test_dataview/binding.gyp index b8d641f5c0f34e..64235390812d79 100644 --- a/test/js-native-api/test_dataview/binding.gyp +++ b/test/js-native-api/test_dataview/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_dataview", "sources": [ - "../entry_point.c", "test_dataview.c" ] } diff --git a/test/js-native-api/test_dataview/test_dataview.c b/test/js-native-api/test_dataview/test_dataview.c index c614a79818cb85..9f62b734c6a9ef 100644 --- a/test/js-native-api/test_dataview/test_dataview.c +++ b/test/js-native-api/test_dataview/test_dataview.c @@ -1,6 +1,7 @@ #include #include #include "../common.h" +#include "../entry_point.h" static napi_value CreateDataView(napi_env env, napi_callback_info info) { size_t argc = 3; diff --git a/test/js-native-api/test_date/binding.gyp b/test/js-native-api/test_date/binding.gyp index a65a4e1387235a..6039d122c7649a 100644 --- a/test/js-native-api/test_date/binding.gyp +++ b/test/js-native-api/test_date/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_date", "sources": [ - "../entry_point.c", "test_date.c" ] } diff --git a/test/js-native-api/test_date/test_date.c b/test/js-native-api/test_date/test_date.c index d5e9c778a9cd8f..ef87d6da350d02 100644 --- a/test/js-native-api/test_date/test_date.c +++ b/test/js-native-api/test_date/test_date.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" static napi_value createDate(napi_env env, napi_callback_info info) { size_t argc = 1; diff --git a/test/js-native-api/test_error/binding.gyp b/test/js-native-api/test_error/binding.gyp index 617ececb89fcb5..46382427fe669c 100644 --- a/test/js-native-api/test_error/binding.gyp +++ b/test/js-native-api/test_error/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_error", "sources": [ - "../entry_point.c", "test_error.c" ] } diff --git a/test/js-native-api/test_error/test_error.c b/test/js-native-api/test_error/test_error.c index 43e98921efadb0..f34798263dba3e 100644 --- a/test/js-native-api/test_error/test_error.c +++ b/test/js-native-api/test_error/test_error.c @@ -1,6 +1,7 @@ #define NAPI_VERSION 9 #include #include "../common.h" +#include "../entry_point.h" static napi_value checkError(napi_env env, napi_callback_info info) { size_t argc = 1; diff --git a/test/js-native-api/test_exception/binding.gyp b/test/js-native-api/test_exception/binding.gyp index 4844346a139338..e98a564a10feac 100644 --- a/test/js-native-api/test_exception/binding.gyp +++ b/test/js-native-api/test_exception/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_exception", "sources": [ - "../entry_point.c", "test_exception.c" ] } diff --git a/test/js-native-api/test_exception/test_exception.c b/test/js-native-api/test_exception/test_exception.c index 053f048466d930..84b991961ae136 100644 --- a/test/js-native-api/test_exception/test_exception.c +++ b/test/js-native-api/test_exception/test_exception.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" static bool exceptionWasPending = false; static int num = 0x23432; diff --git a/test/js-native-api/test_function/binding.gyp b/test/js-native-api/test_function/binding.gyp index df70facefc00cb..7ea9400c351b88 100644 --- a/test/js-native-api/test_function/binding.gyp +++ b/test/js-native-api/test_function/binding.gyp @@ -3,8 +3,6 @@ { "target_name": "test_function", "sources": [ - "../common.c", - "../entry_point.c", "test_function.c" ] } diff --git a/test/js-native-api/test_function/test_function.c b/test/js-native-api/test_function/test_function.c index 107727872a0655..02a2988dc3e265 100644 --- a/test/js-native-api/test_function/test_function.c +++ b/test/js-native-api/test_function/test_function.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" static napi_value TestCreateFunctionParameters(napi_env env, napi_callback_info info) { diff --git a/test/js-native-api/test_general/binding.gyp b/test/js-native-api/test_general/binding.gyp index 6a766dc5e40131..577a506f7fad73 100644 --- a/test/js-native-api/test_general/binding.gyp +++ b/test/js-native-api/test_general/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_general", "sources": [ - "../entry_point.c", "test_general.c" ] } diff --git a/test/js-native-api/test_general/test_general.c b/test/js-native-api/test_general/test_general.c index b474ab442cb763..0cd1c54ee142f1 100644 --- a/test/js-native-api/test_general/test_general.c +++ b/test/js-native-api/test_general/test_general.c @@ -3,11 +3,12 @@ // not related to any of the other tests // defined in the file #define NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED +#include +#include #include #include -#include -#include #include "../common.h" +#include "../entry_point.h" static napi_value testStrictEquals(napi_env env, napi_callback_info info) { size_t argc = 2; diff --git a/test/js-native-api/test_handle_scope/binding.gyp b/test/js-native-api/test_handle_scope/binding.gyp index 842bd5af7444ae..7959c47cb9039e 100644 --- a/test/js-native-api/test_handle_scope/binding.gyp +++ b/test/js-native-api/test_handle_scope/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_handle_scope", "sources": [ - "../entry_point.c", "test_handle_scope.c" ] } diff --git a/test/js-native-api/test_handle_scope/test_handle_scope.c b/test/js-native-api/test_handle_scope/test_handle_scope.c index 681cc04c4f4b68..832ce545d1fabe 100644 --- a/test/js-native-api/test_handle_scope/test_handle_scope.c +++ b/test/js-native-api/test_handle_scope/test_handle_scope.c @@ -1,6 +1,7 @@ #include -#include "../common.h" #include +#include "../common.h" +#include "../entry_point.h" // these tests validate the handle scope functions in the normal // flow. Forcing gc behavior to fully validate they are doing diff --git a/test/js-native-api/test_instance_data/binding.gyp b/test/js-native-api/test_instance_data/binding.gyp index 5b2d4ff328b4fa..0d55905e9e7236 100644 --- a/test/js-native-api/test_instance_data/binding.gyp +++ b/test/js-native-api/test_instance_data/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_instance_data", "sources": [ - "../entry_point.c", "test_instance_data.c" ] } diff --git a/test/js-native-api/test_instance_data/test_instance_data.c b/test/js-native-api/test_instance_data/test_instance_data.c index 95d41ed5f64994..5e33ddd75d47a5 100644 --- a/test/js-native-api/test_instance_data/test_instance_data.c +++ b/test/js-native-api/test_instance_data/test_instance_data.c @@ -1,7 +1,8 @@ +#include #include #include -#include #include "../common.h" +#include "../entry_point.h" typedef struct { size_t value; diff --git a/test/js-native-api/test_new_target/binding.gyp b/test/js-native-api/test_new_target/binding.gyp index f9cc6e83758ced..1afe797d1402b8 100644 --- a/test/js-native-api/test_new_target/binding.gyp +++ b/test/js-native-api/test_new_target/binding.gyp @@ -4,7 +4,6 @@ 'target_name': 'test_new_target', 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], 'sources': [ - '../entry_point.c', 'test_new_target.c' ] } diff --git a/test/js-native-api/test_new_target/test_new_target.c b/test/js-native-api/test_new_target/test_new_target.c index d3fe5b0d2d9568..4e2be97419c7f3 100644 --- a/test/js-native-api/test_new_target/test_new_target.c +++ b/test/js-native-api/test_new_target/test_new_target.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" static napi_value BaseClass(napi_env env, napi_callback_info info) { napi_value newTargetArg; diff --git a/test/js-native-api/test_number/binding.gyp b/test/js-native-api/test_number/binding.gyp index fa65304ba54089..c0a4cb62d9803e 100644 --- a/test/js-native-api/test_number/binding.gyp +++ b/test/js-native-api/test_number/binding.gyp @@ -3,8 +3,6 @@ { "target_name": "test_number", "sources": [ - "../common.c", - "../entry_point.c", "test_number.c", "test_null.c", ] diff --git a/test/js-native-api/test_number/test_number.c b/test/js-native-api/test_number/test_number.c index c8d4733f580a05..b8169451e62ad1 100644 --- a/test/js-native-api/test_number/test_number.c +++ b/test/js-native-api/test_number/test_number.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" #include "test_null.h" static napi_value Test(napi_env env, napi_callback_info info) { diff --git a/test/js-native-api/test_object/binding.gyp b/test/js-native-api/test_object/binding.gyp index e681f98f73ace6..b81f502584619e 100644 --- a/test/js-native-api/test_object/binding.gyp +++ b/test/js-native-api/test_object/binding.gyp @@ -3,8 +3,6 @@ { "target_name": "test_object", "sources": [ - "../common.c", - "../entry_point.c", "test_null.c", "test_object.c" ] diff --git a/test/js-native-api/test_object/test_object.c b/test/js-native-api/test_object/test_object.c index eb5aa2071e30a3..eddf805187507e 100644 --- a/test/js-native-api/test_object/test_object.c +++ b/test/js-native-api/test_object/test_object.c @@ -1,6 +1,7 @@ #include -#include "../common.h" #include +#include "../common.h" +#include "../entry_point.h" #include "test_null.h" static int test_value = 3; diff --git a/test/js-native-api/test_promise/binding.gyp b/test/js-native-api/test_promise/binding.gyp index fd777daf5e02cc..de2802f8607dcf 100644 --- a/test/js-native-api/test_promise/binding.gyp +++ b/test/js-native-api/test_promise/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_promise", "sources": [ - "../entry_point.c", "test_promise.c" ] } diff --git a/test/js-native-api/test_promise/test_promise.c b/test/js-native-api/test_promise/test_promise.c index 488ecea7853601..eef4813aa63774 100644 --- a/test/js-native-api/test_promise/test_promise.c +++ b/test/js-native-api/test_promise/test_promise.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" napi_deferred deferred = NULL; diff --git a/test/js-native-api/test_properties/binding.gyp b/test/js-native-api/test_properties/binding.gyp index adb6dd5ea151c3..ee38504eea75a6 100644 --- a/test/js-native-api/test_properties/binding.gyp +++ b/test/js-native-api/test_properties/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_properties", "sources": [ - "../entry_point.c", "test_properties.c" ] } diff --git a/test/js-native-api/test_properties/test_properties.c b/test/js-native-api/test_properties/test_properties.c index d822d3628d87fa..567dd8c3a44ecd 100644 --- a/test/js-native-api/test_properties/test_properties.c +++ b/test/js-native-api/test_properties/test_properties.c @@ -1,6 +1,7 @@ #define NAPI_VERSION 9 #include #include "../common.h" +#include "../entry_point.h" static double value_ = 1; diff --git a/test/js-native-api/test_reference/binding.gyp b/test/js-native-api/test_reference/binding.gyp index 518fd21c37c566..d8940028915f15 100644 --- a/test/js-native-api/test_reference/binding.gyp +++ b/test/js-native-api/test_reference/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_reference", "sources": [ - "../entry_point.c", "test_reference.c" ] } diff --git a/test/js-native-api/test_reference/test_reference.c b/test/js-native-api/test_reference/test_reference.c index c17f27021b4215..82c1f17d9dce0e 100644 --- a/test/js-native-api/test_reference/test_reference.c +++ b/test/js-native-api/test_reference/test_reference.c @@ -1,8 +1,9 @@ #define NAPI_VERSION 9 -#include #include #include +#include #include "../common.h" +#include "../entry_point.h" static int test_value = 1; static int finalize_count = 0; @@ -51,40 +52,44 @@ static napi_value CreateExternal(napi_env env, napi_callback_info info) { } static napi_value CreateSymbol(napi_env env, napi_callback_info info) { - - size_t argc = 1; - napi_value args[1]; - - NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL,NULL)); - NODE_API_ASSERT(env, argc == 1, "Expect one argument only (symbol description)"); - - napi_value result_symbol; - - NODE_API_CALL(env, napi_create_symbol(env, args[0], &result_symbol)); - return result_symbol; + size_t argc = 1; + napi_value args[1]; + + NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); + NODE_API_ASSERT( + env, argc == 1, "Expect one argument only (symbol description)"); + + napi_value result_symbol; + + NODE_API_CALL(env, napi_create_symbol(env, args[0], &result_symbol)); + return result_symbol; } static napi_value CreateSymbolFor(napi_env env, napi_callback_info info) { - - size_t argc = 1; - napi_value args[1]; - - char description[256]; - size_t description_length; - - NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL,NULL)); - NODE_API_ASSERT(env, argc == 1, "Expect one argument only (symbol description)"); - - NODE_API_CALL(env, napi_get_value_string_utf8(env, args[0], description, sizeof(description), &description_length)); - NODE_API_ASSERT(env, description_length <= 255, "Cannot accommodate descriptions longer than 255 bytes"); - - napi_value result_symbol; - - NODE_API_CALL(env, node_api_symbol_for(env, - description, - description_length, - &result_symbol)); - return result_symbol; + size_t argc = 1; + napi_value args[1]; + + char description[256]; + size_t description_length; + + NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); + NODE_API_ASSERT( + env, argc == 1, "Expect one argument only (symbol description)"); + + NODE_API_CALL( + env, + napi_get_value_string_utf8( + env, args[0], description, sizeof(description), &description_length)); + NODE_API_ASSERT(env, + description_length <= 255, + "Cannot accommodate descriptions longer than 255 bytes"); + + napi_value result_symbol; + + NODE_API_CALL(env, + node_api_symbol_for( + env, description, description_length, &result_symbol)); + return result_symbol; } static napi_value CreateSymbolForEmptyString(napi_env env, napi_callback_info info) { diff --git a/test/js-native-api/test_reference_double_free/binding.gyp b/test/js-native-api/test_reference_double_free/binding.gyp index 864846765d0132..2d906dadae6126 100644 --- a/test/js-native-api/test_reference_double_free/binding.gyp +++ b/test/js-native-api/test_reference_double_free/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_reference_double_free", "sources": [ - "../entry_point.c", "test_reference_double_free.c" ] } diff --git a/test/js-native-api/test_reference_double_free/test_reference_double_free.c b/test/js-native-api/test_reference_double_free/test_reference_double_free.c index f491d237fded3e..0e0f91caf98458 100644 --- a/test/js-native-api/test_reference_double_free/test_reference_double_free.c +++ b/test/js-native-api/test_reference_double_free/test_reference_double_free.c @@ -1,6 +1,7 @@ -#include #include +#include #include "../common.h" +#include "../entry_point.h" static size_t g_call_count = 0; diff --git a/test/js-native-api/test_string/binding.gyp b/test/js-native-api/test_string/binding.gyp index c2f55857d41fe7..63fec1ae3b5375 100644 --- a/test/js-native-api/test_string/binding.gyp +++ b/test/js-native-api/test_string/binding.gyp @@ -3,10 +3,8 @@ { "target_name": "test_string", "sources": [ - "../entry_point.c", "test_string.c", "test_null.c", - "../common.c", ] } ] diff --git a/test/js-native-api/test_string/test_string.c b/test/js-native-api/test_string/test_string.c index e4b79fe50f0774..b2046e3b873392 100644 --- a/test/js-native-api/test_string/test_string.c +++ b/test/js-native-api/test_string/test_string.c @@ -4,6 +4,7 @@ #define NAPI_EXPERIMENTAL #include #include "../common.h" +#include "../entry_point.h" #include "test_null.h" enum length_type { actual_length, auto_length }; diff --git a/test/js-native-api/test_symbol/binding.gyp b/test/js-native-api/test_symbol/binding.gyp index 254531dfa92869..c44a78d042f57c 100644 --- a/test/js-native-api/test_symbol/binding.gyp +++ b/test/js-native-api/test_symbol/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_symbol", "sources": [ - "../entry_point.c", "test_symbol.c" ] } diff --git a/test/js-native-api/test_symbol/test_symbol.c b/test/js-native-api/test_symbol/test_symbol.c index a87b275c938fbf..b14658298d517b 100644 --- a/test/js-native-api/test_symbol/test_symbol.c +++ b/test/js-native-api/test_symbol/test_symbol.c @@ -1,5 +1,6 @@ #include #include "../common.h" +#include "../entry_point.h" static napi_value New(napi_env env, napi_callback_info info) { size_t argc = 1; diff --git a/test/js-native-api/test_typedarray/binding.gyp b/test/js-native-api/test_typedarray/binding.gyp index 0caf90049cac5d..d708d2d2493bf6 100644 --- a/test/js-native-api/test_typedarray/binding.gyp +++ b/test/js-native-api/test_typedarray/binding.gyp @@ -3,7 +3,6 @@ { "target_name": "test_typedarray", "sources": [ - "../entry_point.c", "test_typedarray.c" ] } diff --git a/test/js-native-api/test_typedarray/test_typedarray.c b/test/js-native-api/test_typedarray/test_typedarray.c index 9a2031d256604d..240d024691e772 100644 --- a/test/js-native-api/test_typedarray/test_typedarray.c +++ b/test/js-native-api/test_typedarray/test_typedarray.c @@ -1,7 +1,8 @@ #include -#include #include +#include #include "../common.h" +#include "../entry_point.h" static napi_value Multiply(napi_env env, napi_callback_info info) { size_t argc = 2; From a483be76c7e6eaae6e4352ac519925f178deee40 Mon Sep 17 00:00:00 2001 From: legendecas Date: Fri, 8 Sep 2023 00:40:19 +0800 Subject: [PATCH 2/2] Revert "test: ignore the copied entry_point.c" This reverts commit d15652e95905fa6bfe7b55b6205a1b7298b8b4f8. --- test/js-native-api/.gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/test/js-native-api/.gitignore b/test/js-native-api/.gitignore index 9e3a464bfea7c5..bde1cf3ab9662b 100644 --- a/test/js-native-api/.gitignore +++ b/test/js-native-api/.gitignore @@ -5,4 +5,3 @@ Makefile *.mk gyp-mac-tool /*/build -test_cannot_run_js/entry_point.c