Skip to content

Commit 9363b05

Browse files
joyeecheungRafaelGSS
authored andcommitted
src: do not format single string argument for THROW_ERR_*
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]>
1 parent c5bff73 commit 9363b05

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/node_errors.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,21 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
113113
V(ERR_WORKER_INIT_FAILED, Error) \
114114
V(ERR_PROTO_ACCESS, Error)
115115

116+
// If the macros are used as ERR_*(isolate, message) or
117+
// THROW_ERR_*(isolate, message) with a single string argument, do run
118+
// formatter on the message, and allow the caller to pass in a message
119+
// directly with characters that would otherwise need escaping if used
120+
// as format string unconditionally.
116121
#define V(code, type) \
117122
template <typename... Args> \
118123
inline v8::Local<v8::Object> code( \
119124
v8::Isolate* isolate, const char* format, Args&&... args) { \
120-
std::string message = SPrintF(format, std::forward<Args>(args)...); \
125+
std::string message; \
126+
if (sizeof...(Args) == 0) { \
127+
message = format; \
128+
} else { \
129+
message = SPrintF(format, std::forward<Args>(args)...); \
130+
} \
121131
v8::Local<v8::String> js_code = FIXED_ONE_BYTE_STRING(isolate, #code); \
122132
v8::Local<v8::String> js_msg = \
123133
v8::String::NewFromUtf8(isolate, \

0 commit comments

Comments
 (0)