@@ -263,11 +263,11 @@ function* normalizeSyncSource(source) {
263263 * and protocol conversions.
264264 * @yields {Uint8Array}
265265 */
266- async function * normalizeAsyncValue ( value ) {
266+ async function * normalizeAsyncValue ( value , allowNestedAsyncStreamables = true ) {
267267 // Handle promises first
268268 if ( isPromise ( value ) ) {
269269 const resolved = await value ;
270- yield * normalizeAsyncValue ( resolved ) ;
270+ yield * normalizeAsyncValue ( resolved , allowNestedAsyncStreamables ) ;
271271 return ;
272272 }
273273
@@ -277,28 +277,37 @@ async function* normalizeAsyncValue(value) {
277277 return ;
278278 }
279279
280+ if ( ! allowNestedAsyncStreamables &&
281+ ( isAsyncIterable ( value ) || hasProtocol ( value , toAsyncStreamable ) ) ) {
282+ throw new ERR_INVALID_ARG_TYPE (
283+ 'value' ,
284+ [ 'string' , 'ArrayBuffer' , 'ArrayBufferView' , 'Iterable' , 'toStreamable' ] ,
285+ value ,
286+ ) ;
287+ }
288+
280289 // Handle ToAsyncStreamable protocol (check before ToStreamable)
281290 if ( hasProtocol ( value , toAsyncStreamable ) ) {
282291 const result = FunctionPrototypeCall ( value [ toAsyncStreamable ] , value ) ;
283292 if ( isPromise ( result ) ) {
284- yield * normalizeAsyncValue ( await result ) ;
293+ yield * normalizeAsyncValue ( await result , allowNestedAsyncStreamables ) ;
285294 } else {
286- yield * normalizeAsyncValue ( result ) ;
295+ yield * normalizeAsyncValue ( result , allowNestedAsyncStreamables ) ;
287296 }
288297 return ;
289298 }
290299
291300 // Handle ToStreamable protocol
292301 if ( hasProtocol ( value , toStreamable ) ) {
293302 const result = FunctionPrototypeCall ( value [ toStreamable ] , value ) ;
294- yield * normalizeAsyncValue ( result ) ;
303+ yield * normalizeAsyncValue ( result , allowNestedAsyncStreamables ) ;
295304 return ;
296305 }
297306
298307 // Handle arrays (which are also iterable, but check first for efficiency)
299308 if ( ArrayIsArray ( value ) ) {
300309 for ( let i = 0 ; i < value . length ; i ++ ) {
301- yield * normalizeAsyncValue ( value [ i ] ) ;
310+ yield * normalizeAsyncValue ( value [ i ] , allowNestedAsyncStreamables ) ;
302311 }
303312 return ;
304313 }
@@ -307,15 +316,15 @@ async function* normalizeAsyncValue(value) {
307316 // have both)
308317 if ( isAsyncIterable ( value ) ) {
309318 for await ( const item of value ) {
310- yield * normalizeAsyncValue ( item ) ;
319+ yield * normalizeAsyncValue ( item , allowNestedAsyncStreamables ) ;
311320 }
312321 return ;
313322 }
314323
315324 // Handle sync iterables
316325 if ( isSyncIterable ( value ) ) {
317326 for ( const item of value ) {
318- yield * normalizeAsyncValue ( item ) ;
327+ yield * normalizeAsyncValue ( item , allowNestedAsyncStreamables ) ;
319328 }
320329 return ;
321330 }
@@ -392,7 +401,7 @@ async function* normalizeAsyncSource(source) {
392401 batch = [ ] ;
393402 }
394403 let asyncBatch = [ ] ;
395- for await ( const chunk of normalizeAsyncValue ( value ) ) {
404+ for await ( const chunk of normalizeAsyncValue ( value , false ) ) {
396405 ArrayPrototypePush ( asyncBatch , chunk ) ;
397406 if ( asyncBatch . length === FROM_BATCH_SIZE ) {
398407 yield asyncBatch ;
0 commit comments