Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 46cb0da

Browse filesBrowse files
lundibunditargos
authored andcommitted
http2: replace direct array usage with struct for js_fields_
PR-URL: #30534 Fixes: #30505 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0b88bbd commit 46cb0da
Copy full SHA for 46cb0da

File tree

Expand file treeCollapse file tree

2 files changed

+22
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-12
lines changed
Open diff view settings
Collapse file

‎src/node_http2.cc‎

Copy file name to clipboardExpand all lines: src/node_http2.cc
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,9 @@ Http2Session::Http2Session(Environment* env,
651651
{
652652
// Make the js_fields_ property accessible to JS land.
653653
Local<ArrayBuffer> ab =
654-
ArrayBuffer::New(env->isolate(), js_fields_, kSessionUint8FieldCount);
654+
ArrayBuffer::New(env->isolate(),
655+
reinterpret_cast<uint8_t*>(&js_fields_),
656+
kSessionUint8FieldCount);
655657
Local<Uint8Array> uint8_arr =
656658
Uint8Array::New(ab, 0, kSessionUint8FieldCount);
657659
USE(wrap->Set(env->context(), env->fields_string(), uint8_arr));
@@ -1082,7 +1084,7 @@ int Http2Session::OnFrameNotSent(nghttp2_session* handle,
10821084
if (error_code == NGHTTP2_ERR_SESSION_CLOSING ||
10831085
error_code == NGHTTP2_ERR_STREAM_CLOSED ||
10841086
error_code == NGHTTP2_ERR_STREAM_CLOSING ||
1085-
session->js_fields_[kSessionFrameErrorListenerCount] == 0) {
1087+
session->js_fields_.frame_error_listener_count == 0) {
10861088
return 0;
10871089
}
10881090

@@ -1388,7 +1390,7 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
13881390
// are considered advisory only, so this has no real effect other than to
13891391
// simply let user code know that the priority has changed.
13901392
void Http2Session::HandlePriorityFrame(const nghttp2_frame* frame) {
1391-
if (js_fields_[kSessionPriorityListenerCount] == 0) return;
1393+
if (js_fields_.priority_listener_count == 0) return;
13921394
Isolate* isolate = env()->isolate();
13931395
HandleScope scope(isolate);
13941396
Local<Context> context = env()->context();
@@ -1458,7 +1460,7 @@ void Http2Session::HandleGoawayFrame(const nghttp2_frame* frame) {
14581460

14591461
// Called by OnFrameReceived when a complete ALTSVC frame has been received.
14601462
void Http2Session::HandleAltSvcFrame(const nghttp2_frame* frame) {
1461-
if (!(js_fields_[kBitfield] & (1 << kSessionHasAltsvcListeners))) return;
1463+
if (!(js_fields_.bitfield & (1 << kSessionHasAltsvcListeners))) return;
14621464
Isolate* isolate = env()->isolate();
14631465
HandleScope scope(isolate);
14641466
Local<Context> context = env()->context();
@@ -1537,7 +1539,7 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
15371539
return;
15381540
}
15391541

1540-
if (!(js_fields_[kBitfield] & (1 << kSessionHasPingListeners))) return;
1542+
if (!(js_fields_.bitfield & (1 << kSessionHasPingListeners))) return;
15411543
// Notify the session that a ping occurred
15421544
arg = Buffer::Copy(env(),
15431545
reinterpret_cast<const char*>(frame->ping.opaque_data),
@@ -1549,8 +1551,8 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
15491551
void Http2Session::HandleSettingsFrame(const nghttp2_frame* frame) {
15501552
bool ack = frame->hd.flags & NGHTTP2_FLAG_ACK;
15511553
if (!ack) {
1552-
js_fields_[kBitfield] &= ~(1 << kSessionRemoteSettingsIsUpToDate);
1553-
if (!(js_fields_[kBitfield] & (1 << kSessionHasRemoteSettingsListeners)))
1554+
js_fields_.bitfield &= ~(1 << kSessionRemoteSettingsIsUpToDate);
1555+
if (!(js_fields_.bitfield & (1 << kSessionHasRemoteSettingsListeners)))
15541556
return;
15551557
// This is not a SETTINGS acknowledgement, notify and return
15561558
MakeCallback(env()->http2session_on_settings_function(), 0, nullptr);
Collapse file

‎src/node_http2.h‎

Copy file name to clipboardExpand all lines: src/node_http2.h
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,23 @@ class Http2Stream::Provider::Stream : public Http2Stream::Provider {
675675
void* user_data);
676676
};
677677

678+
typedef struct {
679+
uint8_t bitfield;
680+
uint8_t priority_listener_count;
681+
uint8_t frame_error_listener_count;
682+
} SessionJSFields;
683+
678684
// Indices for js_fields_, which serves as a way to communicate data with JS
679685
// land fast. In particular, we store information about the number/presence
680686
// of certain event listeners in JS, and skip calls from C++ into JS if they
681687
// are missing.
682688
enum SessionUint8Fields {
683-
kBitfield, // See below
684-
kSessionPriorityListenerCount,
685-
kSessionFrameErrorListenerCount,
686-
kSessionUint8FieldCount
689+
kBitfield = offsetof(SessionJSFields, bitfield), // See below
690+
kSessionPriorityListenerCount =
691+
offsetof(SessionJSFields, priority_listener_count),
692+
kSessionFrameErrorListenerCount =
693+
offsetof(SessionJSFields, frame_error_listener_count),
694+
kSessionUint8FieldCount = sizeof(SessionJSFields)
687695
};
688696

689697
enum SessionBitfieldFlags {
@@ -972,7 +980,7 @@ class Http2Session : public AsyncWrap, public StreamListener {
972980
nghttp2_session* session_;
973981

974982
// JS-accessible numeric fields, as indexed by SessionUint8Fields.
975-
uint8_t js_fields_[kSessionUint8FieldCount] = {};
983+
SessionJSFields js_fields_ = {};
976984

977985
// The session type: client or server
978986
nghttp2_session_type session_type_;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.