Skip to content

Commit

Permalink
Fix attempting to get the chunk size after strategy is cleared
Browse files Browse the repository at this point in the history
Although a better fix might be to delay size calculation until we've verified that we're not in the erroring or errored states, that has observable differences for certain bad-strategy cases already in the WPT suite, and multiple implementations seem to have converged on this particular fix already.

Closes #1331.
  • Loading branch information
domenic committed Nov 27, 2024
1 parent 8ebee1f commit 86d07e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5373,6 +5373,10 @@ The following abstract operations support the implementation of the
id="writable-stream-default-controller-get-chunk-size">WritableStreamDefaultControllerGetChunkSize(|controller|,
|chunk|)</dfn> performs the following steps:

1. If |controller|.[=WritableStreamDefaultController/[[strategySizeAlgorithm]]=] is undefined, then:
1. Assert: |controller|.[=WritableStreamDefaultController/[[stream]]=].[=WritableStream/[[state]]=] is "`erroring`" or
"`errored`".
1. Return 1.
1. Let |returnValue| be the result of performing
|controller|.[=WritableStreamDefaultController/[[strategySizeAlgorithm]]=], passing in |chunk|,
and interpreting the result as a [=completion record=].
Expand Down
5 changes: 5 additions & 0 deletions reference-implementation/lib/abstract-ops/writable-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,11 @@ function WritableStreamDefaultControllerGetBackpressure(controller) {
}

function WritableStreamDefaultControllerGetChunkSize(controller, chunk) {
if (controller._strategySizeAlgorithm === undefined) {
assert(controller._stream._state === 'erroring' || controller._stream._state === 'errored');
return 1;
}

try {
return controller._strategySizeAlgorithm(chunk);
} catch (chunkSizeE) {
Expand Down

0 comments on commit 86d07e9

Please sign in to comment.