Skip to content

Commit

Permalink
http2: remove pushValueToArray in Http2Session::HandleOriginFrame
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 <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
  • Loading branch information
joyeecheung authored and BridgeAR committed Nov 13, 2018
1 parent 7ffbb1f commit 62fefd8
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1424,25 +1424,17 @@ void Http2Session::HandleOriginFrame(const nghttp2_frame* frame) {
nghttp2_extension ext = frame->ext;
nghttp2_ext_origin* origin = static_cast<nghttp2_ext_origin*>(ext.payload);

Local<Value> holder = Array::New(isolate);
Local<Function> fn = env()->push_values_to_array_function();
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
size_t nov = origin->nov;
std::vector<Local<Value>> origin_v(nov);

size_t n = 0;
while (n < origin->nov) {
size_t j = 0;
while (n < origin->nov && j < arraysize(argv)) {
auto entry = origin->ov[n++];
argv[j++] =
String::NewFromOneByte(isolate,
entry.origin,
v8::NewStringType::kNormal,
entry.origin_len).ToLocalChecked();
}
if (j > 0)
fn->Call(context, holder, j, argv).ToLocalChecked();
for (size_t i = 0; i < nov; ++i) {
const nghttp2_origin_entry& entry = origin->ov[i];
origin_v[i] =
String::NewFromOneByte(
isolate, entry.origin, v8::NewStringType::kNormal, entry.origin_len)
.ToLocalChecked();
}

Local<Value> holder = Array::New(isolate, origin_v.data(), origin_v.size());
MakeCallback(env()->onorigin_string(), 1, &holder);
}

Expand Down

0 comments on commit 62fefd8

Please sign in to comment.