summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/fetch/22_body.js3
-rw-r--r--ext/web/06_streams.js21
2 files changed, 21 insertions, 3 deletions
diff --git a/ext/fetch/22_body.js b/ext/fetch/22_body.js
index 9fe00b144..644b9f76f 100644
--- a/ext/fetch/22_body.js
+++ b/ext/fetch/22_body.js
@@ -33,6 +33,7 @@ import {
readableStreamCollectIntoUint8Array,
readableStreamDisturb,
ReadableStreamPrototype,
+ readableStreamTee,
readableStreamThrowIfErrored,
} from "ext:deno_web/06_streams.js";
const primordials = globalThis.__bootstrap.primordials;
@@ -194,7 +195,7 @@ class InnerBody {
* @returns {InnerBody}
*/
clone() {
- const { 0: out1, 1: out2 } = this.stream.tee();
+ const { 0: out1, 1: out2 } = readableStreamTee(this.stream, true);
this.streamOrStatic = out1;
const second = new InnerBody(out2);
second.source = core.deserialize(core.serialize(this.source));
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,