@@ -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
@@ -454,32 +450,20 @@ class Parser : public AsyncWrap, public StreamListener {
454
450
455
451
456
452
int on_body (const char * at, size_t length) {
457
- EscapableHandleScope scope (env ()->isolate ());
453
+ if (length == 0 )
454
+ return 0 ;
458
455
459
- Local<Object> obj = object ();
460
- Local<Value> cb = obj->Get (env ()->context (), kOnBody ).ToLocalChecked ();
456
+ Environment* env = this ->env ();
457
+ HandleScope handle_scope (env->isolate ());
458
+
459
+ Local<Value> cb = object ()->Get (env->context (), kOnBody ).ToLocalChecked ();
461
460
462
461
if (!cb->IsFunction ())
463
462
return 0 ;
464
463
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
- }
464
+ Local<Value> buffer = Buffer::Copy (env, at, length).ToLocalChecked ();
473
465
474
- Local<Value> argv[3 ] = {
475
- current_buffer_,
476
- Integer::NewFromUnsigned (
477
- env ()->isolate (), static_cast <uint32_t >(at - current_buffer_data_)),
478
- Integer::NewFromUnsigned (env ()->isolate (), length)};
479
-
480
- MaybeLocal<Value> r = MakeCallback (cb.As <Function>(),
481
- arraysize (argv),
482
- argv);
466
+ MaybeLocal<Value> r = MakeCallback (cb.As <Function>(), 1 , &buffer);
483
467
484
468
if (r.IsEmpty ()) {
485
469
got_exception_ = true ;
@@ -593,17 +577,9 @@ class Parser : public AsyncWrap, public StreamListener {
593
577
static void Execute (const FunctionCallbackInfo<Value>& args) {
594
578
Parser* parser;
595
579
ASSIGN_OR_RETURN_UNWRAP (&parser, args.Holder ());
596
- CHECK (parser->current_buffer_ .IsEmpty ());
597
- CHECK_EQ (parser->current_buffer_len_ , 0 );
598
- CHECK_NULL (parser->current_buffer_data_ );
599
580
600
581
ArrayBufferViewContents<char > buffer (args[0 ]);
601
582
602
- // This is a hack to get the current_buffer to the callbacks with the least
603
- // amount of overhead. Nothing else will run while http_parser_execute()
604
- // runs, therefore this pointer can be set and used for the execution.
605
- parser->current_buffer_ = args[0 ].As <Object>();
606
-
607
583
Local<Value> ret = parser->Execute (buffer.data (), buffer.length ());
608
584
609
585
if (!ret.IsEmpty ())
@@ -615,7 +591,6 @@ class Parser : public AsyncWrap, public StreamListener {
615
591
Parser* parser;
616
592
ASSIGN_OR_RETURN_UNWRAP (&parser, args.Holder ());
617
593
618
- CHECK (parser->current_buffer_ .IsEmpty ());
619
594
Local<Value> ret = parser->Execute (nullptr , 0 );
620
595
621
596
if (!ret.IsEmpty ())
@@ -695,11 +670,6 @@ class Parser : public AsyncWrap, public StreamListener {
695
670
// Should always be called from the same context.
696
671
CHECK_EQ (env, parser->env ());
697
672
698
- if (parser->execute_depth_ ) {
699
- parser->pending_pause_ = should_pause;
700
- return ;
701
- }
702
-
703
673
if (should_pause) {
704
674
llhttp_pause (&parser->parser_ );
705
675
} else {
@@ -801,7 +771,6 @@ class Parser : public AsyncWrap, public StreamListener {
801
771
if (nread == 0 )
802
772
return ;
803
773
804
- current_buffer_.Clear ();
805
774
Local<Value> ret = Execute (buf.base , nread);
806
775
807
776
// Exception
@@ -834,17 +803,12 @@ class Parser : public AsyncWrap, public StreamListener {
834
803
835
804
llhttp_errno_t err;
836
805
837
- // Do not allow re-entering `http_parser_execute()`
838
- CHECK_EQ (execute_depth_, 0 );
839
-
840
- execute_depth_++;
841
806
if (data == nullptr ) {
842
807
err = llhttp_finish (&parser_);
843
808
} else {
844
809
err = llhttp_execute (&parser_, data, len);
845
810
Save ();
846
811
}
847
- execute_depth_--;
848
812
849
813
// Calculate bytes read and resume after Upgrade/CONNECT pause
850
814
size_t nread = len;
@@ -864,8 +828,6 @@ class Parser : public AsyncWrap, public StreamListener {
864
828
llhttp_pause (&parser_);
865
829
}
866
830
867
- // Unassign the 'buffer_' variable
868
- current_buffer_.Clear ();
869
831
current_buffer_len_ = 0 ;
870
832
current_buffer_data_ = nullptr ;
871
833
@@ -989,8 +951,6 @@ class Parser : public AsyncWrap, public StreamListener {
989
951
990
952
991
953
int MaybePause () {
992
- CHECK_NE (execute_depth_, 0 );
993
-
994
954
if (!pending_pause_) {
995
955
return 0 ;
996
956
}
@@ -1018,10 +978,8 @@ class Parser : public AsyncWrap, public StreamListener {
1018
978
size_t num_values_;
1019
979
bool have_flushed_;
1020
980
bool got_exception_;
1021
- Local<Object> current_buffer_;
1022
981
size_t current_buffer_len_;
1023
982
const char * current_buffer_data_;
1024
- unsigned int execute_depth_ = 0 ;
1025
983
bool headers_completed_ = false ;
1026
984
bool pending_pause_ = false ;
1027
985
uint64_t header_nread_ = 0 ;
0 commit comments