[vm] Fix handling of exceptions thrown from Iterable.iterator during yield*

TEST=language/sync_star/sync_star_exception_iterator_test
Fixes https://github.com/dart-lang/sdk/issues/52083

Change-Id: I6f26189b5d5df1c1804cd6cd7a64f72bdbe55f94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295922
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Alexander Markov 2023-04-19 13:50:19 +00:00 committed by Commit Queue
parent 3e2d3bc77f
commit 9cf26fc3cd

View file

@ -572,6 +572,8 @@ class _SyncStarIterator<T> implements Iterator<T> {
// Case: yield* some_iterator.
final iterable = _yieldStarIterable;
if (iterable != null) {
_yieldStarIterable = null;
_current = null;
if (iterable is _SyncStarIterable) {
// We got a recursive yield* of sync* function. Instead of creating
// a new iterator we replace our current _state (remembering the
@ -583,11 +585,14 @@ class _SyncStarIterator<T> implements Iterator<T> {
nestedState._functionData = this;
_state = nestedState;
} else {
_yieldStarIterator = iterable.iterator;
try {
_yieldStarIterator = iterable.iterator;
} catch (exception, stackTrace) {
pendingException = exception;
pendingStackTrace = stackTrace;
}
}
_yieldStarIterable = null;
_current = null;
// Fetch the next item.
// Fetch the next item or continue with exception.
continue;
}