Skip to content

Commit

Permalink
src: use SPrintF in ProcessEmitWarning
Browse files Browse the repository at this point in the history
PR-URL: #38758
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>

Backport-PR-URL: #39419
  • Loading branch information
RaisinTen authored and richardlau committed Jul 20, 2021
1 parent bb9a9ad commit e7f266e
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 32 deletions.
1 change: 1 addition & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,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',
Expand Down
2 changes: 1 addition & 1 deletion src/api/hooks.cc
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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"
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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"
Expand Down
2 changes: 1 addition & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "node_crypto_groups.h"
#include "node_errors.h"
#include "node_mutex.h"
#include "node_process.h"
#include "node_process-inl.h"
#include "allocated_buffer-inl.h"
#include "tls_wrap.h" // TLSWrap

Expand Down
2 changes: 1 addition & 1 deletion src/node_dir.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "node_dir.h"
#include "node_file-inl.h"
#include "node_process.h"
#include "node_process-inl.h"
#include "memory_tracker-inl.h"
#include "util.h"

Expand Down
2 changes: 1 addition & 1 deletion src/node_env_var.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "debug_utils-inl.h"
#include "env-inl.h"
#include "node_errors.h"
#include "node_process.h"
#include "node_process-inl.h"

#include <time.h> // tzset(), _tzset()

Expand Down
2 changes: 1 addition & 1 deletion src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "node_errors.h"
#include "node_internals.h"
#include "node_report.h"
#include "node_process.h"
#include "node_process-inl.h"
#include "node_v8_platform-inl.h"
#include "util-inl.h"

Expand Down
2 changes: 1 addition & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "aliased_buffer.h"
#include "memory_tracker-inl.h"
#include "node_buffer.h"
#include "node_process.h"
#include "node_process-inl.h"
#include "node_stat_watcher.h"
#include "util-inl.h"

Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "node_contextify.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "node_process.h"
#include "node_process-inl.h"
#include "util-inl.h"

using node::contextify::ContextifyContext;
Expand Down
2 changes: 1 addition & 1 deletion src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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 <cinttypes>
Expand Down
26 changes: 26 additions & 0 deletions src/node_process-inl.h
Original file line number Diff line number Diff line change
@@ -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 <typename... Args>
inline v8::Maybe<bool> ProcessEmitWarning(Environment* env,
const char* fmt,
Args&&... args) {
std::string warning = SPrintF(fmt, std::forward<Args>(args)...);

return ProcessEmitWarningGeneric(env, warning.c_str());
}

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#endif // SRC_NODE_PROCESS_INL_H_
5 changes: 4 additions & 1 deletion src/node_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ v8::Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
const char* type = nullptr,
const char* code = nullptr);

v8::Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...);
template <typename... Args>
inline v8::Maybe<bool> ProcessEmitWarning(Environment* env,
const char* fmt,
Args&&... args);
v8::Maybe<bool> ProcessEmitExperimentalWarning(Environment* env,
const char* warning);
v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
Expand Down
15 changes: 1 addition & 14 deletions src/node_process_events.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <cstdarg>
#include <set>

#include "env-inl.h"
#include "node_process.h"
#include "node_process-inl.h"
#include "util.h"

namespace node {
Expand Down Expand Up @@ -84,18 +83,6 @@ Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
return Just(true);
}

// Call process.emitWarning(str), fmt is a snprintf() format string
Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...) {
char warning[1024];
va_list ap;

va_start(ap, fmt);
vsnprintf(warning, sizeof(warning), fmt, ap);
va_end(ap);

return ProcessEmitWarningGeneric(env, warning);
}


std::set<std::string> experimental_warnings;

Expand Down
2 changes: 1 addition & 1 deletion src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "node.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_process.h"
#include "node_process-inl.h"
#include "util-inl.h"
#include "uv.h"
#include "v8.h"
Expand Down
2 changes: 1 addition & 1 deletion src/node_process_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "node_internals.h"
#include "node_options-inl.h"
#include "node_metadata.h"
#include "node_process.h"
#include "node_process-inl.h"
#include "node_revert.h"
#include "util-inl.h"

Expand Down
2 changes: 1 addition & 1 deletion src/node_task_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "node.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_process.h"
#include "node_process-inl.h"
#include "util-inl.h"
#include "v8.h"

Expand Down
2 changes: 1 addition & 1 deletion src/signal_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/uv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "uv.h"
#include "env-inl.h"
#include "node.h"
#include "node_process.h"
#include "node_process-inl.h"

namespace node {

Expand Down

0 comments on commit e7f266e

Please sign in to comment.