Skip to content

Commit 0be9ebb

Browse files
jasnelladdaleax
authored andcommitted
src: minor http2 refactorings
* 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>
1 parent 5f5d380 commit 0be9ebb

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

src/node_http2.cc

+7-10
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ Http2Priority::Http2Priority(Environment* env,
348348
Local<Context> context = env->context();
349349
int32_t parent_ = parent->Int32Value(context).ToChecked();
350350
int32_t weight_ = weight->Int32Value(context).ToChecked();
351-
bool exclusive_ = exclusive->BooleanValue(env->isolate());
351+
bool exclusive_ = exclusive->IsTrue();
352352
Debug(env, DebugCategory::HTTP2STREAM,
353353
"Http2Priority: parent: %d, weight: %d, exclusive: %s\n",
354354
parent_, weight_, exclusive_ ? "yes" : "no");
355-
nghttp2_priority_spec_init(&spec, parent_, weight_, exclusive_ ? 1 : 0);
355+
nghttp2_priority_spec_init(this, parent_, weight_, exclusive_ ? 1 : 0);
356356
}
357357

358358

@@ -996,8 +996,7 @@ int Http2Session::OnStreamClose(nghttp2_session* handle,
996996
MaybeLocal<Value> answer =
997997
stream->MakeCallback(env->http2session_on_stream_close_function(),
998998
1, &arg);
999-
if (answer.IsEmpty() ||
1000-
!(answer.ToLocalChecked()->BooleanValue(env->isolate()))) {
999+
if (answer.IsEmpty() || answer.ToLocalChecked()->IsFalse()) {
10011000
// Skip to destroy
10021001
stream->Destroy();
10031002
}
@@ -2444,9 +2443,7 @@ void Http2Session::Destroy(const FunctionCallbackInfo<Value>& args) {
24442443
Local<Context> context = env->context();
24452444

24462445
uint32_t code = args[0]->Uint32Value(context).ToChecked();
2447-
bool socketDestroyed = args[1]->BooleanValue(env->isolate());
2448-
2449-
session->Close(code, socketDestroyed);
2446+
session->Close(code, args[1]->IsTrue());
24502447
}
24512448

24522449
// Submits a new request on the Http2Session and returns either an error code
@@ -2465,7 +2462,7 @@ void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
24652462
int32_t ret = 0;
24662463
Http2Stream* stream =
24672464
session->Http2Session::SubmitRequest(
2468-
*priority,
2465+
&priority,
24692466
Http2Headers(env, headers),
24702467
&ret,
24712468
static_cast<int>(options));
@@ -2638,9 +2635,9 @@ void Http2Stream::Priority(const FunctionCallbackInfo<Value>& args) {
26382635
ASSIGN_OR_RETURN_UNWRAP(&stream, args.Holder());
26392636

26402637
Http2Priority priority(env, args[0], args[1], args[2]);
2641-
bool silent = args[3]->BooleanValue(env->isolate());
2638+
bool silent = args[3]->IsTrue();
26422639

2643-
CHECK_EQ(stream->SubmitPriority(*priority, silent), 0);
2640+
CHECK_EQ(stream->SubmitPriority(&priority, silent), 0);
26442641
Debug(stream, "priority submitted");
26452642
}
26462643

src/node_http2.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,11 @@ class Http2Options {
246246
size_t max_outstanding_settings_ = kDefaultMaxSettings;
247247
};
248248

249-
class Http2Priority {
250-
public:
249+
struct Http2Priority : public nghttp2_priority_spec {
251250
Http2Priority(Environment* env,
252251
v8::Local<v8::Value> parent,
253252
v8::Local<v8::Value> weight,
254253
v8::Local<v8::Value> exclusive);
255-
256-
nghttp2_priority_spec* operator*() {
257-
return &spec;
258-
}
259-
private:
260-
nghttp2_priority_spec spec;
261254
};
262255

263256
class Http2StreamListener : public StreamListener {

0 commit comments

Comments
 (0)