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>
This commit is contained in:
Anna Henningsen committed 2019-01-31 00:14:51 +01:00
1 parent bb564a3688
commit de2bdfbc6f
4 files changed
+19 -33

No files matched your search

+5 -5
View File
@@ -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) {
+2 -2
View File
@@ -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();
+11
View File
@@ -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
+1 -26
View File
@@ -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