@@ -6,7 +6,7 @@ const { promiseResolvedWith, promiseRejectedWith, newPromise, resolvePromise, re
6
6
require ( '../helpers/webidl.js' ) ;
7
7
const { CanTransferArrayBuffer, CopyDataBlockBytes, CreateArrayFromList, IsDetachedBuffer, TransferArrayBuffer } =
8
8
require ( './ecmascript.js' ) ;
9
- const { CloneAsUint8Array, IsNonNegativeNumber } = require ( './miscellaneous.js' ) ;
9
+ const { CloneAsUint8Array, IsNonNegativeNumber, StructuredTransferOrClone } = require ( './miscellaneous.js' ) ;
10
10
const { EnqueueValueWithSize, ResetQueue } = require ( './queue-with-sizes.js' ) ;
11
11
const { AcquireWritableStreamDefaultWriter, IsWritableStreamLocked, WritableStreamAbort,
12
12
WritableStreamDefaultWriterCloseWithErrorPropagation, WritableStreamDefaultWriterRelease,
@@ -89,7 +89,7 @@ function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, hi
89
89
90
90
const controller = ReadableStreamDefaultController . new ( globalThis ) ;
91
91
SetUpReadableStreamDefaultController (
92
- stream , controller , startAlgorithm , pullAlgorithm , cancelAlgorithm , highWaterMark , sizeAlgorithm
92
+ stream , controller , startAlgorithm , pullAlgorithm , cancelAlgorithm , highWaterMark , sizeAlgorithm , false
93
93
) ;
94
94
95
95
return stream ;
@@ -340,7 +340,7 @@ function ReadableStreamTee(stream, cloneForBranch2) {
340
340
if ( ReadableByteStreamController . isImpl ( stream . _controller ) ) {
341
341
return ReadableByteStreamTee ( stream ) ;
342
342
}
343
- return ReadableStreamDefaultTee ( stream , cloneForBranch2 ) ;
343
+ return ReadableStreamDefaultTee ( stream , stream . _controller . isTransferring ? true : cloneForBranch2 ) ;
344
344
}
345
345
346
346
function ReadableStreamDefaultTee ( stream , cloneForBranch2 ) {
@@ -392,10 +392,10 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
392
392
// }
393
393
394
394
if ( canceled1 === false ) {
395
- ReadableStreamDefaultControllerEnqueue ( branch1 . _controller , chunk1 ) ;
395
+ ReadableStreamDefaultControllerEnqueue ( branch1 . _controller , chunk1 , undefined ) ;
396
396
}
397
397
if ( canceled2 === false ) {
398
- ReadableStreamDefaultControllerEnqueue ( branch2 . _controller , chunk2 ) ;
398
+ ReadableStreamDefaultControllerEnqueue ( branch2 . _controller , chunk2 , undefined ) ;
399
399
}
400
400
401
401
reading = false ;
@@ -1074,14 +1074,22 @@ function ReadableStreamDefaultControllerClose(controller) {
1074
1074
}
1075
1075
}
1076
1076
1077
- function ReadableStreamDefaultControllerEnqueue ( controller , chunk ) {
1077
+ function ReadableStreamDefaultControllerEnqueue ( controller , chunk , transfer ) {
1078
1078
if ( ReadableStreamDefaultControllerCanCloseOrEnqueue ( controller ) === false ) {
1079
1079
return ;
1080
1080
}
1081
1081
1082
1082
const stream = controller . _stream ;
1083
1083
1084
1084
if ( IsReadableStreamLocked ( stream ) === true && ReadableStreamGetNumReadRequests ( stream ) > 0 ) {
1085
+ if ( controller . isTransferring ) {
1086
+ try {
1087
+ chunk = StructuredTransferOrClone ( chunk , transfer ) ;
1088
+ } catch ( chunkCloneError ) {
1089
+ ReadableStreamDefaultControllerError ( controller , chunkCloneError ) ;
1090
+ throw chunkCloneError ;
1091
+ }
1092
+ }
1085
1093
ReadableStreamFulfillReadRequest ( stream , chunk , false ) ;
1086
1094
} else {
1087
1095
let chunkSize ;
@@ -1093,7 +1101,7 @@ function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
1093
1101
}
1094
1102
1095
1103
try {
1096
- EnqueueValueWithSize ( controller , chunk , chunkSize ) ;
1104
+ EnqueueValueWithSize ( controller , chunk , chunkSize , transfer ) ;
1097
1105
} catch ( enqueueE ) {
1098
1106
ReadableStreamDefaultControllerError ( controller , enqueueE ) ;
1099
1107
throw enqueueE ;
@@ -1148,7 +1156,7 @@ function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) {
1148
1156
}
1149
1157
1150
1158
function SetUpReadableStreamDefaultController (
1151
- stream , controller , startAlgorithm , pullAlgorithm , cancelAlgorithm , highWaterMark , sizeAlgorithm ) {
1159
+ stream , controller , startAlgorithm , pullAlgorithm , cancelAlgorithm , highWaterMark , sizeAlgorithm , isTransferring ) {
1152
1160
assert ( stream . _controller === undefined ) ;
1153
1161
1154
1162
controller . _stream = stream ;
@@ -1169,6 +1177,8 @@ function SetUpReadableStreamDefaultController(
1169
1177
controller . _pullAlgorithm = pullAlgorithm ;
1170
1178
controller . _cancelAlgorithm = cancelAlgorithm ;
1171
1179
1180
+ controller . isTransferring = isTransferring ;
1181
+
1172
1182
stream . _controller = controller ;
1173
1183
1174
1184
const startResult = startAlgorithm ( ) ;
@@ -1195,7 +1205,7 @@ function SetUpReadableStreamDefaultControllerFromUnderlyingSource(
1195
1205
let startAlgorithm = ( ) => undefined ;
1196
1206
let pullAlgorithm = ( ) => promiseResolvedWith ( undefined ) ;
1197
1207
let cancelAlgorithm = ( ) => promiseResolvedWith ( undefined ) ;
1198
-
1208
+ const isTransferring = underlyingSourceDict . type === 'transfer' ;
1199
1209
if ( 'start' in underlyingSourceDict ) {
1200
1210
startAlgorithm = ( ) => underlyingSourceDict . start . call ( underlyingSource , controller ) ;
1201
1211
}
@@ -1207,8 +1217,8 @@ function SetUpReadableStreamDefaultControllerFromUnderlyingSource(
1207
1217
}
1208
1218
1209
1219
SetUpReadableStreamDefaultController (
1210
- stream , controller , startAlgorithm , pullAlgorithm , cancelAlgorithm , highWaterMark , sizeAlgorithm
1211
- ) ;
1220
+ stream , controller , startAlgorithm , pullAlgorithm , cancelAlgorithm , highWaterMark , sizeAlgorithm ,
1221
+ isTransferring ) ;
1212
1222
}
1213
1223
1214
1224
// Byte stream controllers
0 commit comments