diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-04-16 22:25:11 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-04-19 12:09:24 +0800 |
commit | 7e269f52667104c94dcf65e527b04c2632d701bb (patch) | |
tree | 666f38bae7f287432d4caa2bdd3d8a2c2c4933c2 /src | |
parent | 0f16528247b2b1dee1e5825d3fee17f0c00bd5e6 (diff) | |
download | android-node-v8-7e269f52667104c94dcf65e527b04c2632d701bb.tar.gz android-node-v8-7e269f52667104c94dcf65e527b04c2632d701bb.tar.bz2 android-node-v8-7e269f52667104c94dcf65e527b04c2632d701bb.zip |
src: migrate ERR_INDEX_OUT_OF_RANGE in C++
This patch migrates the "Index out of range" errors in C++
to errors with the code `ERR_INDEX_OUT_OF_RANGE` which have
equivalents in JavaScript.
PR-URL: https://github.com/nodejs/node/pull/20121
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_buffer.cc | 9 | ||||
-rw-r--r-- | src/node_errors.h | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 15e6c7a0c4..2e96869717 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -21,6 +21,7 @@ #include "node.h" #include "node_buffer.h" +#include "node_errors.h" #include "env-inl.h" #include "string_bytes.h" @@ -38,7 +39,7 @@ #define THROW_AND_RETURN_IF_OOB(r) \ do { \ - if (!(r)) return env->ThrowRangeError("Index out of range"); \ + if (!(r)) return node::THROW_ERR_INDEX_OUT_OF_RANGE(env); \ } while (0) #define SLICE_START_END(start_arg, end_arg, end_max) \ @@ -544,7 +545,7 @@ void Copy(const FunctionCallbackInfo<Value> &args) { return args.GetReturnValue().Set(0); if (source_start > ts_obj_length) - return env->ThrowRangeError("Index out of range"); + return node::THROW_ERR_INDEX_OUT_OF_RANGE(env); if (source_end - source_start > target_length - target_start) source_end = source_start + target_length - target_start; @@ -728,9 +729,9 @@ 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 env->ThrowRangeError("Index out of range"); + return node::THROW_ERR_INDEX_OUT_OF_RANGE(env); if (target_start > target_length) - return env->ThrowRangeError("Index out of range"); + return node::THROW_ERR_INDEX_OUT_OF_RANGE(env); CHECK_LE(source_start, source_end); CHECK_LE(target_start, target_end); diff --git a/src/node_errors.h b/src/node_errors.h index 4153553f5b..584a62ece1 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -17,8 +17,9 @@ namespace node { // a `Local<Value>` containing the TypeError with proper code and message #define ERRORS_WITH_CODE(V) \ + V(ERR_INDEX_OUT_OF_RANGE, RangeError) \ V(ERR_MEMORY_ALLOCATION_FAILED, Error) \ - V(ERR_STRING_TOO_LONG, Error) \ + V(ERR_STRING_TOO_LONG, Error) \ V(ERR_BUFFER_TOO_LARGE, Error) #define V(code, type) \ @@ -42,6 +43,7 @@ namespace node { // Errors with predefined static messages #define PREDEFINED_ERROR_MESSAGES(V) \ + V(ERR_INDEX_OUT_OF_RANGE, "Index out of range") \ V(ERR_MEMORY_ALLOCATION_FAILED, "Failed to allocate memory") #define V(code, message) \ |