From bd98d4dac3d1100563adb5b7f52b37024e7742ac Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 26 Nov 2024 15:56:04 +0900 Subject: [PATCH] Fix attempting to get the chunk size after strategy is cleared 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. --- index.bs | 4 ++++ .../lib/abstract-ops/writable-streams.js | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/index.bs b/index.bs index 8b9bf7ad2..03774cb42 100644 --- a/index.bs +++ b/index.bs @@ -5373,6 +5373,10 @@ The following abstract operations support the implementation of the id="writable-stream-default-controller-get-chunk-size">WritableStreamDefaultControllerGetChunkSize(|controller|, |chunk|) 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=]. diff --git a/reference-implementation/lib/abstract-ops/writable-streams.js b/reference-implementation/lib/abstract-ops/writable-streams.js index cf303bfe7..02b2ee7b1 100644 --- a/reference-implementation/lib/abstract-ops/writable-streams.js +++ b/reference-implementation/lib/abstract-ops/writable-streams.js @@ -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) {