Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: minor refactor to node_errors.h #23879

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
#define THROW_AND_RETURN_IF_OOB(r) \
do { \
if (!(r)) \
return node::THROW_ERR_OUT_OF_RANGE_WITH_TEXT(env, \
"Index out of range"); \
return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space after the comma?

} while (0) \

#define SLICE_START_END(start_arg, end_arg, end_max) \
Expand Down Expand Up @@ -494,7 +493,7 @@ void Copy(const FunctionCallbackInfo<Value> &args) {
return args.GetReturnValue().Set(0);

if (source_start > ts_obj_length)
return node::THROW_ERR_OUT_OF_RANGE_WITH_TEXT(
return THROW_ERR_OUT_OF_RANGE(
env, "The value of \"sourceStart\" is out of range.");

if (source_end - source_start > target_length - target_start)
Expand Down Expand Up @@ -685,10 +684,10 @@ void CompareOffset(const FunctionCallbackInfo<Value> &args) {
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[5], ts_obj_length, &source_end));

if (source_start > ts_obj_length)
return node::THROW_ERR_OUT_OF_RANGE_WITH_TEXT(
return THROW_ERR_OUT_OF_RANGE(
env, "The value of \"sourceStart\" is out of range.");
if (target_start > target_length)
return node::THROW_ERR_OUT_OF_RANGE_WITH_TEXT(
return THROW_ERR_OUT_OF_RANGE(
env, "The value of \"targetStart\" is out of range.");

CHECK_LE(source_start, source_end);
Expand Down
17 changes: 8 additions & 9 deletions src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ namespace node {
js_code).FromJust(); \
return e; \
} \
inline void THROW_ ## code(v8::Isolate* isolate, const char* message) { \
isolate->ThrowException(code(isolate, message)); \
} \
inline void THROW_ ## code(Environment* env, const char* message) { \
env->isolate()->ThrowException(code(env->isolate(), message)); \
THROW_ ## code(env->isolate(), message); \
}
ERRORS_WITH_CODE(V)
#undef V
Expand All @@ -80,8 +83,11 @@ namespace node {
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) { \
env->isolate()->ThrowException(code(env->isolate(), message)); \
THROW_ ## code(env->isolate()); \
}
PREDEFINED_ERROR_MESSAGES(V)
#undef V
Expand All @@ -95,13 +101,6 @@ inline void THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(Environment* env,
THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(env, message.str().c_str());
}

inline void THROW_ERR_OUT_OF_RANGE_WITH_TEXT(Environment* env,
const char* messageText) {
std::ostringstream message;
message << messageText;
THROW_ERR_OUT_OF_RANGE(env, message.str().c_str());
}

inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
char message[128];
snprintf(message, sizeof(message),
Expand Down