Skip to content

Commit

Permalink
src: minor http2 refactorings
Browse files Browse the repository at this point in the history
* Simplify Http2Priority struct
* BooleanValue => IsTrue/IsFalse

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

PR-URL: #32551
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
jasnell authored and addaleax committed Apr 2, 2020
1 parent 5f5d380 commit 0be9ebb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
17 changes: 7 additions & 10 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -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");
}

Expand Down
9 changes: 1 addition & 8 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0be9ebb

Please sign in to comment.