process: remove pushValueToArray in GetActiveRequests

Instead of calling into JS from C++ to push values into an array,
use the new Array::New API that takes a pointer and a length
directly.

PR-URL: https://github.com/nodejs/node/pull/24264
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
Joyee Cheung 2018-11-09 11:38:28 +08:00
parent 08bfd5625f
commit 235afb4c6a
No known key found for this signature in database
GPG Key ID: 92B78A53C8303B8D

View File

@ -797,29 +797,17 @@ void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Local<Array> ary = Array::New(args.GetIsolate());
Local<Context> ctx = env->context();
Local<Function> fn = env->push_values_to_array_function();
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
size_t idx = 0;
std::vector<Local<Value>> request_v;
for (auto w : *env->req_wrap_queue()) {
if (w->persistent().IsEmpty())
continue;
argv[idx] = w->GetOwner();
if (++idx >= arraysize(argv)) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
idx = 0;
}
request_v.push_back(w->GetOwner());
}
if (idx > 0) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
}
args.GetReturnValue().Set(ary);
args.GetReturnValue().Set(
Array::New(env->isolate(), request_v.data(), request_v.size()));
}
// Non-static, friend of HandleWrap. Could have been a HandleWrap method but
// implemented here for consistency with GetActiveRequests().
void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {