src: minor http2 refactorings

* Simplify Http2Priority struct
* BooleanValue => IsTrue/IsFalse

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/32551
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
pull/32617/head
James M Snell 2020-03-29 10:38:24 -07:00 committed by Anna Henningsen
parent 5f5d3805f0
commit 0be9ebb722
No known key found for this signature in database
GPG Key ID: A94130F0BFC8EBE9
2 changed files with 8 additions and 18 deletions

View File

@ -348,11 +348,11 @@ Http2Priority::Http2Priority(Environment* env,
Local<Context> context = env->context();
int32_t parent_ = parent->Int32Value(context).ToChecked();
int32_t weight_ = weight->Int32Value(context).ToChecked();
bool exclusive_ = exclusive->BooleanValue(env->isolate());
bool exclusive_ = exclusive->IsTrue();
Debug(env, DebugCategory::HTTP2STREAM,
"Http2Priority: parent: %d, weight: %d, exclusive: %s\n",
parent_, weight_, exclusive_ ? "yes" : "no");
nghttp2_priority_spec_init(&spec, parent_, weight_, exclusive_ ? 1 : 0);
nghttp2_priority_spec_init(this, parent_, weight_, exclusive_ ? 1 : 0);
}
@ -996,8 +996,7 @@ int Http2Session::OnStreamClose(nghttp2_session* handle,
MaybeLocal<Value> answer =
stream->MakeCallback(env->http2session_on_stream_close_function(),
1, &arg);
if (answer.IsEmpty() ||
!(answer.ToLocalChecked()->BooleanValue(env->isolate()))) {
if (answer.IsEmpty() || answer.ToLocalChecked()->IsFalse()) {
// Skip to destroy
stream->Destroy();
}
@ -2444,9 +2443,7 @@ void Http2Session::Destroy(const FunctionCallbackInfo<Value>& args) {
Local<Context> context = env->context();
uint32_t code = args[0]->Uint32Value(context).ToChecked();
bool socketDestroyed = args[1]->BooleanValue(env->isolate());
session->Close(code, socketDestroyed);
session->Close(code, args[1]->IsTrue());
}
// Submits a new request on the Http2Session and returns either an error code
@ -2465,7 +2462,7 @@ void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
int32_t ret = 0;
Http2Stream* stream =
session->Http2Session::SubmitRequest(
*priority,
&priority,
Http2Headers(env, headers),
&ret,
static_cast<int>(options));
@ -2638,9 +2635,9 @@ void Http2Stream::Priority(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&stream, args.Holder());
Http2Priority priority(env, args[0], args[1], args[2]);
bool silent = args[3]->BooleanValue(env->isolate());
bool silent = args[3]->IsTrue();
CHECK_EQ(stream->SubmitPriority(*priority, silent), 0);
CHECK_EQ(stream->SubmitPriority(&priority, silent), 0);
Debug(stream, "priority submitted");
}

View File

@ -246,18 +246,11 @@ class Http2Options {
size_t max_outstanding_settings_ = kDefaultMaxSettings;
};
class Http2Priority {
public:
struct Http2Priority : public nghttp2_priority_spec {
Http2Priority(Environment* env,
v8::Local<v8::Value> parent,
v8::Local<v8::Value> weight,
v8::Local<v8::Value> exclusive);
nghttp2_priority_spec* operator*() {
return &spec;
}
private:
nghttp2_priority_spec spec;
};
class Http2StreamListener : public StreamListener {