Skip to content

Commit

Permalink
src: return v8::Object from error constructors
Browse files Browse the repository at this point in the history
It's more specific than `v8::Value`.

PR-URL: #54541
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
  • Loading branch information
targos committed Oct 2, 2024
1 parent 671c3ac commit 90ff714
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);

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

#define V(code, message) \
inline v8::Local<v8::Value> code(v8::Isolate* isolate) { \
return code(isolate, message); \
} \
inline void THROW_ ## code(v8::Isolate* isolate) { \
isolate->ThrowException(code(isolate, message)); \
} \
inline void THROW_ ## code(Environment* env) { \
THROW_ ## code(env->isolate()); \
}
PREDEFINED_ERROR_MESSAGES(V)
#define V(code, message) \
inline v8::Local<v8::Object> code(v8::Isolate* isolate) { \
return code(isolate, message); \
} \
inline void THROW_##code(v8::Isolate* isolate) { \
isolate->ThrowException(code(isolate, message)); \
} \
inline void THROW_##code(Environment* env) { THROW_##code(env->isolate()); }
PREDEFINED_ERROR_MESSAGES(V)
#undef V

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

inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
inline v8::Local<v8::Object> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
char message[128];
snprintf(message, sizeof(message),
"Cannot create a Buffer larger than 0x%zx bytes",
v8::TypedArray::kMaxLength);
return ERR_BUFFER_TOO_LARGE(isolate, message);
}

inline v8::Local<v8::Value> ERR_STRING_TOO_LONG(v8::Isolate* isolate) {
inline v8::Local<v8::Object> ERR_STRING_TOO_LONG(v8::Isolate* isolate) {
char message[128];
snprintf(message, sizeof(message),
"Cannot create a string longer than 0x%x characters",
Expand Down

0 comments on commit 90ff714

Please sign in to comment.