2323#include " node_buffer.h"
2424#include " util.h"
2525
26- #include " async_wrap-inl.h"
2726#include " env-inl.h"
2827#include " llhttp.h"
2928#include " memory_tracker-inl.h"
@@ -250,17 +249,16 @@ class ConnectionsList : public BaseObject {
250249 std::set<Parser*, ParserComparator> active_connections_;
251250};
252251
253- class Parser : public AsyncWrap , public StreamListener {
252+ class Parser : public BaseObject , public StreamListener {
254253 friend class ConnectionsList ;
255254 friend struct ParserComparator ;
256255
257256 public:
258257 Parser (BindingData* binding_data, Local<Object> wrap)
259- : AsyncWrap (binding_data->env (), wrap),
258+ : BaseObject (binding_data->env (), wrap),
260259 current_buffer_len_(0 ),
261260 current_buffer_data_(nullptr ),
262- binding_data_(binding_data) {
263- }
261+ binding_data_(binding_data) {}
264262
265263 SET_NO_MEMORY_INFO ()
266264 SET_MEMORY_INFO_NAME(Parser)
@@ -289,13 +287,7 @@ class Parser : public AsyncWrap, public StreamListener {
289287 Local<Value> cb = object ()->Get (env ()->context (), kOnMessageBegin )
290288 .ToLocalChecked ();
291289 if (cb->IsFunction ()) {
292- InternalCallbackScope callback_scope (
293- this , InternalCallbackScope::kSkipTaskQueues );
294-
295- MaybeLocal<Value> r = cb.As <Function>()->Call (
296- env ()->context (), object (), 0 , nullptr );
297-
298- if (r.IsEmpty ()) callback_scope.MarkAsFailed ();
290+ USE (cb.As <Function>()->Call (env ()->context (), object (), 0 , nullptr ));
299291 }
300292
301293 return 0 ;
@@ -442,14 +434,8 @@ class Parser : public AsyncWrap, public StreamListener {
442434
443435 argv[A_UPGRADE] = Boolean::New (env ()->isolate (), parser_.upgrade );
444436
445- MaybeLocal<Value> head_response;
446- {
447- InternalCallbackScope callback_scope (
448- this , InternalCallbackScope::kSkipTaskQueues );
449- head_response = cb.As <Function>()->Call (
450- env ()->context (), object (), arraysize (argv), argv);
451- if (head_response.IsEmpty ()) callback_scope.MarkAsFailed ();
452- }
437+ auto head_response = cb.As <Function>()->Call (
438+ env ()->context (), object (), arraysize (argv), argv);
453439
454440 int64_t val;
455441
@@ -478,9 +464,10 @@ class Parser : public AsyncWrap, public StreamListener {
478464
479465 Local<Value> buffer = Buffer::Copy (env, at, length).ToLocalChecked ();
480466
481- MaybeLocal<Value> r = MakeCallback (cb.As <Function>(), 1 , &buffer);
467+ v8::TryCatch try_catch (env->isolate ());
468+ USE (cb.As <Function>()->Call (env->context (), object (), 1 , &buffer));
482469
483- if (r. IsEmpty ()) {
470+ if (try_catch. HasCaught ()) {
484471 got_exception_ = true ;
485472 llhttp_set_error_reason (&parser_, " HPE_JS_EXCEPTION:JS Exception" );
486473 return HPE_USER;
@@ -516,15 +503,10 @@ class Parser : public AsyncWrap, public StreamListener {
516503 if (!cb->IsFunction ())
517504 return 0 ;
518505
519- MaybeLocal<Value> r;
520- {
521- InternalCallbackScope callback_scope (
522- this , InternalCallbackScope::kSkipTaskQueues );
523- r = cb.As <Function>()->Call (env ()->context (), object (), 0 , nullptr );
524- if (r.IsEmpty ()) callback_scope.MarkAsFailed ();
525- }
506+ v8::TryCatch try_catch (env ()->isolate ());
507+ USE (cb.As <Function>()->Call (env ()->context (), object (), 0 , nullptr ));
526508
527- if (r. IsEmpty ()) {
509+ if (try_catch. HasCaught ()) {
528510 got_exception_ = true ;
529511 return -1 ;
530512 }
@@ -571,17 +553,6 @@ class Parser : public AsyncWrap, public StreamListener {
571553 delete parser;
572554 }
573555
574- // TODO(@anonrig): Add V8 Fast API
575- static void Free (const FunctionCallbackInfo<Value>& args) {
576- Parser* parser;
577- ASSIGN_OR_RETURN_UNWRAP (&parser, args.This ());
578-
579- // Since the Parser destructor isn't going to run the destroy() callbacks
580- // it needs to be triggered manually.
581- parser->EmitTraceEventDestroy ();
582- parser->EmitDestroy ();
583- }
584-
585556 // TODO(@anonrig): Add V8 Fast API
586557 static void Remove (const FunctionCallbackInfo<Value>& args) {
587558 Parser* parser;
@@ -639,25 +610,24 @@ class Parser : public AsyncWrap, public StreamListener {
639610 ConnectionsList* connectionsList = nullptr ;
640611
641612 CHECK (args[0 ]->IsInt32 ());
642- CHECK (args[1 ]->IsObject ());
643613
644- if (args.Length () > 2 ) {
645- CHECK (args[2 ]->IsNumber ());
614+ if (args.Length () > 1 ) {
615+ CHECK (args[1 ]->IsNumber ());
646616 max_http_header_size =
647- static_cast <uint64_t >(args[2 ].As <Number>()->Value ());
617+ static_cast <uint64_t >(args[1 ].As <Number>()->Value ());
648618 }
649619 if (max_http_header_size == 0 ) {
650620 max_http_header_size = env->options ()->max_http_header_size ;
651621 }
652622
653- if (args.Length () > 3 ) {
654- CHECK (args[3 ]->IsInt32 ());
655- lenient_flags = args[3 ].As <Int32>()->Value ();
623+ if (args.Length () > 2 ) {
624+ CHECK (args[2 ]->IsInt32 ());
625+ lenient_flags = args[2 ].As <Int32>()->Value ();
656626 }
657627
658- if (args.Length () > 4 && !args[4 ]->IsNullOrUndefined ()) {
659- CHECK (args[4 ]->IsObject ());
660- ASSIGN_OR_RETURN_UNWRAP (&connectionsList, args[4 ]);
628+ if (args.Length () > 3 && !args[3 ]->IsNullOrUndefined ()) {
629+ CHECK (args[3 ]->IsObject ());
630+ ASSIGN_OR_RETURN_UNWRAP (&connectionsList, args[3 ]);
661631 }
662632
663633 llhttp_type_t type =
@@ -669,13 +639,6 @@ class Parser : public AsyncWrap, public StreamListener {
669639 // Should always be called from the same context.
670640 CHECK_EQ (env, parser->env ());
671641
672- AsyncWrap::ProviderType provider =
673- (type == HTTP_REQUEST ?
674- AsyncWrap::PROVIDER_HTTPINCOMINGMESSAGE
675- : AsyncWrap::PROVIDER_HTTPCLIENTREQUEST);
676-
677- parser->set_provider_type (provider);
678- parser->AsyncReset (args[1 ].As <Object>());
679642 parser->Init (type, max_http_header_size, lenient_flags);
680643
681644 if (connectionsList != nullptr ) {
@@ -802,7 +765,13 @@ class Parser : public AsyncWrap, public StreamListener {
802765 current_buffer_len_ = nread;
803766 current_buffer_data_ = buf.base ;
804767
805- MakeCallback (cb.As <Function>(), 1 , &ret);
768+ v8::TryCatch try_catch (env ()->isolate ());
769+ USE (cb.As <Function>()->Call (env ()->context (), object (), 1 , &ret));
770+
771+ if (try_catch.HasCaught ()) {
772+ got_exception_ = true ;
773+ return ;
774+ }
806775
807776 current_buffer_len_ = 0 ;
808777 current_buffer_data_ = nullptr ;
@@ -917,12 +886,11 @@ class Parser : public AsyncWrap, public StreamListener {
917886 url_.ToString (env ())
918887 };
919888
920- MaybeLocal<Value> r = MakeCallback (cb. As <Function>(),
921- arraysize (argv),
922- argv);
889+ v8::TryCatch try_catch ( env ()-> isolate ());
890+ USE (cb. As <Function>()-> Call (
891+ env ()-> context (), object (), arraysize (argv), argv) );
923892
924- if (r.IsEmpty ())
925- got_exception_ = true ;
893+ if (try_catch.HasCaught ()) got_exception_ = true ;
926894
927895 url_.Reset ();
928896 have_flushed_ = true ;
@@ -1287,9 +1255,7 @@ void CreatePerIsolateProperties(IsolateData* isolate_data,
12871255 t->Set (FIXED_ONE_BYTE_STRING (isolate, " kLenientAll" ),
12881256 Integer::NewFromUnsigned (isolate, kLenientAll ));
12891257
1290- t->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data));
12911258 SetProtoMethod (isolate, t, " close" , Parser::Close);
1292- SetProtoMethod (isolate, t, " free" , Parser::Free);
12931259 SetProtoMethod (isolate, t, " remove" , Parser::Remove);
12941260 SetProtoMethod (isolate, t, " execute" , Parser::Execute);
12951261 SetProtoMethod (isolate, t, " finish" , Parser::Finish);
@@ -1358,7 +1324,6 @@ void CreatePerContextProperties(Local<Object> target,
13581324void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
13591325 registry->Register (Parser::New);
13601326 registry->Register (Parser::Close);
1361- registry->Register (Parser::Free);
13621327 registry->Register (Parser::Remove);
13631328 registry->Register (Parser::Execute);
13641329 registry->Register (Parser::Finish);
0 commit comments