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 e92afd9

Browse filesBrowse files
lundibundiaddaleax
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 3475f9b commit e92afd9
Copy full SHA for e92afd9

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
@@ -647,7 +647,9 @@ Http2Session::Http2Session(Environment* env,
647647
{
648648
// Make the js_fields_ property accessible to JS land.
649649
Local<ArrayBuffer> ab =
650-
ArrayBuffer::New(env->isolate(), js_fields_, kSessionUint8FieldCount);
650+
ArrayBuffer::New(env->isolate(),
651+
reinterpret_cast<uint8_t*>(&js_fields_),
652+
kSessionUint8FieldCount);
651653
Local<Uint8Array> uint8_arr =
652654
Uint8Array::New(ab, 0, kSessionUint8FieldCount);
653655
USE(wrap->Set(env->context(), env->fields_string(), uint8_arr));
@@ -1046,7 +1048,7 @@ int Http2Session::OnFrameNotSent(nghttp2_session* handle,
10461048
if (error_code == NGHTTP2_ERR_SESSION_CLOSING ||
10471049
error_code == NGHTTP2_ERR_STREAM_CLOSED ||
10481050
error_code == NGHTTP2_ERR_STREAM_CLOSING ||
1049-
session->js_fields_[kSessionFrameErrorListenerCount] == 0) {
1051+
session->js_fields_.frame_error_listener_count == 0) {
10501052
return 0;
10511053
}
10521054

@@ -1349,7 +1351,7 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
13491351
// are considered advisory only, so this has no real effect other than to
13501352
// simply let user code know that the priority has changed.
13511353
void Http2Session::HandlePriorityFrame(const nghttp2_frame* frame) {
1352-
if (js_fields_[kSessionPriorityListenerCount] == 0) return;
1354+
if (js_fields_.priority_listener_count == 0) return;
13531355
Isolate* isolate = env()->isolate();
13541356
HandleScope scope(isolate);
13551357
Local<Context> context = env()->context();
@@ -1418,7 +1420,7 @@ void Http2Session::HandleGoawayFrame(const nghttp2_frame* frame) {
14181420

14191421
// Called by OnFrameReceived when a complete ALTSVC frame has been received.
14201422
void Http2Session::HandleAltSvcFrame(const nghttp2_frame* frame) {
1421-
if (!(js_fields_[kBitfield] & (1 << kSessionHasAltsvcListeners))) return;
1423+
if (!(js_fields_.bitfield & (1 << kSessionHasAltsvcListeners))) return;
14221424
Isolate* isolate = env()->isolate();
14231425
HandleScope scope(isolate);
14241426
Local<Context> context = env()->context();
@@ -1497,7 +1499,7 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
14971499
return;
14981500
}
14991501

1500-
if (!(js_fields_[kBitfield] & (1 << kSessionHasPingListeners))) return;
1502+
if (!(js_fields_.bitfield & (1 << kSessionHasPingListeners))) return;
15011503
// Notify the session that a ping occurred
15021504
arg = Buffer::Copy(env(),
15031505
reinterpret_cast<const char*>(frame->ping.opaque_data),
@@ -1509,8 +1511,8 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
15091511
void Http2Session::HandleSettingsFrame(const nghttp2_frame* frame) {
15101512
bool ack = frame->hd.flags & NGHTTP2_FLAG_ACK;
15111513
if (!ack) {
1512-
js_fields_[kBitfield] &= ~(1 << kSessionRemoteSettingsIsUpToDate);
1513-
if (!(js_fields_[kBitfield] & (1 << kSessionHasRemoteSettingsListeners)))
1514+
js_fields_.bitfield &= ~(1 << kSessionRemoteSettingsIsUpToDate);
1515+
if (!(js_fields_.bitfield & (1 << kSessionHasRemoteSettingsListeners)))
15141516
return;
15151517
// This is not a SETTINGS acknowledgement, notify and return
15161518
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
@@ -673,15 +673,23 @@ class Http2Stream::Provider::Stream : public Http2Stream::Provider {
673673
void* user_data);
674674
};
675675

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

687695
enum SessionBitfieldFlags {
@@ -968,7 +976,7 @@ class Http2Session : public AsyncWrap, public StreamListener {
968976
nghttp2_session* session_;
969977

970978
// JS-accessible numeric fields, as indexed by SessionUint8Fields.
971-
uint8_t js_fields_[kSessionUint8FieldCount] = {};
979+
SessionJSFields js_fields_ = {};
972980

973981
// The session type: client or server
974982
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.