From 7271cc8cad06b33d18b75e92260358bedcd7de24 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 25 Mar 2024 16:05:00 +0100 Subject: [PATCH 1/4] Use `async iterable` webidl type in ReadableStream.from --- index.bs | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/index.bs b/index.bs index e05b6fd85..367c7a48c 100644 --- a/index.bs +++ b/index.bs @@ -488,7 +488,7 @@ The Web IDL definition for the {{ReadableStream}} class is given as follows: interface ReadableStream { constructor(optional object underlyingSource, optional QueuingStrategy strategy = {}); - static ReadableStream from(any asyncIterable); + static ReadableStream from(async iterable asyncIterable); readonly attribute boolean locked; @@ -2127,39 +2127,21 @@ The following abstract operations operate on {{ReadableStream}} instances at a h ReadableStreamFromIterable(|asyncIterable|) performs the following steps: 1. Let |stream| be undefined. - 1. Let |iteratorRecord| be ? [$GetIterator$](|asyncIterable|, async). 1. Let |startAlgorithm| be an algorithm that returns undefined. 1. Let |pullAlgorithm| be the following steps: - 1. Let |nextResult| be [$IteratorNext$](|iteratorRecord|). - 1. If |nextResult| is an abrupt completion, return [=a promise rejected with=] - |nextResult|.\[[Value]]. - 1. Let |nextPromise| be [=a promise resolved with=] |nextResult|.\[[Value]]. - 1. Return the result of [=reacting=] to |nextPromise| with the following fulfillment steps, - given |iterResult|: - 1. If [$Type$](|iterResult|) is not Object, throw a {{TypeError}}. - 1. Let |done| be ? [$IteratorComplete$](|iterResult|). - 1. If |done| is true: - 1. Perform ! [$ReadableStreamDefaultControllerClose$](|stream|.[=ReadableStream/[[controller]]=]). - 1. Otherwise: - 1. Let |value| be ? [$IteratorValue$](|iterResult|). - 1. Perform ! [$ReadableStreamDefaultControllerEnqueue$](|stream|.[=ReadableStream/[[controller]]=], - |value|). - + 1. Let |nextPromise| be the result of [=getting the next value/get an async iterable next value=] + from |asyncIterable|. + 1. Return the result of [=reacting=] to |nextPromise|: + - If |next| was fulfilled with value |v|: + 1. If |v| is [=end of iteration=], perform ! [$ReadableStreamDefaultControllerClose$](|stream|.[=ReadableStream/[[controller]]=]). + 1. Otherwise, perform ! [$ReadableStreamDefaultControllerEnqueue$](|stream|.[=ReadableStream/[[controller]]=], |v|). + - If |next| was rejected with reason |r|, perform ! [$ReadableStreamDefaultControllerError$](|stream|.[=ReadableStream/[[controller]]=], |r|). 1. Let |cancelAlgorithm| be the following steps, given |reason|: - 1. Let |iterator| be |iteratorRecord|.\[[Iterator]]. - 1. Let |returnMethod| be [$GetMethod$](|iterator|, "`return`"). - 1. If |returnMethod| is an abrupt completion, return [=a promise rejected with=] - |returnMethod|.\[[Value]]. - 1. If |returnMethod|.\[[Value]] is undefined, return [=a promise resolved with=] undefined. - 1. Let |returnResult| be [$Call$](|returnMethod|.\[[Value]], |iterator|, « |reason| »). - 1. If |returnResult| is an abrupt completion, return [=a promise rejected with=] - |returnResult|.\[[Value]]. - 1. Let |returnPromise| be [=a promise resolved with=] |returnResult|.\[[Value]]. - 1. Return the result of [=reacting=] to |returnPromise| with the following fulfillment steps, - given |iterResult|: - 1. If [$Type$](|iterResult|) is not Object, throw a {{TypeError}}. - 1. Return undefined. + 1. Let |finishPromise| be the result of [=finishing iteration/finish iterating an async iterable=] + of |asyncIterable|. + 1. Return the result of [=reacting=] to |finishPromise|: + - If |finishPromise| was fulfilled, return undefined. + - If |finishPromise| was rejected with reason |r|, throw |r|. 1. Set |stream| to ! [$CreateReadableStream$](|startAlgorithm|, |pullAlgorithm|, |cancelAlgorithm|, 0). 1. Return |stream|. From e2ce1703c45486d8b2e2e4bf56f6f744840d8d6b Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 26 Mar 2024 14:12:00 +0100 Subject: [PATCH 2/4] Wire through reason --- index.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 367c7a48c..09fb4317c 100644 --- a/index.bs +++ b/index.bs @@ -2123,7 +2123,7 @@ The following abstract operations operate on {{ReadableStream}} instances at a h
- + ReadableStreamFromIterable(|asyncIterable|) performs the following steps: 1. Let |stream| be undefined. @@ -2137,8 +2137,8 @@ The following abstract operations operate on {{ReadableStream}} instances at a h 1. Otherwise, perform ! [$ReadableStreamDefaultControllerEnqueue$](|stream|.[=ReadableStream/[[controller]]=], |v|). - If |next| was rejected with reason |r|, perform ! [$ReadableStreamDefaultControllerError$](|stream|.[=ReadableStream/[[controller]]=], |r|). 1. Let |cancelAlgorithm| be the following steps, given |reason|: - 1. Let |finishPromise| be the result of [=finishing iteration/finish iterating an async iterable=] - of |asyncIterable|. + 1. Let |finishPromise| be the result of [=closing/close an async iterable=] |asyncIterable| with + reason |reason|. 1. Return the result of [=reacting=] to |finishPromise|: - If |finishPromise| was fulfilled, return undefined. - If |finishPromise| was rejected with reason |r|, throw |r|. From e85e52a0882624cab753b57d3f33ea8f5c942e54 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 26 Mar 2024 14:12:34 +0100 Subject: [PATCH 3/4] re-add comment --- index.bs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.bs b/index.bs index 09fb4317c..4160027d2 100644 --- a/index.bs +++ b/index.bs @@ -2134,6 +2134,8 @@ The following abstract operations operate on {{ReadableStream}} instances at a h 1. Return the result of [=reacting=] to |nextPromise|: - If |next| was fulfilled with value |v|: 1. If |v| is [=end of iteration=], perform ! [$ReadableStreamDefaultControllerClose$](|stream|.[=ReadableStream/[[controller]]=]). + 1. Otherwise, perform ! [$ReadableStreamDefaultControllerEnqueue$](|stream|.[=ReadableStream/[[controller]]=], |v|). - If |next| was rejected with reason |r|, perform ! [$ReadableStreamDefaultControllerError$](|stream|.[=ReadableStream/[[controller]]=], |r|). 1. Let |cancelAlgorithm| be the following steps, given |reason|: From 28809cb59b1b85f450360efb4a8614c996b5deaf Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 18 Jul 2024 10:50:44 +0200 Subject: [PATCH 4/4] review comment --- index.bs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 4160027d2..d9d73dc30 100644 --- a/index.bs +++ b/index.bs @@ -2141,9 +2141,7 @@ The following abstract operations operate on {{ReadableStream}} instances at a h 1. Let |cancelAlgorithm| be the following steps, given |reason|: 1. Let |finishPromise| be the result of [=closing/close an async iterable=] |asyncIterable| with reason |reason|. - 1. Return the result of [=reacting=] to |finishPromise|: - - If |finishPromise| was fulfilled, return undefined. - - If |finishPromise| was rejected with reason |r|, throw |r|. + 1. Return |finishPromise|. 1. Set |stream| to ! [$CreateReadableStream$](|startAlgorithm|, |pullAlgorithm|, |cancelAlgorithm|, 0). 1. Return |stream|.