From 1f03ad1df05973511f9409b7560c945974ef3469 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 25 Oct 2018 19:35:17 +0200 Subject: [PATCH 1/2] src: minor refactor to node_errors.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/node_buffer.cc | 9 ++++----- src/node_errors.h | 17 ++++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 19841336e99a26..e3fb918f181a48 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -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"); \ } while (0) \ #define SLICE_START_END(start_arg, end_arg, end_max) \ @@ -494,7 +493,7 @@ void Copy(const FunctionCallbackInfo &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) @@ -685,10 +684,10 @@ void CompareOffset(const FunctionCallbackInfo &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); diff --git a/src/node_errors.h b/src/node_errors.h index 233a0f7532c717..a958eccf8af4b9 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -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 @@ -80,8 +83,11 @@ namespace node { inline v8::Local 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 @@ -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 ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) { char message[128]; snprintf(message, sizeof(message), From dca427c2a44fbc3a82f89804c007eb691912242d Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 25 Oct 2018 20:01:57 +0200 Subject: [PATCH 2/2] fixup! src: minor refactor to node_errors.h --- src/node_buffer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index e3fb918f181a48..d4f7c751634b4d 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -41,7 +41,7 @@ #define THROW_AND_RETURN_IF_OOB(r) \ do { \ if (!(r)) \ - return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \ + return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \ } while (0) \ #define SLICE_START_END(start_arg, end_arg, end_max) \