@@ -464,10 +464,10 @@ class Parser : public BaseObject, public StreamListener {
464464
465465 Local<Value> buffer = Buffer::Copy (env, at, length).ToLocalChecked ();
466466
467- MaybeLocal<Value> r =
468- cb.As <Function>()->Call (env->context (), object (), 1 , &buffer);
467+ v8::TryCatch try_catch (env-> isolate ());
468+ USE ( cb.As <Function>()->Call (env->context (), object (), 1 , &buffer) );
469469
470- if (r. IsEmpty ()) {
470+ if (try_catch. HasCaught ()) {
471471 got_exception_ = true ;
472472 llhttp_set_error_reason (&parser_, " HPE_JS_EXCEPTION:JS Exception" );
473473 return HPE_USER;
@@ -503,9 +503,11 @@ class Parser : public BaseObject, public StreamListener {
503503 if (!cb->IsFunction ())
504504 return 0 ;
505505
506- MaybeLocal<Value> r =
507- cb.As <Function>()->Call (env ()->context (), object (), 0 , nullptr );
508- if (r.IsEmpty ()) {
506+
507+ v8::TryCatch try_catch (env ()->isolate ());
508+ USE (cb.As <Function>()->Call (env ()->context (), object (), 0 , nullptr ));
509+
510+ if (try_catch.HasCaught ()) {
509511 got_exception_ = true ;
510512 return -1 ;
511513 }
@@ -782,8 +784,14 @@ class Parser : public BaseObject, public StreamListener {
782784 current_buffer_len_ = nread;
783785 current_buffer_data_ = buf.base ;
784786
787+ v8::TryCatch try_catch (env ()->isolate ());
785788 USE (cb.As <Function>()->Call (env ()->context (), object (), 1 , &ret));
786789
790+ if (try_catch.HasCaught ()) {
791+ got_exception_ = true ;
792+ return ;
793+ }
794+
787795 current_buffer_len_ = 0 ;
788796 current_buffer_data_ = nullptr ;
789797 }
@@ -897,10 +905,12 @@ class Parser : public BaseObject, public StreamListener {
897905 url_.ToString (env ())
898906 };
899907
900- if (cb.As <Function>()
901- ->Call (env ()->context (), object (), arraysize (argv), argv)
902- .IsEmpty ())
908+ v8::TryCatch try_catch (env ()->isolate ());
909+ USE (cb.As <Function>()->Call (env ()->context (), object (), arraysize (argv), argv));
910+
911+ if (try_catch.HasCaught ()) {
903912 got_exception_ = true ;
913+ }
904914
905915 url_.Reset ();
906916 have_flushed_ = true ;
0 commit comments