From 9cf26fc3cdc8595ff004e990f40ef6392cfc5b36 Mon Sep 17 00:00:00 2001 From: Alexander Markov Date: Wed, 19 Apr 2023 13:50:19 +0000 Subject: [PATCH] [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 Reviewed-by: Martin Kustermann --- sdk/lib/_internal/vm/lib/async_patch.dart | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sdk/lib/_internal/vm/lib/async_patch.dart b/sdk/lib/_internal/vm/lib/async_patch.dart index 4c71903977e..b4ebd933b12 100644 --- a/sdk/lib/_internal/vm/lib/async_patch.dart +++ b/sdk/lib/_internal/vm/lib/async_patch.dart @@ -572,6 +572,8 @@ class _SyncStarIterator implements Iterator { // 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 implements Iterator { 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; }