From e7dde8377ed6c71ea79863445955fd8a5d8bb188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 16 May 2024 11:53:25 +0000 Subject: [PATCH] [dart2wasm] Port VM fix for #52083 (sync*) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dart2wasm's sync* runtime library was mostly copied from VM, but we didn't get the fix for #52083 in 9cf26fc. This ports the fix to dart2wasm. This currently doesn't fix any tests as there are other issues with dart2wasm's sync* implementation, which we are fixing in https://dart-review.googlesource.com/c/sdk/+/366663. Change-Id: I9d82d1bbb4c96ccb9bf411a385f4b7ff395a1c19 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366671 Reviewed-by: Martin Kustermann Commit-Queue: Ömer Ağacan --- sdk/lib/_internal/wasm/lib/sync_star_patch.dart | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sdk/lib/_internal/wasm/lib/sync_star_patch.dart b/sdk/lib/_internal/wasm/lib/sync_star_patch.dart index 9f73b7ea83b..ece864f78b5 100644 --- a/sdk/lib/_internal/wasm/lib/sync_star_patch.dart +++ b/sdk/lib/_internal/wasm/lib/sync_star_patch.dart @@ -139,17 +139,22 @@ 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 // current _state for later resumption). _state = _SuspendState(iterable, _state).._iterator = this; } 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; }