Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-01-28 00:05:23 +0300
committerAnna Henningsen <anna@addaleax.net>2019-01-31 02:14:51 +0300
commitde2bdfbc6f13062741529922e4f32d2ab210105e (patch)
treefc79d72c17fbcdb3116505dec54b45477d462ac5
parentbb564a36882102ba8cd46878db7ea886334cac20 (diff)
src: simplify SlicedArguments
Re-use the existing `MaybeStackBuffer` logic for `SlicedArguments`. PR-URL: https://github.com/nodejs/node/pull/25745 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r--src/inspector_js_api.cc10
-rw-r--r--src/node_perf.cc4
-rw-r--r--src/util-inl.h11
-rw-r--r--src/util.h27
4 files changed, 19 insertions, 33 deletions
diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc
index 8802998e9a0..48ebd73817a 100644
--- a/src/inspector_js_api.cc
+++ b/src/inspector_js_api.cc
@@ -139,7 +139,7 @@ void CallAndPauseOnStart(const FunctionCallbackInfo<v8::Value>& args) {
env->inspector_agent()->PauseOnNextJavascriptStatement("Break on start");
v8::MaybeLocal<v8::Value> retval =
args[0].As<v8::Function>()->Call(env->context(), args[1],
- call_args.size(), call_args.data());
+ call_args.length(), call_args.out());
if (!retval.IsEmpty()) {
args.GetReturnValue().Set(retval.ToLocalChecked());
}
@@ -164,8 +164,8 @@ void InspectorConsoleCall(const FunctionCallbackInfo<Value>& info) {
v8::True(isolate)).FromJust());
CHECK(!inspector_method.As<Function>()->Call(context,
info.Holder(),
- call_args.size(),
- call_args.data()).IsEmpty());
+ call_args.length(),
+ call_args.out()).IsEmpty());
}
CHECK(config_object->Delete(context, in_call_key).FromJust());
}
@@ -174,8 +174,8 @@ void InspectorConsoleCall(const FunctionCallbackInfo<Value>& info) {
CHECK(node_method->IsFunction());
node_method.As<Function>()->Call(context,
info.Holder(),
- call_args.size(),
- call_args.data()).FromMaybe(Local<Value>());
+ call_args.length(),
+ call_args.out()).FromMaybe(Local<Value>());
}
static void* GetAsyncTask(int64_t asyncId) {
diff --git a/src/node_perf.cc b/src/node_perf.cc
index 9c0091d2bc9..cefd0ff26db 100644
--- a/src/node_perf.cc
+++ b/src/node_perf.cc
@@ -344,10 +344,10 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
v8::MaybeLocal<Value> ret;
if (is_construct_call) {
- ret = fn->NewInstance(context, call_args.size(), call_args.data())
+ ret = fn->NewInstance(context, call_args.length(), call_args.out())
.FromMaybe(Local<Object>());
} else {
- ret = fn->Call(context, args.This(), call_args.size(), call_args.data());
+ ret = fn->Call(context, args.This(), call_args.length(), call_args.out());
}
uint64_t end = PERFORMANCE_NOW();
diff --git a/src/util-inl.h b/src/util-inl.h
index 6d612f1eb7c..182c50268d3 100644
--- a/src/util-inl.h
+++ b/src/util-inl.h
@@ -455,6 +455,17 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
return v8::Number::New(isolate, static_cast<double>(number));
}
+SlicedArguments::SlicedArguments(
+ const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
+ const size_t length = static_cast<size_t>(args.Length());
+ if (start >= length) return;
+ const size_t size = length - start;
+
+ AllocateSufficientStorage(size);
+ for (size_t i = 0; i < size; ++i)
+ (*this)[i] = args[i + start];
+}
+
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
diff --git a/src/util.h b/src/util.h
index f3a174821ab..fcb543fcacf 100644
--- a/src/util.h
+++ b/src/util.h
@@ -629,37 +629,12 @@ constexpr T RoundUp(T a, T b) {
#define MUST_USE_RESULT
#endif
-class SlicedArguments {
+class SlicedArguments : public MaybeStackBuffer<v8::Local<v8::Value>> {
public:
inline explicit SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start = 0);
- inline size_t size() const { return size_; }
- inline v8::Local<v8::Value>* data() { return data_; }
-
- private:
- size_t size_;
- v8::Local<v8::Value>* data_;
- v8::Local<v8::Value> fixed_[64];
- std::vector<v8::Local<v8::Value>> dynamic_;
};
-SlicedArguments::SlicedArguments(
- const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
- : size_(0), data_(fixed_) {
- const size_t length = static_cast<size_t>(args.Length());
- if (start >= length) return;
- const size_t size = length - start;
-
- if (size > arraysize(fixed_)) {
- dynamic_.resize(size);
- data_ = dynamic_.data();
- }
-
- for (size_t i = 0; i < size; ++i) data_[i] = args[i + start];
-
- size_ = size;
-}
-
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS