Skip to content

Commit 5c25204

Browse files
authored
Be uniformly lenient in what other-spec algorithms can do
* Be uniformly lenient in what other-spec algorithms can do Previously: * Setting up a readable stream would ignore the return value (or thrown exception) from pullAlgorithm and sizeAlgorithm, instead always returning an immediately-fulfilled promise. * Setting up a writable stream would require closeAlgorithm and abortAlgorithm, if given, to return promises. * Setting up a transform stream would require transformAlgorithm and flushAlgorithm to act synchronously; it would catch any exceptions, but otherwise always return an immediately-fulfilled promise. Now, all of these algorithms are maximally flexible, to make it easier to write other specs: * If not given, the wrapper algorithms return immediately-fulfilled promises. * If they return promises, that promise will be returned, allowing async action. (Web Serial does this currently, even though per the above the Streams spec did not account for it.) * If they synchronously throw exceptions, those exceptions are converted into rejected promises (and never ignored). * If they return nothing, i.e. act synchronously, then the wrapper algorithms take care of returning immediately-fulfilled promises.
1 parent a43a4af commit 5c25204

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

index.bs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6191,16 +6191,21 @@ to grow organically as needed.
61916191
up"><var>pullAlgorithm</var></dfn>, an optional algorithm <dfn export for="ReadableStream/set
61926192
up"><var>cancelAlgorithm</var></dfn>, an optional number <dfn export for="ReadableStream/set
61936193
up"><var>highWaterMark</var></dfn> (default 1), an optional algorithm <dfn export
6194-
for="ReadableStream/set up"><var>sizeAlgorithm</var></dfn>, perform the following steps. If given,
6195-
|sizeAlgorithm| must be an algorithm accepting [=chunk=] objects and returning a number; and if
6196-
given, |highWaterMark| must be a non-negative, non-NaN number.
6194+
for="ReadableStream/set up"><var>sizeAlgorithm</var></dfn>, perform the following steps. If
6195+
given, |pullAlgorithm| and |cancelAlgorithm| may return a promise. If given, |sizeAlgorithm| must
6196+
be an algorithm accepting [=chunk=] objects and returning a number; and if given, |highWaterMark|
6197+
must be a non-negative, non-NaN number.
61976198

61986199
1. Let |startAlgorithm| be an algorithm that returns undefined.
61996200
1. Let |pullAlgorithmWrapper| be an algorithm that runs these steps:
6200-
1. If |pullAlgorithm| was given, run it.
6201+
1. Let |result| be the result of running |pullAlgorithm|, if |pullAlgorithm| was given, or null
6202+
otherwise. If this throws an exception |e|, return [=a promise rejected with=] |e|.
6203+
1. If |result| is a {{Promise}}, then return |result|.
62016204
1. Return [=a promise resolved with=] undefined.
62026205
1. Let |cancelAlgorithmWrapper| be an algorithm that runs these steps:
6203-
1. If |cancelAlgorithm| was given, run it.
6206+
1. Let |result| be the result of running |cancelAlgorithm|, if |cancelAlgorithm| was given, or
6207+
null otherwise. If this throws an exception |e|, return [=a promise rejected with=] |e|.
6208+
1. If |result| is a {{Promise}}, then return |result|.
62046209
1. Return [=a promise resolved with=] undefined.
62056210
1. If |sizeAlgorithm| was not given, then set it to an algorithm that returns 1.
62066211
1. Perform [$InitializeReadableStream$](|stream|).
@@ -6365,16 +6370,20 @@ for="ReadableStream">locked</dfn> if ! [$IsReadableStreamLocked$](|stream|) retu
63656370
up"><var>highWaterMark</var></dfn> (default 1), an optional algorithm <dfn export
63666371
for="WritableStream/set up"><var>sizeAlgorithm</var></dfn>, perform the following steps.
63676372
|writeAlgorithm| must be an algorithm that accepts a [=chunk=] object and returns a promise. If
6368-
given, |closeAlgorithm| and |abortAlgorithm| must return a promise. If given, |sizeAlgorithm| must
6373+
given, |closeAlgorithm| and |abortAlgorithm| may return a promise. If given, |sizeAlgorithm| must
63696374
be an algorithm accepting [=chunk=] objects and returning a number; and if given, |highWaterMark|
63706375
must be a non-negative, non-NaN number.
63716376

63726377
1. Let |startAlgorithm| be an algorithm that returns undefined.
63736378
1. Let |closeAlgorithmWrapper| be an algorithm that runs these steps:
6374-
1. If |closeAlgorithm| was given, return the result of running it.
6379+
1. Let |result| be the result of running |closeAlgorithm|, if |closeAlgorithm| was given, or
6380+
null otherwise. If this throws an exception |e|, return [=a promise rejected with=] |e|.
6381+
1. If |result| is a {{Promise}}, then return |result|.
63756382
1. Return [=a promise resolved with=] undefined.
63766383
1. Let |abortAlgorithmWrapper| be an algorithm that runs these steps:
6377-
1. If |abortAlgorithm| was given, return the result of running it.
6384+
1. Let |result| be the result of running |abortAlgorithm|, if |abortAlgorithm| was given, or
6385+
null otherwise. If this throws an exception |e|, return [=a promise rejected with=] |e|.
6386+
1. If |result| is a {{Promise}}, then return |result|.
63786387
1. Return [=a promise resolved with=] undefined.
63796388
1. If |sizeAlgorithm| was not given, then set it to an algorithm that returns 1.
63806389
1. Perform [$InitializeWritableStream$](|stream|).
@@ -6440,18 +6449,22 @@ reason.
64406449
To <dfn export for="TransformStream" lt="set up|setting up">set up</dfn> a
64416450
newly-[=new|created-via-Web IDL=] {{TransformStream}} |stream| given an algorithm <dfn export
64426451
for="TransformStream/set up"><var>transformAlgorithm</var></dfn> and an optional algorithm <dfn
6443-
export for="TransformStream/set up"><var>flushAlgorithm</var></dfn>:
6452+
export for="TransformStream/set up"><var>flushAlgorithm</var></dfn>, perform the following steps.
6453+
|transformAlgorithm| and, if given, |flushAlgorithm|, may return a promise.
64446454

64456455
1. Let |writableHighWaterMark| be 1.
64466456
1. Let |writableSizeAlgorithm| be an algorithm that returns 1.
64476457
1. Let |readableHighWaterMark| be 0.
64486458
1. Let |readableSizeAlgorithm| be an algorithm that returns 1.
64496459
1. Let |transformAlgorithmWrapper| be an algorithm that runs these steps given a value |chunk|:
6450-
1. Run |transformAlgorithm| given |chunk|. If this throws an exception |e|, return [=a promise
6451-
rejected with=] |e|.
6460+
1. Let |result| be the result of running |transformAlgorithm| given |chunk|. If this throws an
6461+
exception |e|, return [=a promise rejected with=] |e|.
6462+
1. If |result| is a {{Promise}}, then return |result|.
64526463
1. Return [=a promise resolved with=] undefined.
64536464
1. Let |flushAlgorithmWrapper| be an algorithm that runs these steps:
6454-
1. If |flushAlgorithm| was given, run it.
6465+
1. Let |result| be the result of running |flushAlgorithm|, if |flushAlgorithm| was given, or
6466+
null otherwise. If this throws an exception |e|, return [=a promise rejected with=] |e|.
6467+
1. If |result| is a {{Promise}}, then return |result|.
64556468
1. Return [=a promise resolved with=] undefined.
64566469
1. Let |startPromise| be [=a promise resolved with=] undefined.
64576470
1. Perform ! [$InitializeTransformStream$](|stream|, |startPromise|, |writableHighWaterMark|,

0 commit comments

Comments
 (0)