Skip to content

Commit 90ff714

Browse files
committedOct 2, 2024
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 671c3ac commit 90ff714

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
@@ -106,7 +106,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
106106

107107
#define V(code, type) \
108108
template <typename... Args> \
109-
inline v8::Local<v8::Value> code( \
109+
inline v8::Local<v8::Object> code( \
110110
v8::Isolate* isolate, const char* format, Args&&... args) { \
111111
std::string message = SPrintF(format, std::forward<Args>(args)...); \
112112
v8::Local<v8::String> js_code = OneByteString(isolate, #code); \
@@ -206,17 +206,15 @@ ERRORS_WITH_CODE(V)
206206
"Accessing Object.prototype.__proto__ has been " \
207207
"disallowed with --disable-proto=throw")
208208

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

222220
// Errors with predefined non-static messages
@@ -228,15 +226,15 @@ inline void THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(Environment* env,
228226
THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(env, message.str().c_str());
229227
}
230228

231-
inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
229+
inline v8::Local<v8::Object> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
232230
char message[128];
233231
snprintf(message, sizeof(message),
234232
"Cannot create a Buffer larger than 0x%zx bytes",
235233
v8::TypedArray::kMaxLength);
236234
return ERR_BUFFER_TOO_LARGE(isolate, message);
237235
}
238236

239-
inline v8::Local<v8::Value> ERR_STRING_TOO_LONG(v8::Isolate* isolate) {
237+
inline v8::Local<v8::Object> ERR_STRING_TOO_LONG(v8::Isolate* isolate) {
240238
char message[128];
241239
snprintf(message, sizeof(message),
242240
"Cannot create a string longer than 0x%x characters",

0 commit comments

Comments
 (0)
Please sign in to comment.