@@ -568,42 +568,23 @@ Http2Session::Http2Session(Environment* env,
568
568
outgoing_storage_.reserve (1024 );
569
569
outgoing_buffers_.reserve (32 );
570
570
571
- {
572
- // Make the js_fields_ property accessible to JS land.
573
- std::unique_ptr<BackingStore> backing =
574
- ArrayBuffer::NewBackingStore (
575
- reinterpret_cast <uint8_t *>(&js_fields_),
576
- kSessionUint8FieldCount ,
577
- [](void *, size_t , void *){},
578
- nullptr );
579
- Local<ArrayBuffer> ab =
580
- ArrayBuffer::New (env->isolate (), std::move (backing));
581
- // TODO(thangktran): drop this check when V8 is pumped to 8.0 .
582
- if (!ab->IsExternal ())
583
- ab->Externalize (ab->GetBackingStore ());
584
- ab->SetPrivate (env->context (),
585
- env->arraybuffer_untransferable_private_symbol (),
586
- True (env->isolate ())).Check ();
587
- js_fields_ab_.Reset (env->isolate (), ab);
588
- Local<Uint8Array> uint8_arr =
589
- Uint8Array::New (ab, 0 , kSessionUint8FieldCount );
590
- USE (wrap->Set (env->context (), env->fields_string (), uint8_arr));
591
- }
571
+ // Make the js_fields_ property accessible to JS land.
572
+ js_fields_store_ =
573
+ ArrayBuffer::NewBackingStore (env->isolate (), sizeof (SessionJSFields));
574
+ js_fields_ = new (js_fields_store_->Data ()) SessionJSFields;
575
+
576
+ Local<ArrayBuffer> ab = ArrayBuffer::New (env->isolate (), js_fields_store_);
577
+ Local<Uint8Array> uint8_arr =
578
+ Uint8Array::New (ab, 0 , kSessionUint8FieldCount );
579
+ USE (wrap->Set (env->context (), env->fields_string (), uint8_arr));
592
580
}
593
581
594
582
Http2Session::~Http2Session () {
595
583
CHECK_EQ (flags_ & SESSION_STATE_HAS_SCOPE, 0 );
596
584
Debug (this , " freeing nghttp2 session" );
597
585
nghttp2_session_del (session_);
598
586
CHECK_EQ (current_nghttp2_memory_, 0 );
599
- HandleScope handle_scope (env ()->isolate ());
600
- // Detach js_fields_ab_ to avoid having problem when new Http2Session
601
- // instances are created on the same location of previous
602
- // instances. This in turn will call ArrayBuffer::NewBackingStore()
603
- // multiple times with the same buffer address and causing error.
604
- // Ref: https://github.com/nodejs/node/pull/30782
605
- Local<ArrayBuffer> ab = js_fields_ab_.Get (env ()->isolate ());
606
- ab->Detach ();
587
+ js_fields_->~SessionJSFields ();
607
588
}
608
589
609
590
std::string Http2Session::diagnostic_name () const {
@@ -871,7 +852,7 @@ int Http2Session::OnBeginHeadersCallback(nghttp2_session* handle,
871
852
Http2Stream::New (session, id, frame->headers .cat ) ==
872
853
nullptr )) {
873
854
if (session->rejected_stream_count_ ++ >
874
- session->js_fields_ . max_rejected_streams )
855
+ session->js_fields_ -> max_rejected_streams )
875
856
return NGHTTP2_ERR_CALLBACK_FAILURE;
876
857
// Too many concurrent streams being opened
877
858
nghttp2_submit_rst_stream (**session, NGHTTP2_FLAG_NONE, id,
@@ -965,9 +946,9 @@ int Http2Session::OnInvalidFrame(nghttp2_session* handle,
965
946
Debug (session,
966
947
" invalid frame received (%u/%u), code: %d" ,
967
948
session->invalid_frame_count_ ,
968
- session->js_fields_ . max_invalid_frames ,
949
+ session->js_fields_ -> max_invalid_frames ,
969
950
lib_error_code);
970
- if (session->invalid_frame_count_ ++ > session->js_fields_ . max_invalid_frames )
951
+ if (session->invalid_frame_count_ ++ > session->js_fields_ -> max_invalid_frames )
971
952
return 1 ;
972
953
973
954
// If the error is fatal or if error code is ERR_STREAM_CLOSED... emit error
@@ -1003,7 +984,7 @@ int Http2Session::OnFrameNotSent(nghttp2_session* handle,
1003
984
if (error_code == NGHTTP2_ERR_SESSION_CLOSING ||
1004
985
error_code == NGHTTP2_ERR_STREAM_CLOSED ||
1005
986
error_code == NGHTTP2_ERR_STREAM_CLOSING ||
1006
- session->js_fields_ . frame_error_listener_count == 0 ) {
987
+ session->js_fields_ -> frame_error_listener_count == 0 ) {
1007
988
return 0 ;
1008
989
}
1009
990
@@ -1306,7 +1287,7 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
1306
1287
// are considered advisory only, so this has no real effect other than to
1307
1288
// simply let user code know that the priority has changed.
1308
1289
void Http2Session::HandlePriorityFrame (const nghttp2_frame* frame) {
1309
- if (js_fields_. priority_listener_count == 0 ) return ;
1290
+ if (js_fields_-> priority_listener_count == 0 ) return ;
1310
1291
Isolate* isolate = env ()->isolate ();
1311
1292
HandleScope scope (isolate);
1312
1293
Local<Context> context = env ()->context ();
@@ -1375,7 +1356,7 @@ void Http2Session::HandleGoawayFrame(const nghttp2_frame* frame) {
1375
1356
1376
1357
// Called by OnFrameReceived when a complete ALTSVC frame has been received.
1377
1358
void Http2Session::HandleAltSvcFrame (const nghttp2_frame* frame) {
1378
- if (!(js_fields_. bitfield & (1 << kSessionHasAltsvcListeners ))) return ;
1359
+ if (!(js_fields_-> bitfield & (1 << kSessionHasAltsvcListeners ))) return ;
1379
1360
Isolate* isolate = env ()->isolate ();
1380
1361
HandleScope scope (isolate);
1381
1362
Local<Context> context = env ()->context ();
@@ -1454,7 +1435,7 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
1454
1435
return ;
1455
1436
}
1456
1437
1457
- if (!(js_fields_. bitfield & (1 << kSessionHasPingListeners ))) return ;
1438
+ if (!(js_fields_-> bitfield & (1 << kSessionHasPingListeners ))) return ;
1458
1439
// Notify the session that a ping occurred
1459
1440
arg = Buffer::Copy (env (),
1460
1441
reinterpret_cast <const char *>(frame->ping .opaque_data ),
@@ -1466,8 +1447,8 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
1466
1447
void Http2Session::HandleSettingsFrame (const nghttp2_frame* frame) {
1467
1448
bool ack = frame->hd .flags & NGHTTP2_FLAG_ACK;
1468
1449
if (!ack) {
1469
- js_fields_. bitfield &= ~(1 << kSessionRemoteSettingsIsUpToDate );
1470
- if (!(js_fields_. bitfield & (1 << kSessionHasRemoteSettingsListeners )))
1450
+ js_fields_-> bitfield &= ~(1 << kSessionRemoteSettingsIsUpToDate );
1451
+ if (!(js_fields_-> bitfield & (1 << kSessionHasRemoteSettingsListeners )))
1471
1452
return ;
1472
1453
// This is not a SETTINGS acknowledgement, notify and return
1473
1454
MakeCallback (env ()->http2session_on_settings_function (), 0 , nullptr );
0 commit comments