diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-04-16 22:58:19 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-04-19 12:09:26 +0800 |
commit | 2c23e31c317025f6064c194f8850a474f4b6bf53 (patch) | |
tree | 8f25f315719122321a912cf1bae35a6f76a51edf /src/node_serdes.cc | |
parent | 7e269f52667104c94dcf65e527b04c2632d701bb (diff) | |
download | node-new-2c23e31c317025f6064c194f8850a474f4b6bf53.tar.gz |
src: throw ERR_INVALID_ARG_TYPE in C++ argument checks
- Moves THROW_AND_RETURN_IF_NOT_BUFFER and
THROW_AND_RETURN_IF_NOT_STRING from node_crypto.cc to
node_errors.h so it can be reused.
- Move THROW_AND_RETURN_UNLESS_BUFFER in util.h to
node_buffer.cc and call THROW_AND_RETURN_IF_NOT_BUFFER
there. The only other reference to THROW_AND_RETURN_UNLESS_BUFFER in
node_i18n.cc can be safely replaced by an assertion since
the argument will be checked in JS land.
- Migrate ERR_INVALID_ARG_TYPE errors in C++. We can move the
checks to JS land if possible later without having to
go semver-major.
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/node_serdes.cc')
-rw-r--r-- | src/node_serdes.cc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/node_serdes.cc b/src/node_serdes.cc index 1995eb1b9b..6ace942c29 100644 --- a/src/node_serdes.cc +++ b/src/node_serdes.cc @@ -1,5 +1,6 @@ #include "node_internals.h" #include "node_buffer.h" +#include "node_errors.h" #include "base_object-inl.h" namespace node { @@ -209,7 +210,8 @@ void SerializerContext::TransferArrayBuffer( if (id.IsNothing()) return; if (!args[1]->IsArrayBuffer()) - return ctx->env()->ThrowTypeError("arrayBuffer must be an ArrayBuffer"); + return node::THROW_ERR_INVALID_ARG_TYPE( + ctx->env(), "arrayBuffer must be an ArrayBuffer"); Local<ArrayBuffer> ab = args[1].As<ArrayBuffer>(); ctx->serializer_.TransferArrayBuffer(id.FromJust(), ab); @@ -255,7 +257,8 @@ void SerializerContext::WriteRawBytes(const FunctionCallbackInfo<Value>& args) { ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder()); if (!args[0]->IsUint8Array()) { - return ctx->env()->ThrowTypeError("source must be a Uint8Array"); + return node::THROW_ERR_INVALID_ARG_TYPE( + ctx->env(), "source must be a Uint8Array"); } ctx->serializer_.WriteRawBytes(Buffer::Data(args[0]), @@ -305,7 +308,8 @@ void DeserializerContext::New(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); if (!args[0]->IsUint8Array()) { - return env->ThrowTypeError("buffer must be a Uint8Array"); + return node::THROW_ERR_INVALID_ARG_TYPE( + env, "buffer must be a Uint8Array"); } new DeserializerContext(env, args.This(), args[0]); @@ -349,8 +353,8 @@ void DeserializerContext::TransferArrayBuffer( return; } - return ctx->env()->ThrowTypeError("arrayBuffer must be an ArrayBuffer or " - "SharedArrayBuffer"); + return node::THROW_ERR_INVALID_ARG_TYPE( + ctx->env(), "arrayBuffer must be an ArrayBuffer or SharedArrayBuffer"); } void DeserializerContext::GetWireFormatVersion( |