@@ -248,11 +248,7 @@ class Parser : public AsyncWrap, public StreamListener {
248248 binding_data_(binding_data) {
249249 }
250250
251-
252- void MemoryInfo (MemoryTracker* tracker) const override {
253- tracker->TrackField (" current_buffer" , current_buffer_);
254- }
255-
251+ SET_NO_MEMORY_INFO ()
256252 SET_MEMORY_INFO_NAME(Parser)
257253 SET_SELF_SIZE(Parser)
258254
@@ -454,32 +450,20 @@ class Parser : public AsyncWrap, public StreamListener {
454450
455451
456452 int on_body (const char * at, size_t length) {
457- EscapableHandleScope scope (env ()->isolate ());
453+ if (length == 0 )
454+ return 0 ;
458455
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 ();
461460
462461 if (!cb->IsFunction ())
463462 return 0 ;
464463
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 ();
473465
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);
483467
484468 if (r.IsEmpty ()) {
485469 got_exception_ = true ;
@@ -593,17 +577,9 @@ class Parser : public AsyncWrap, public StreamListener {
593577 static void Execute (const FunctionCallbackInfo<Value>& args) {
594578 Parser* parser;
595579 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_ );
599580
600581 ArrayBufferViewContents<char > buffer (args[0 ]);
601582
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-
607583 Local<Value> ret = parser->Execute (buffer.data (), buffer.length ());
608584
609585 if (!ret.IsEmpty ())
@@ -615,7 +591,6 @@ class Parser : public AsyncWrap, public StreamListener {
615591 Parser* parser;
616592 ASSIGN_OR_RETURN_UNWRAP (&parser, args.Holder ());
617593
618- CHECK (parser->current_buffer_ .IsEmpty ());
619594 Local<Value> ret = parser->Execute (nullptr , 0 );
620595
621596 if (!ret.IsEmpty ())
@@ -695,11 +670,6 @@ class Parser : public AsyncWrap, public StreamListener {
695670 // Should always be called from the same context.
696671 CHECK_EQ (env, parser->env ());
697672
698- if (parser->execute_depth_ ) {
699- parser->pending_pause_ = should_pause;
700- return ;
701- }
702-
703673 if (should_pause) {
704674 llhttp_pause (&parser->parser_ );
705675 } else {
@@ -801,7 +771,6 @@ class Parser : public AsyncWrap, public StreamListener {
801771 if (nread == 0 )
802772 return ;
803773
804- current_buffer_.Clear ();
805774 Local<Value> ret = Execute (buf.base , nread);
806775
807776 // Exception
@@ -834,17 +803,12 @@ class Parser : public AsyncWrap, public StreamListener {
834803
835804 llhttp_errno_t err;
836805
837- // Do not allow re-entering `http_parser_execute()`
838- CHECK_EQ (execute_depth_, 0 );
839-
840- execute_depth_++;
841806 if (data == nullptr ) {
842807 err = llhttp_finish (&parser_);
843808 } else {
844809 err = llhttp_execute (&parser_, data, len);
845810 Save ();
846811 }
847- execute_depth_--;
848812
849813 // Calculate bytes read and resume after Upgrade/CONNECT pause
850814 size_t nread = len;
@@ -864,8 +828,6 @@ class Parser : public AsyncWrap, public StreamListener {
864828 llhttp_pause (&parser_);
865829 }
866830
867- // Unassign the 'buffer_' variable
868- current_buffer_.Clear ();
869831 current_buffer_len_ = 0 ;
870832 current_buffer_data_ = nullptr ;
871833
@@ -989,8 +951,6 @@ class Parser : public AsyncWrap, public StreamListener {
989951
990952
991953 int MaybePause () {
992- CHECK_NE (execute_depth_, 0 );
993-
994954 if (!pending_pause_) {
995955 return 0 ;
996956 }
@@ -1018,10 +978,8 @@ class Parser : public AsyncWrap, public StreamListener {
1018978 size_t num_values_;
1019979 bool have_flushed_;
1020980 bool got_exception_;
1021- Local<Object> current_buffer_;
1022981 size_t current_buffer_len_;
1023982 const char * current_buffer_data_;
1024- unsigned int execute_depth_ = 0 ;
1025983 bool headers_completed_ = false ;
1026984 bool pending_pause_ = false ;
1027985 uint64_t header_nread_ = 0 ;
0 commit comments