Skip to content

Commit 53957bf

Browse files
natebiggsCommit Queue
authored and
Commit Queue
committed
[dart2js] Update async* helper to check if stream closed state before re-entering generator body.
If the stream has been closed then re-enter with the appropriate error code. Bug: #55017 Change-Id: Iadf5d039698a48d402a409b5b42ed268885439d1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355040 Commit-Queue: Nate Biggs <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent 17d6ba1 commit 53957bf

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

sdk/lib/_internal/js_runtime/lib/async_patch.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,21 @@ void _asyncStarHelper(
407407
controller.isSuspended = true;
408408
return;
409409
}
410-
bodyFunction(async_status_codes.SUCCESS, null);
410+
bodyFunction(
411+
controller.isCanceled
412+
? async_status_codes.STREAM_WAS_CANCELED
413+
: async_status_codes.SUCCESS,
414+
null);
411415
});
412416
return;
413417
} else if (object.state == _IterationMarker.YIELD_STAR) {
414418
Stream stream = object.value;
415419
// Errors of [stream] are passed though to the main stream. (see
416420
// [AsyncStreamController.addStream]).
417-
// TODO(sigurdm): The spec is not very clear here. Clarify with Gilad.
418421
controller.addStream(stream).then((_) {
419-
// No check for isPaused here because the spec 17.16.2 only
420-
// demands checks *before* each element in [stream] not after the last
421-
// one. On the other hand we check for isCanceled, as that check happens
422-
// after insertion of each element.
422+
// No need to check for pause because to get here the stream either
423+
// completed normally or was cancelled. The stream cannot be paused
424+
// after either of these states.
423425
int errorCode = controller.isCanceled
424426
? async_status_codes.STREAM_WAS_CANCELED
425427
: async_status_codes.SUCCESS;

0 commit comments

Comments
 (0)