@@ -248,11 +248,7 @@ class Parser : public AsyncWrap, public StreamListener {
248
248
binding_data_(binding_data) {
249
249
}
250
250
251
-
252
- void MemoryInfo (MemoryTracker* tracker) const override {
253
- tracker->TrackField (" current_buffer" , current_buffer_);
254
- }
255
-
251
+ SET_NO_MEMORY_INFO ()
256
252
SET_MEMORY_INFO_NAME(Parser)
257
253
SET_SELF_SIZE(Parser)
258
254
@@ -462,19 +458,14 @@ class Parser : public AsyncWrap, public StreamListener {
462
458
if (!cb->IsFunction ())
463
459
return 0 ;
464
460
465
- // We came from consumed stream
466
- if (current_buffer_.IsEmpty ()) {
467
- // Make sure Buffer will be in parent HandleScope
468
- current_buffer_ = scope.Escape (Buffer::Copy (
469
- env ()->isolate (),
470
- current_buffer_data_,
471
- current_buffer_len_).ToLocalChecked ());
472
- }
461
+ // Make sure Buffer will be in parent HandleScope
462
+ Local<Object> current_buffer = scope.Escape (
463
+ Buffer::Copy (env ()->isolate (), at, length).ToLocalChecked ());
473
464
474
465
Local<Value> argv[3 ] = {
475
- current_buffer_ ,
466
+ current_buffer ,
476
467
Integer::NewFromUnsigned (
477
- env ()->isolate (), static_cast < uint32_t >(at - current_buffer_data_) ),
468
+ env ()->isolate (), 0 ),
478
469
Integer::NewFromUnsigned (env ()->isolate (), length)};
479
470
480
471
MaybeLocal<Value> r = MakeCallback (cb.As <Function>(),
@@ -594,45 +585,8 @@ class Parser : public AsyncWrap, public StreamListener {
594
585
Parser* parser;
595
586
ASSIGN_OR_RETURN_UNWRAP (&parser, args.Holder ());
596
587
597
- // If parser.Execute is invoked within one of the callbacks,
598
- // like kOnHeadersComplete, it is scheduled before the buffer is
599
- // emptied and thus all assertions fails. For this reason we
600
- // postpone the actual execution.
601
- if (!parser->current_buffer_ .IsEmpty ()) {
602
- ArrayBufferViewContents<char > buffer (args[0 ]);
603
-
604
- Environment::GetCurrent (args)->SetImmediate (
605
- [parser, args, buffer](Environment* env) {
606
- CHECK (parser->current_buffer_ .IsEmpty ());
607
- CHECK_EQ (parser->current_buffer_len_ , 0 );
608
- CHECK_NULL (parser->current_buffer_data_ );
609
-
610
- // This is a hack to get the current_buffer to the callbacks
611
- // with the least amount of overhead. Nothing else will run
612
- // while http_parser_execute() runs, therefore this pointer
613
- // can be set and used for the execution.
614
- parser->current_buffer_ = args[0 ].As <Object>();
615
-
616
- Local<Value> ret = parser->Execute (buffer.data (), buffer.length ());
617
-
618
- if (!ret.IsEmpty ())
619
- args.GetReturnValue ().Set (ret);
620
- });
621
-
622
- return ;
623
- }
624
-
625
- CHECK (parser->current_buffer_ .IsEmpty ());
626
- CHECK_EQ (parser->current_buffer_len_ , 0 );
627
- CHECK_NULL (parser->current_buffer_data_ );
628
-
629
588
ArrayBufferViewContents<char > buffer (args[0 ]);
630
589
631
- // This is a hack to get the current_buffer to the callbacks with the least
632
- // amount of overhead. Nothing else will run while http_parser_execute()
633
- // runs, therefore this pointer can be set and used for the execution.
634
- parser->current_buffer_ = args[0 ].As <Object>();
635
-
636
590
Local<Value> ret = parser->Execute (buffer.data (), buffer.length ());
637
591
638
592
if (!ret.IsEmpty ())
@@ -644,7 +598,6 @@ class Parser : public AsyncWrap, public StreamListener {
644
598
Parser* parser;
645
599
ASSIGN_OR_RETURN_UNWRAP (&parser, args.Holder ());
646
600
647
- CHECK (parser->current_buffer_ .IsEmpty ());
648
601
Local<Value> ret = parser->Execute (nullptr , 0 );
649
602
650
603
if (!ret.IsEmpty ())
@@ -724,11 +677,6 @@ class Parser : public AsyncWrap, public StreamListener {
724
677
// Should always be called from the same context.
725
678
CHECK_EQ (env, parser->env ());
726
679
727
- if (parser->execute_depth_ ) {
728
- parser->pending_pause_ = should_pause;
729
- return ;
730
- }
731
-
732
680
if (should_pause) {
733
681
llhttp_pause (&parser->parser_ );
734
682
} else {
@@ -830,7 +778,6 @@ class Parser : public AsyncWrap, public StreamListener {
830
778
if (nread == 0 )
831
779
return ;
832
780
833
- current_buffer_.Clear ();
834
781
Local<Value> ret = Execute (buf.base , nread);
835
782
836
783
// Exception
@@ -863,17 +810,12 @@ class Parser : public AsyncWrap, public StreamListener {
863
810
864
811
llhttp_errno_t err;
865
812
866
- // Do not allow re-entering `http_parser_execute()`
867
- CHECK_EQ (execute_depth_, 0 );
868
-
869
- execute_depth_++;
870
813
if (data == nullptr ) {
871
814
err = llhttp_finish (&parser_);
872
815
} else {
873
816
err = llhttp_execute (&parser_, data, len);
874
817
Save ();
875
818
}
876
- execute_depth_--;
877
819
878
820
// Calculate bytes read and resume after Upgrade/CONNECT pause
879
821
size_t nread = len;
@@ -893,8 +835,6 @@ class Parser : public AsyncWrap, public StreamListener {
893
835
llhttp_pause (&parser_);
894
836
}
895
837
896
- // Unassign the 'buffer_' variable
897
- current_buffer_.Clear ();
898
838
current_buffer_len_ = 0 ;
899
839
current_buffer_data_ = nullptr ;
900
840
@@ -1018,8 +958,6 @@ class Parser : public AsyncWrap, public StreamListener {
1018
958
1019
959
1020
960
int MaybePause () {
1021
- CHECK_NE (execute_depth_, 0 );
1022
-
1023
961
if (!pending_pause_) {
1024
962
return 0 ;
1025
963
}
@@ -1047,7 +985,6 @@ class Parser : public AsyncWrap, public StreamListener {
1047
985
size_t num_values_;
1048
986
bool have_flushed_;
1049
987
bool got_exception_;
1050
- Local<Object> current_buffer_;
1051
988
size_t current_buffer_len_;
1052
989
const char * current_buffer_data_;
1053
990
unsigned int execute_depth_ = 0 ;
0 commit comments