From 8a8c950765624338d72db4eaecd5ee5edbcf825c Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 27 Jan 2025 13:56:12 -0500 Subject: [PATCH] `from()`: Close synchronous iterators properly (#192) --- spec.bs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/spec.bs b/spec.bs index bdb0817..f5bb7d5 100644 --- a/spec.bs +++ b/spec.bs @@ -27,8 +27,9 @@ urlPrefix: https://tc39.es/ecma262/#; spec: ECMASCRIPT type: dfn text: current realm text: Object; url: sec-object-type - text: normal completion; url: sec-normalcompletion - text: throw completion; url: sec-throwcompletion + text: normal completion; url: sec-completion-record-specification-type + text: NormalCompletion; url: sec-normalcompletion + text: throw completion; url: sec-completion-record-specification-type url: sec-returnifabrupt-shorthands text: ? text: ! @@ -502,6 +503,9 @@ An internal observer is a [=struct=] with the following [=struct/item Otherwise, return a [=new=] {{Observable}} whose [=Observable/subscribe callback=] is an algorithm that takes a {{Subscriber}} |subscriber| and does the following: + 1. If |subscriber|'s [=Subscriber/subscription controller=]'s [=AbortController/signal=] is + [=AbortSignal/aborted=], then return. + 1. Let |iteratorRecordCompletion| be [$GetIterator$](|value|, sync). 1. If |iteratorRecordCompletion| is a [=throw completion=], then run |subscriber|'s @@ -510,6 +514,14 @@ An internal observer is a [=struct=] with the following [=struct/item 1. Let |iteratorRecord| be [=!=] |iteratorRecordCompletion|. + 1. If |subscriber|'s [=Subscriber/subscription controller=]'s [=AbortController/signal=] is + [=AbortSignal/aborted=], then return. + + 1. [=AbortSignal/add|Add the following abort algorithm=] to |subscriber|'s + [=Subscriber/subscription controller=]'s [=AbortController/signal=]: + + 1. Run [$IteratorClose$](|iteratorRecord|, [=NormalCompletion=](UNUSED)). + 1. [=iteration/While=] true: 1. Let |next| be [$IteratorStepValue$](|iteratorRecord|). @@ -529,6 +541,9 @@ An internal observer is a [=struct=] with the following [=struct/item 1. Run |subscriber|'s {{Subscriber/next()}} given |next|. + 1. If |subscriber|'s [=Subscriber/subscription controller=]'s [=AbortController/signal=] + is [=AbortSignal/aborted=], then [=iteration/break=]. + 1. From Promise: If [$IsPromise$](|value|) is true, then: