Skip to content

Commit 4938188

Browse files
targosRafaelGSS
authored andcommitted
src: return v8::Object from error constructors
It's more specific than `v8::Value`. PR-URL: #54541 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
1 parent 4578e94 commit 4938188

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/node_errors.h

+12-14
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
113113

114114
#define V(code, type) \
115115
template <typename... Args> \
116-
inline v8::Local<v8::Value> code( \
116+
inline v8::Local<v8::Object> code( \
117117
v8::Isolate* isolate, const char* format, Args&&... args) { \
118118
std::string message = SPrintF(format, std::forward<Args>(args)...); \
119119
v8::Local<v8::String> js_code = OneByteString(isolate, #code); \
@@ -209,17 +209,15 @@ ERRORS_WITH_CODE(V)
209209
"Accessing Object.prototype.__proto__ has been " \
210210
"disallowed with --disable-proto=throw")
211211

212-
#define V(code, message) \
213-
inline v8::Local<v8::Value> code(v8::Isolate* isolate) { \
214-
return code(isolate, message); \
215-
} \
216-
inline void THROW_ ## code(v8::Isolate* isolate) { \
217-
isolate->ThrowException(code(isolate, message)); \
218-
} \
219-
inline void THROW_ ## code(Environment* env) { \
220-
THROW_ ## code(env->isolate()); \
221-
}
222-
PREDEFINED_ERROR_MESSAGES(V)
212+
#define V(code, message) \
213+
inline v8::Local<v8::Object> code(v8::Isolate* isolate) { \
214+
return code(isolate, message); \
215+
} \
216+
inline void THROW_##code(v8::Isolate* isolate) { \
217+
isolate->ThrowException(code(isolate, message)); \
218+
} \
219+
inline void THROW_##code(Environment* env) { THROW_##code(env->isolate()); }
220+
PREDEFINED_ERROR_MESSAGES(V)
223221
#undef V
224222

225223
// Errors with predefined non-static messages
@@ -231,7 +229,7 @@ inline void THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(Environment* env,
231229
THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(env, message.str().c_str());
232230
}
233231

234-
inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
232+
inline v8::Local<v8::Object> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
235233
char message[128];
236234
snprintf(message,
237235
sizeof(message),
@@ -240,7 +238,7 @@ inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
240238
return ERR_BUFFER_TOO_LARGE(isolate, message);
241239
}
242240

243-
inline v8::Local<v8::Value> ERR_STRING_TOO_LONG(v8::Isolate* isolate) {
241+
inline v8::Local<v8::Object> ERR_STRING_TOO_LONG(v8::Isolate* isolate) {
244242
char message[128];
245243
snprintf(message, sizeof(message),
246244
"Cannot create a string longer than 0x%x characters",

0 commit comments

Comments
 (0)