Skip to content

Commit

Permalink
src: do not format single string argument for THROW_ERR_*
Browse files Browse the repository at this point in the history
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.

PR-URL: #57126
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
joyeecheung authored and targos committed Feb 25, 2025
1 parent d62299b commit 90a4de0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,21 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
V(ERR_WORKER_INIT_FAILED, Error) \
V(ERR_PROTO_ACCESS, Error)

// If the macros are used as ERR_*(isolate, message) or
// THROW_ERR_*(isolate, message) with a single string argument, do run
// formatter on the message, and allow the caller to pass in a message
// directly with characters that would otherwise need escaping if used
// as format string unconditionally.
#define V(code, type) \
template <typename... Args> \
inline v8::Local<v8::Object> code( \
v8::Isolate* isolate, const char* format, Args&&... args) { \
std::string message = SPrintF(format, std::forward<Args>(args)...); \
std::string message; \
if (sizeof...(Args) == 0) { \
message = format; \
} else { \
message = SPrintF(format, std::forward<Args>(args)...); \
} \
v8::Local<v8::String> js_code = FIXED_ONE_BYTE_STRING(isolate, #code); \
v8::Local<v8::String> js_msg = \
v8::String::NewFromUtf8(isolate, \
Expand Down

0 comments on commit 90a4de0

Please sign in to comment.