Skip to content

Commit dcaf723

Browse files
addaleaxtargos
authored andcommitted
src: minor refactor to node_errors.h
Add overloads of the error generation/throwing methods that take an `Isolate*` argument, since the created objects don’t depend on the `Environment*` in question. Also, remove `THROW_ERR_OUT_OF_RANGE_WITH_TEXT`, which did the same thing as `THROW_ERR_OUT_OF_RANGE` in a more convoluted way. PR-URL: #23879 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
1 parent 7bbc072 commit dcaf723

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/node_buffer.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
#define THROW_AND_RETURN_IF_OOB(r) \
4242
do { \
4343
if (!(r)) \
44-
return node::THROW_ERR_OUT_OF_RANGE_WITH_TEXT(env, \
45-
"Index out of range"); \
44+
return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \
4645
} while (0) \
4746

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

496495
if (source_start > ts_obj_length)
497-
return node::THROW_ERR_OUT_OF_RANGE_WITH_TEXT(
496+
return THROW_ERR_OUT_OF_RANGE(
498497
env, "The value of \"sourceStart\" is out of range.");
499498

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

687686
if (source_start > ts_obj_length)
688-
return node::THROW_ERR_OUT_OF_RANGE_WITH_TEXT(
687+
return THROW_ERR_OUT_OF_RANGE(
689688
env, "The value of \"sourceStart\" is out of range.");
690689
if (target_start > target_length)
691-
return node::THROW_ERR_OUT_OF_RANGE_WITH_TEXT(
690+
return THROW_ERR_OUT_OF_RANGE(
692691
env, "The value of \"targetStart\" is out of range.");
693692

694693
CHECK_LE(source_start, source_end);

src/node_errors.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ namespace node {
5252
js_code).FromJust(); \
5353
return e; \
5454
} \
55+
inline void THROW_ ## code(v8::Isolate* isolate, const char* message) { \
56+
isolate->ThrowException(code(isolate, message)); \
57+
} \
5558
inline void THROW_ ## code(Environment* env, const char* message) { \
56-
env->isolate()->ThrowException(code(env->isolate(), message)); \
59+
THROW_ ## code(env->isolate(), message); \
5760
}
5861
ERRORS_WITH_CODE(V)
5962
#undef V
@@ -80,8 +83,11 @@ namespace node {
8083
inline v8::Local<v8::Value> code(v8::Isolate* isolate) { \
8184
return code(isolate, message); \
8285
} \
86+
inline void THROW_ ## code(v8::Isolate* isolate) { \
87+
isolate->ThrowException(code(isolate, message)); \
88+
} \
8389
inline void THROW_ ## code(Environment* env) { \
84-
env->isolate()->ThrowException(code(env->isolate(), message)); \
90+
THROW_ ## code(env->isolate()); \
8591
}
8692
PREDEFINED_ERROR_MESSAGES(V)
8793
#undef V
@@ -95,13 +101,6 @@ inline void THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(Environment* env,
95101
THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(env, message.str().c_str());
96102
}
97103

98-
inline void THROW_ERR_OUT_OF_RANGE_WITH_TEXT(Environment* env,
99-
const char* messageText) {
100-
std::ostringstream message;
101-
message << messageText;
102-
THROW_ERR_OUT_OF_RANGE(env, message.str().c_str());
103-
}
104-
105104
inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) {
106105
char message[128];
107106
snprintf(message, sizeof(message),

0 commit comments

Comments
 (0)