23
23
#include " node_buffer.h"
24
24
#include " util.h"
25
25
26
- #include " async_wrap-inl.h"
27
26
#include " env-inl.h"
28
27
#include " llhttp.h"
29
28
#include " memory_tracker-inl.h"
@@ -250,17 +249,16 @@ class ConnectionsList : public BaseObject {
250
249
std::set<Parser*, ParserComparator> active_connections_;
251
250
};
252
251
253
- class Parser : public AsyncWrap , public StreamListener {
252
+ class Parser : public BaseObject , public StreamListener {
254
253
friend class ConnectionsList ;
255
254
friend struct ParserComparator ;
256
255
257
256
public:
258
257
Parser (BindingData* binding_data, Local<Object> wrap)
259
- : AsyncWrap (binding_data->env (), wrap),
258
+ : BaseObject (binding_data->env (), wrap),
260
259
current_buffer_len_(0 ),
261
260
current_buffer_data_(nullptr ),
262
- binding_data_(binding_data) {
263
- }
261
+ binding_data_(binding_data) {}
264
262
265
263
SET_NO_MEMORY_INFO ()
266
264
SET_MEMORY_INFO_NAME(Parser)
@@ -289,13 +287,10 @@ class Parser : public AsyncWrap, public StreamListener {
289
287
Local<Value> cb = object ()->Get (env ()->context (), kOnMessageBegin )
290
288
.ToLocalChecked ();
291
289
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 );
290
+ MaybeLocal<Value> r =
291
+ cb.As <Function>()->Call (env ()->context (), object (), 0 , nullptr );
297
292
298
- if (r.IsEmpty ()) callback_scope. MarkAsFailed () ;
293
+ // if (r.IsEmpty()) got_exception_ = true ;
299
294
}
300
295
301
296
return 0 ;
@@ -442,14 +437,8 @@ class Parser : public AsyncWrap, public StreamListener {
442
437
443
438
argv[A_UPGRADE] = Boolean::New (env ()->isolate (), parser_.upgrade );
444
439
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
- }
440
+ MaybeLocal<Value> head_response = cb.As <Function>()->Call (
441
+ env ()->context (), object (), arraysize (argv), argv);
453
442
454
443
int64_t val;
455
444
@@ -478,7 +467,8 @@ class Parser : public AsyncWrap, public StreamListener {
478
467
479
468
Local<Value> buffer = Buffer::Copy (env, at, length).ToLocalChecked ();
480
469
481
- MaybeLocal<Value> r = MakeCallback (cb.As <Function>(), 1 , &buffer);
470
+ MaybeLocal<Value> r =
471
+ cb.As <Function>()->Call (env->context (), object (), 1 , &buffer);
482
472
483
473
if (r.IsEmpty ()) {
484
474
got_exception_ = true ;
@@ -516,14 +506,8 @@ class Parser : public AsyncWrap, public StreamListener {
516
506
if (!cb->IsFunction ())
517
507
return 0 ;
518
508
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
- }
526
-
509
+ MaybeLocal<Value> r =
510
+ cb.As <Function>()->Call (env ()->context (), object (), 0 , nullptr );
527
511
if (r.IsEmpty ()) {
528
512
got_exception_ = true ;
529
513
return -1 ;
@@ -575,11 +559,6 @@ class Parser : public AsyncWrap, public StreamListener {
575
559
static void Free (const FunctionCallbackInfo<Value>& args) {
576
560
Parser* parser;
577
561
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
562
}
584
563
585
564
static void Remove (const FunctionCallbackInfo<Value>& args) {
@@ -638,25 +617,24 @@ class Parser : public AsyncWrap, public StreamListener {
638
617
ConnectionsList* connectionsList = nullptr ;
639
618
640
619
CHECK (args[0 ]->IsInt32 ());
641
- CHECK (args[1 ]->IsObject ());
642
620
643
- if (args.Length () > 2 ) {
644
- CHECK (args[2 ]->IsNumber ());
621
+ if (args.Length () > 1 ) {
622
+ CHECK (args[1 ]->IsNumber ());
645
623
max_http_header_size =
646
- static_cast <uint64_t >(args[2 ].As <Number>()->Value ());
624
+ static_cast <uint64_t >(args[1 ].As <Number>()->Value ());
647
625
}
648
626
if (max_http_header_size == 0 ) {
649
627
max_http_header_size = env->options ()->max_http_header_size ;
650
628
}
651
629
652
- if (args.Length () > 3 ) {
653
- CHECK (args[3 ]->IsInt32 ());
654
- lenient_flags = args[3 ].As <Int32>()->Value ();
630
+ if (args.Length () > 2 ) {
631
+ CHECK (args[2 ]->IsInt32 ());
632
+ lenient_flags = args[2 ].As <Int32>()->Value ();
655
633
}
656
634
657
- if (args.Length () > 4 && !args[4 ]->IsNullOrUndefined ()) {
658
- CHECK (args[4 ]->IsObject ());
659
- ASSIGN_OR_RETURN_UNWRAP (&connectionsList, args[4 ]);
635
+ if (args.Length () > 3 && !args[3 ]->IsNullOrUndefined ()) {
636
+ CHECK (args[3 ]->IsObject ());
637
+ ASSIGN_OR_RETURN_UNWRAP (&connectionsList, args[3 ]);
660
638
}
661
639
662
640
llhttp_type_t type =
@@ -668,13 +646,6 @@ class Parser : public AsyncWrap, public StreamListener {
668
646
// Should always be called from the same context.
669
647
CHECK_EQ (env, parser->env ());
670
648
671
- AsyncWrap::ProviderType provider =
672
- (type == HTTP_REQUEST ?
673
- AsyncWrap::PROVIDER_HTTPINCOMINGMESSAGE
674
- : AsyncWrap::PROVIDER_HTTPCLIENTREQUEST);
675
-
676
- parser->set_provider_type (provider);
677
- parser->AsyncReset (args[1 ].As <Object>());
678
649
parser->Init (type, max_http_header_size, lenient_flags);
679
650
680
651
if (connectionsList != nullptr ) {
@@ -820,7 +791,7 @@ class Parser : public AsyncWrap, public StreamListener {
820
791
current_buffer_len_ = nread;
821
792
current_buffer_data_ = buf.base ;
822
793
823
- MakeCallback (cb.As <Function>(), 1 , &ret);
794
+ USE (cb.As <Function>()-> Call ( env ()-> context (), object (), 1 , &ret) );
824
795
825
796
current_buffer_len_ = 0 ;
826
797
current_buffer_data_ = nullptr ;
@@ -935,11 +906,9 @@ class Parser : public AsyncWrap, public StreamListener {
935
906
url_.ToString (env ())
936
907
};
937
908
938
- MaybeLocal<Value> r = MakeCallback (cb.As <Function>(),
939
- arraysize (argv),
940
- argv);
941
-
942
- if (r.IsEmpty ())
909
+ if (cb.As <Function>()
910
+ ->Call (env ()->context (), object (), arraysize (argv), argv)
911
+ .IsEmpty ())
943
912
got_exception_ = true ;
944
913
945
914
url_.Reset ();
@@ -1299,7 +1268,6 @@ void CreatePerIsolateProperties(IsolateData* isolate_data,
1299
1268
t->Set (FIXED_ONE_BYTE_STRING (isolate, " kLenientAll" ),
1300
1269
Integer::NewFromUnsigned (isolate, kLenientAll ));
1301
1270
1302
- t->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data));
1303
1271
SetProtoMethod (isolate, t, " close" , Parser::Close);
1304
1272
SetProtoMethod (isolate, t, " free" , Parser::Free);
1305
1273
SetProtoMethod (isolate, t, " remove" , Parser::Remove);
0 commit comments