Skip to content

Commit

Permalink
process: remove pushValueToArray in GetActiveHandles
Browse files Browse the repository at this point in the history
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: #24264
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
joyeecheung authored and BridgeAR committed Nov 13, 2018
1 parent ba4337d commit ccc3bb7
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/node_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -813,26 +813,14 @@ void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Local<Array> ary = Array::New(env->isolate());
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>> handle_v;
for (auto w : *env->handle_wrap_queue()) {
if (!HandleWrap::HasRef(w))
continue;
argv[idx] = w->GetOwner();
if (++idx >= arraysize(argv)) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
idx = 0;
}
}
if (idx > 0) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
handle_v.push_back(w->GetOwner());
}

args.GetReturnValue().Set(ary);
args.GetReturnValue().Set(
Array::New(env->isolate(), handle_v.data(), handle_v.size()));
}

void DebugPortGetter(Local<Name> property,
Expand Down

0 comments on commit ccc3bb7

Please sign in to comment.