@@ -434,6 +434,7 @@ static RawObject asyncGenAcloseSend(Thread* thread, RawObject raw_self_obj,
434
434
RawObject send_value_raw) {
435
435
HandleScope scope (thread);
436
436
Object self_obj (&scope, raw_self_obj);
437
+ Object send_value (&scope, send_value_raw);
437
438
if (!self_obj.isAsyncGeneratorAclose ()) {
438
439
return thread->raiseWithFmt (LayoutId::kTypeError ,
439
440
" Must be called with an async_generator_aclose "
@@ -454,7 +455,6 @@ static RawObject asyncGenAcloseSend(Thread* thread, RawObject raw_self_obj,
454
455
// to make progress through async-like yields.
455
456
Object res (&scope, NoneType::object ());
456
457
AsyncGenerator generator (&scope, self.generator ());
457
- Object send_value (&scope, send_value_raw);
458
458
if (state == AsyncGeneratorOpIterBase::State::Init) {
459
459
if (!send_value.isNoneType ()) {
460
460
return thread->raiseWithFmt (
@@ -586,6 +586,7 @@ static RawObject asyncGenAsendSend(Thread* thread, RawObject raw_self_obj,
586
586
RawObject send_value_raw) {
587
587
HandleScope scope (thread);
588
588
Object self_obj (&scope, raw_self_obj);
589
+ Object send_value (&scope, send_value_raw);
589
590
if (!self_obj.isAsyncGeneratorAsend ()) {
590
591
return thread->raiseWithFmt (LayoutId::kTypeError ,
591
592
" Must be called with an async_generator_asend "
@@ -601,7 +602,6 @@ static RawObject asyncGenAsendSend(Thread* thread, RawObject raw_self_obj,
601
602
}
602
603
// Only use primed value for initial send, and only if no other specific value
603
604
// is provided.
604
- Object send_value (&scope, send_value_raw);
605
605
if (state == AsyncGeneratorOpIterBase::State::Init) {
606
606
if (send_value.isNoneType ()) {
607
607
send_value = self.value ();
@@ -710,6 +710,7 @@ static RawObject asyncGenAthrowSend(Thread* thread, RawObject raw_self_obj,
710
710
RawObject send_value_raw) {
711
711
HandleScope scope (thread);
712
712
Object self_obj (&scope, raw_self_obj);
713
+ Object send_value (&scope, send_value_raw);
713
714
if (!self_obj.isAsyncGeneratorAthrow ()) {
714
715
return thread->raiseWithFmt (LayoutId::kTypeError ,
715
716
" Must be called with an async_generator_athrow "
@@ -730,7 +731,6 @@ static RawObject asyncGenAthrowSend(Thread* thread, RawObject raw_self_obj,
730
731
// through async-like yields.
731
732
Object res (&scope, NoneType::object ());
732
733
AsyncGenerator generator (&scope, self.generator ());
733
- Object send_value (&scope, send_value_raw);
734
734
if (state == AsyncGeneratorOpIterBase::State::Init) {
735
735
if (!send_value.isNoneType ()) {
736
736
return thread->raiseWithFmt (
@@ -747,15 +747,11 @@ static RawObject asyncGenAthrowSend(Thread* thread, RawObject raw_self_obj,
747
747
// Handle StopAsyncIteration and GeneratorExit exceptions raised here.
748
748
// Other exceptions are handled further down.
749
749
if (res.isErrorException ()) {
750
- if (thread->pendingExceptionMatches (LayoutId::kStopAsyncIteration )) {
750
+ if (thread->pendingExceptionMatches (LayoutId::kStopAsyncIteration ) ||
751
+ thread->pendingExceptionMatches (LayoutId::kGeneratorExit )) {
751
752
self.setState (AsyncGeneratorOpIterBase::State::Closed);
752
753
return *res;
753
754
}
754
- if (thread->pendingExceptionMatches (LayoutId::kGeneratorExit )) {
755
- self.setState (AsyncGeneratorOpIterBase::State::Closed);
756
- thread->clearPendingException ();
757
- return thread->raiseStopIteration ();
758
- }
759
755
}
760
756
} else {
761
757
DCHECK (state == AsyncGeneratorOpIterBase::State::Iter, " Unexpected state" );
0 commit comments