summaryrefslogtreecommitdiff
path: root/ext/web/06_streams.js
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2023-08-15 09:21:02 +0200
committerGitHub <noreply@github.com>2023-08-15 09:21:02 +0200
commit0fc31d9d657b4ccf24099803d5321182f08f710c (patch)
treeebe525efbe1d33b6daa3a9e8be95ebb53600a4a1 /ext/web/06_streams.js
parent119526a7a5fef24783e5a7a5f4fb05038b410c88 (diff)
fix(ext/fetch): clone second branch chunks in Body.clone() (#20057)
This PR makes `Body.clone()` spec compliant: https://fetch.spec.whatwg.org/#concept-body-clone > 1, Let « out1, out2 » be the result of [teeing](https://streams.spec.whatwg.org/#readablestream-tee) body’s [stream](https://fetch.spec.whatwg.org/#concept-body-stream). > ... > To tee a [ReadableStream](https://streams.spec.whatwg.org/#readablestream) stream, return ? [ReadableStreamTee](https://streams.spec.whatwg.org/#readable-stream-tee)(stream, true). --- Closes #10994
Diffstat (limited to 'ext/web/06_streams.js')
-rw-r--r--ext/web/06_streams.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js
index beab2ec12..01f84aa2c 100644
--- a/ext/web/06_streams.js
+++ b/ext/web/06_streams.js
@@ -9,6 +9,7 @@
const core = globalThis.Deno.core;
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
+import { structuredClone } from "ext:deno_web/02_structured_clone.js";
import {
AbortSignalPrototype,
add,
@@ -2847,9 +2848,24 @@ function readableStreamDefaultTee(stream, cloneForBranch2) {
queueMicrotask(() => {
readAgain = false;
const value1 = value;
- const value2 = value;
+ let value2 = value;
- // TODO(lucacasonato): respect clonedForBranch2.
+ if (canceled2 === false && cloneForBranch2 === true) {
+ try {
+ value2 = structuredClone(value2);
+ } catch (cloneError) {
+ readableStreamDefaultControllerError(
+ branch1[_controller],
+ cloneError,
+ );
+ readableStreamDefaultControllerError(
+ branch2[_controller],
+ cloneError,
+ );
+ cancelPromise.resolve(readableStreamCancel(stream, cloneError));
+ return;
+ }
+ }
if (canceled1 === false) {
readableStreamDefaultControllerEnqueue(
@@ -6464,6 +6480,7 @@ export {
readableStreamForRidUnrefableRef,
readableStreamForRidUnrefableUnref,
ReadableStreamPrototype,
+ readableStreamTee,
readableStreamThrowIfErrored,
TransformStream,
TransformStreamDefaultController,