@@ -24,6 +24,7 @@ const {
2424 Symbol,
2525 SymbolAsyncIterator,
2626 SymbolDispose,
27+ SymbolIterator,
2728 SymbolToStringTag,
2829 TypedArrayPrototypeGetLength,
2930 Uint8Array,
@@ -32,6 +33,7 @@ const {
3233const {
3334 AbortError,
3435 codes : {
36+ ERR_ARG_NOT_ITERABLE ,
3537 ERR_ILLEGAL_CONSTRUCTOR ,
3638 ERR_INVALID_ARG_TYPE ,
3739 ERR_INVALID_ARG_VALUE ,
@@ -110,8 +112,6 @@ const {
110112 nonOpCancel,
111113 nonOpPull,
112114 nonOpStart,
113- getIterator,
114- iteratorNext,
115115 kType,
116116 kState,
117117} = require ( 'internal/webstreams/util' ) ;
@@ -1341,41 +1341,36 @@ function createReadableStreamState() {
13411341
13421342function readableStreamFromIterable ( iterable ) {
13431343 let stream ;
1344- const iteratorRecord = getIterator ( iterable , 'async' ) ;
1345-
1344+ const iteratorGetter = iterable [ SymbolAsyncIterator ] ?? iterable [ SymbolIterator ] ;
1345+ if ( iteratorGetter == null || typeof iteratorGetter !== 'function' ) {
1346+ throw new ERR_ARG_NOT_ITERABLE ( iterable ) ;
1347+ }
1348+ const iterator = FunctionPrototypeCall ( iteratorGetter , iterable ) ;
13461349 const startAlgorithm = nonOpStart ;
13471350
13481351 async function pullAlgorithm ( ) {
1349- const nextResult = iteratorNext ( iteratorRecord ) ;
1350- const nextPromise = PromiseResolve ( nextResult ) ;
1351- return PromisePrototypeThen ( nextPromise , ( iterResult ) => {
1352- if ( typeof iterResult !== 'object' || iterResult === null ) {
1353- throw new ERR_INVALID_STATE . TypeError (
1354- 'The promise returned by the iterator.next() method must fulfill with an object' ) ;
1355- }
1356- if ( iterResult . done ) {
1357- readableStreamDefaultControllerClose ( stream [ kState ] . controller ) ;
1358- } else {
1359- readableStreamDefaultControllerEnqueue ( stream [ kState ] . controller , iterResult . value ) ;
1360- }
1361- } ) ;
1352+ const iterResult = await iterator . next ( ) ;
1353+ if ( typeof iterResult !== 'object' || iterResult === null ) {
1354+ throw new ERR_INVALID_STATE . TypeError (
1355+ 'The promise returned by the iterator.next() method must fulfill with an object' ) ;
1356+ }
1357+ if ( iterResult . done ) {
1358+ readableStreamDefaultControllerClose ( stream [ kState ] . controller ) ;
1359+ } else {
1360+ readableStreamDefaultControllerEnqueue ( stream [ kState ] . controller , await iterResult . value ) ;
1361+ }
13621362 }
13631363
13641364 async function cancelAlgorithm ( reason ) {
1365- const iterator = iteratorRecord . iterator ;
13661365 const returnMethod = iterator . return ;
13671366 if ( returnMethod === undefined ) {
1368- return PromiseResolve ( ) ;
1367+ return ;
1368+ }
1369+ const iterResult = await FunctionPrototypeCall ( returnMethod , iterator , reason ) ;
1370+ if ( typeof iterResult !== 'object' || iterResult === null ) {
1371+ throw new ERR_INVALID_STATE . TypeError (
1372+ 'The promise returned by the iterator.return() method must fulfill with an object' ) ;
13691373 }
1370- const returnResult = FunctionPrototypeCall ( returnMethod , iterator , reason ) ;
1371- const returnPromise = PromiseResolve ( returnResult ) ;
1372- return PromisePrototypeThen ( returnPromise , ( iterResult ) => {
1373- if ( typeof iterResult !== 'object' || iterResult === null ) {
1374- throw new ERR_INVALID_STATE . TypeError (
1375- 'The promise returned by the iterator.return() method must fulfill with an object' ) ;
1376- }
1377- return undefined ;
1378- } ) ;
13791374 }
13801375
13811376 stream = createReadableStream (
0 commit comments