From 228990b73c59bce3e612223be3485aa510eadff9 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Fri, 21 May 2021 21:18:44 +0530 Subject: [PATCH 1/3] src: use SPrintF in ProcessEmitWarning --- src/node_process.h | 5 ++++- src/node_process_events.cc | 15 +++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/node_process.h b/src/node_process.h index 2e87385348d936..f1f0bc72185a85 100644 --- a/src/node_process.h +++ b/src/node_process.h @@ -25,7 +25,10 @@ v8::Maybe ProcessEmitWarningGeneric(Environment* env, const char* type = nullptr, const char* code = nullptr); -v8::Maybe ProcessEmitWarning(Environment* env, const char* fmt, ...); +template +v8::Maybe ProcessEmitWarning(Environment* env, + const char* fmt, + Args&&... args); v8::Maybe ProcessEmitExperimentalWarning(Environment* env, const char* warning); v8::Maybe ProcessEmitDeprecationWarning(Environment* env, diff --git a/src/node_process_events.cc b/src/node_process_events.cc index 0c149b26e334b0..edaf1909b92664 100644 --- a/src/node_process_events.cc +++ b/src/node_process_events.cc @@ -2,6 +2,7 @@ #include #include "env-inl.h" +#include "debug_utils-inl.h" #include "node_process.h" #include "util.h" @@ -85,15 +86,13 @@ Maybe ProcessEmitWarningGeneric(Environment* env, } // Call process.emitWarning(str), fmt is a snprintf() format string -Maybe ProcessEmitWarning(Environment* env, const char* fmt, ...) { - char warning[1024]; - va_list ap; +template +v8::Maybe ProcessEmitWarning(Environment* env, + const char* fmt, + Args&&... args) { + std::string warning = SPrintF(fmt, std::forward(args)...); - va_start(ap, fmt); - vsnprintf(warning, sizeof(warning), fmt, ap); - va_end(ap); - - return ProcessEmitWarningGeneric(env, warning); + return ProcessEmitWarningGeneric(env, warning.c_str()); } From 9aa33363f4e034f172030d36bd864b136e3293de Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sat, 22 May 2021 19:13:03 +0530 Subject: [PATCH 2/3] fixup! src: use SPrintF in ProcessEmitWarning --- src/node_process.h | 13 ++++++++++--- src/node_process_events.cc | 12 ------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/node_process.h b/src/node_process.h index f1f0bc72185a85..89dbe46fcf5a27 100644 --- a/src/node_process.h +++ b/src/node_process.h @@ -4,6 +4,7 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "v8.h" +#include "debug_utils-inl.h" namespace node { @@ -25,10 +26,16 @@ v8::Maybe ProcessEmitWarningGeneric(Environment* env, const char* type = nullptr, const char* code = nullptr); +// Call process.emitWarning(str), fmt is a snprintf() format string template -v8::Maybe ProcessEmitWarning(Environment* env, - const char* fmt, - Args&&... args); +inline v8::Maybe ProcessEmitWarning(Environment* env, + const char* fmt, + Args&&... args) { + std::string warning = SPrintF(fmt, std::forward(args)...); + + return ProcessEmitWarningGeneric(env, warning.c_str()); +} + v8::Maybe ProcessEmitExperimentalWarning(Environment* env, const char* warning); v8::Maybe ProcessEmitDeprecationWarning(Environment* env, diff --git a/src/node_process_events.cc b/src/node_process_events.cc index edaf1909b92664..5191ee0786d1aa 100644 --- a/src/node_process_events.cc +++ b/src/node_process_events.cc @@ -1,8 +1,6 @@ -#include #include #include "env-inl.h" -#include "debug_utils-inl.h" #include "node_process.h" #include "util.h" @@ -85,16 +83,6 @@ Maybe ProcessEmitWarningGeneric(Environment* env, return Just(true); } -// Call process.emitWarning(str), fmt is a snprintf() format string -template -v8::Maybe ProcessEmitWarning(Environment* env, - const char* fmt, - Args&&... args) { - std::string warning = SPrintF(fmt, std::forward(args)...); - - return ProcessEmitWarningGeneric(env, warning.c_str()); -} - std::set experimental_warnings; From 0c84eb71d122f04ae1ab738057a821aa68d5bac3 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sat, 22 May 2021 19:56:45 +0530 Subject: [PATCH 3/3] move ProcessEmitWarning to node_process-inl.h --- node.gyp | 1 + src/api/hooks.cc | 2 +- src/crypto/crypto_cipher.cc | 2 +- src/env.cc | 2 +- src/inspector_agent.cc | 2 +- src/module_wrap.cc | 2 +- src/node.cc | 2 +- src/node_dir.cc | 2 +- src/node_env_var.cc | 2 +- src/node_errors.cc | 2 +- src/node_file.cc | 2 +- src/node_messaging.cc | 2 +- src/node_perf.cc | 2 +- src/node_process-inl.h | 26 ++++++++++++++++++++++++++ src/node_process.h | 9 +-------- src/node_process_events.cc | 2 +- src/node_process_methods.cc | 2 +- src/node_process_object.cc | 2 +- src/node_task_queue.cc | 2 +- src/signal_wrap.cc | 2 +- src/uv.cc | 2 +- 21 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 src/node_process-inl.h diff --git a/node.gyp b/node.gyp index 642a9767fb64d8..30327b38a59df5 100644 --- a/node.gyp +++ b/node.gyp @@ -749,6 +749,7 @@ 'src/node_perf_common.h', 'src/node_platform.h', 'src/node_process.h', + 'src/node_process-inl.h', 'src/node_report.h', 'src/node_revert.h', 'src/node_root_certs.h', diff --git a/src/api/hooks.cc b/src/api/hooks.cc index cb46c5c1b87643..c19d8c5b9106f4 100644 --- a/src/api/hooks.cc +++ b/src/api/hooks.cc @@ -1,6 +1,6 @@ #include "env-inl.h" #include "node_internals.h" -#include "node_process.h" +#include "node_process-inl.h" #include "async_wrap.h" namespace node { diff --git a/src/crypto/crypto_cipher.cc b/src/crypto/crypto_cipher.cc index 5ce466582823ae..4629143d47e492 100644 --- a/src/crypto/crypto_cipher.cc +++ b/src/crypto/crypto_cipher.cc @@ -6,7 +6,7 @@ #include "memory_tracker-inl.h" #include "node_buffer.h" #include "node_internals.h" -#include "node_process.h" +#include "node_process-inl.h" #include "v8.h" namespace node { diff --git a/src/env.cc b/src/env.cc index 28a1c2fd3c3676..4ee4b675d87953 100644 --- a/src/env.cc +++ b/src/env.cc @@ -10,7 +10,7 @@ #include "node_errors.h" #include "node_internals.h" #include "node_options-inl.h" -#include "node_process.h" +#include "node_process-inl.h" #include "node_v8_platform-inl.h" #include "node_worker.h" #include "req_wrap-inl.h" diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 4b30c177bea55c..a3c901dca2eafc 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -12,7 +12,7 @@ #include "node_errors.h" #include "node_internals.h" #include "node_options-inl.h" -#include "node_process.h" +#include "node_process-inl.h" #include "node_url.h" #include "util-inl.h" #include "timer_wrap.h" diff --git a/src/module_wrap.cc b/src/module_wrap.cc index ed48c0bc5f45a9..f45ee7627b0a9b 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -5,7 +5,7 @@ #include "node_contextify.h" #include "node_errors.h" #include "node_internals.h" -#include "node_process.h" +#include "node_process-inl.h" #include "node_url.h" #include "node_watchdog.h" #include "util-inl.h" diff --git a/src/node.cc b/src/node.cc index bf041fb682a2c2..3b6d58ea7308ea 100644 --- a/src/node.cc +++ b/src/node.cc @@ -35,7 +35,7 @@ #include "node_native_module_env.h" #include "node_options-inl.h" #include "node_perf.h" -#include "node_process.h" +#include "node_process-inl.h" #include "node_report.h" #include "node_revert.h" #include "node_v8_platform-inl.h" diff --git a/src/node_dir.cc b/src/node_dir.cc index b103c08262a5e8..c530da0cc3be4b 100644 --- a/src/node_dir.cc +++ b/src/node_dir.cc @@ -1,7 +1,7 @@ #include "node_dir.h" #include "node_external_reference.h" #include "node_file-inl.h" -#include "node_process.h" +#include "node_process-inl.h" #include "memory_tracker-inl.h" #include "util.h" diff --git a/src/node_env_var.cc b/src/node_env_var.cc index b13f7fcd16fd50..27c833d498ec77 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -3,7 +3,7 @@ #include "node_errors.h" #include "node_external_reference.h" #include "node_i18n.h" -#include "node_process.h" +#include "node_process-inl.h" #include // tzset(), _tzset() diff --git a/src/node_errors.cc b/src/node_errors.cc index 47b13f6149545b..3aee2533a8c078 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -5,7 +5,7 @@ #include "node_errors.h" #include "node_external_reference.h" #include "node_internals.h" -#include "node_process.h" +#include "node_process-inl.h" #include "node_report.h" #include "node_v8_platform-inl.h" #include "util-inl.h" diff --git a/src/node_file.cc b/src/node_file.cc index d3bcb8fbd804c7..3d185983ae452c 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -24,7 +24,7 @@ #include "memory_tracker-inl.h" #include "node_buffer.h" #include "node_external_reference.h" -#include "node_process.h" +#include "node_process-inl.h" #include "node_stat_watcher.h" #include "util-inl.h" diff --git a/src/node_messaging.cc b/src/node_messaging.cc index ac4abc3af01568..7dd18979530b44 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -7,7 +7,7 @@ #include "node_contextify.h" #include "node_errors.h" #include "node_external_reference.h" -#include "node_process.h" +#include "node_process-inl.h" #include "util-inl.h" using node::contextify::ContextifyContext; diff --git a/src/node_perf.cc b/src/node_perf.cc index c1a0b2cf3a14d7..8c5778ecb10bb0 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -5,7 +5,7 @@ #include "node_internals.h" #include "node_perf.h" #include "node_buffer.h" -#include "node_process.h" +#include "node_process-inl.h" #include "util-inl.h" #include diff --git a/src/node_process-inl.h b/src/node_process-inl.h new file mode 100644 index 00000000000000..21a448cfdb2a75 --- /dev/null +++ b/src/node_process-inl.h @@ -0,0 +1,26 @@ +#ifndef SRC_NODE_PROCESS_INL_H_ +#define SRC_NODE_PROCESS_INL_H_ + +#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#include "node_process.h" +#include "v8.h" +#include "debug_utils-inl.h" + +namespace node { + +// Call process.emitWarning(str), fmt is a snprintf() format string +template +inline v8::Maybe ProcessEmitWarning(Environment* env, + const char* fmt, + Args&&... args) { + std::string warning = SPrintF(fmt, std::forward(args)...); + + return ProcessEmitWarningGeneric(env, warning.c_str()); +} + +} // namespace node + +#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#endif // SRC_NODE_PROCESS_INL_H_ diff --git a/src/node_process.h b/src/node_process.h index 89dbe46fcf5a27..14c8f659168975 100644 --- a/src/node_process.h +++ b/src/node_process.h @@ -4,7 +4,6 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "v8.h" -#include "debug_utils-inl.h" namespace node { @@ -26,16 +25,10 @@ v8::Maybe ProcessEmitWarningGeneric(Environment* env, const char* type = nullptr, const char* code = nullptr); -// Call process.emitWarning(str), fmt is a snprintf() format string template inline v8::Maybe ProcessEmitWarning(Environment* env, const char* fmt, - Args&&... args) { - std::string warning = SPrintF(fmt, std::forward(args)...); - - return ProcessEmitWarningGeneric(env, warning.c_str()); -} - + Args&&... args); v8::Maybe ProcessEmitExperimentalWarning(Environment* env, const char* warning); v8::Maybe ProcessEmitDeprecationWarning(Environment* env, diff --git a/src/node_process_events.cc b/src/node_process_events.cc index 5191ee0786d1aa..34f0251cabc02b 100644 --- a/src/node_process_events.cc +++ b/src/node_process_events.cc @@ -1,7 +1,7 @@ #include #include "env-inl.h" -#include "node_process.h" +#include "node_process-inl.h" #include "util.h" namespace node { diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 5030ab872f4f16..3bb56458d0eb33 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -6,7 +6,7 @@ #include "node_errors.h" #include "node_external_reference.h" #include "node_internals.h" -#include "node_process.h" +#include "node_process-inl.h" #include "util-inl.h" #include "uv.h" #include "v8-fast-api-calls.h" diff --git a/src/node_process_object.cc b/src/node_process_object.cc index 3d573d534601e0..587b4ecb936835 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -4,7 +4,7 @@ #include "node_internals.h" #include "node_metadata.h" #include "node_options-inl.h" -#include "node_process.h" +#include "node_process-inl.h" #include "node_revert.h" #include "util-inl.h" diff --git a/src/node_task_queue.cc b/src/node_task_queue.cc index 004eb6a6529f79..9bbdb3180217b3 100644 --- a/src/node_task_queue.cc +++ b/src/node_task_queue.cc @@ -4,7 +4,7 @@ #include "node_errors.h" #include "node_external_reference.h" #include "node_internals.h" -#include "node_process.h" +#include "node_process-inl.h" #include "util-inl.h" #include "v8.h" diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index cdf063c035a5d3..e8a1500d2e9961 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -22,7 +22,7 @@ #include "async_wrap-inl.h" #include "env-inl.h" #include "handle_wrap.h" -#include "node_process.h" +#include "node_process-inl.h" #include "util-inl.h" #include "v8.h" diff --git a/src/uv.cc b/src/uv.cc index 0e6672c47269b3..2b0c424587e420 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -23,7 +23,7 @@ #include "env-inl.h" #include "node.h" #include "node_external_reference.h" -#include "node_process.h" +#include "node_process-inl.h" namespace node {