Skip to content
Permalink
Browse files

src: inline `SLICE_START_END()` in node_buffer.cc

This macro is only used once, so it doesn’t need to be a macro.

PR-URL: #29357
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information...
addaleax authored and BridgeAR committed Aug 28, 2019
1 parent 4a7c4b7 commit 2666e006e180ea16dda292b9b719bd4ed02bc261
Showing with 7 additions and 10 deletions.
  1. +7 −10 src/node_buffer.cc
@@ -44,15 +44,6 @@
return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \
} while (0) \

#define SLICE_START_END(env, start_arg, end_arg, end_max) \
size_t start = 0; \
size_t end = 0; \
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, start_arg, 0, &start)); \
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, end_arg, end_max, &end)); \
if (end < start) end = start; \
THROW_AND_RETURN_IF_OOB(Just(end <= end_max)); \
size_t length = end - start;

namespace node {
namespace Buffer {

@@ -467,7 +458,13 @@ void StringSlice(const FunctionCallbackInfo<Value>& args) {
if (buffer.length() == 0)
return args.GetReturnValue().SetEmptyString();

SLICE_START_END(env, args[0], args[1], buffer.length())
size_t start = 0;
size_t end = 0;
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[0], 0, &start));
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[1], buffer.length(), &end));
if (end < start) end = start;
THROW_AND_RETURN_IF_OOB(Just(end <= buffer.length()));
size_t length = end - start;

Local<Value> error;
MaybeLocal<Value> ret =

0 comments on commit 2666e00

Please sign in to comment.
You can’t perform that action at this time.