Skip to content

Commit 713fc0c

Browse files
jakecastellitargos
authored andcommitted
stream: throw TypeError when criteria fulfilled in getIterator
PR-URL: #53825Fixes: #53819 Refs: #53819 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
1 parent 9759049 commit 713fc0c

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎lib/internal/webstreams/util.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818

1919
const{
2020
codes: {
21+
ERR_ARG_NOT_ITERABLE,
2122
ERR_INVALID_ARG_VALUE,
2223
ERR_OPERATION_FAILED,
2324
ERR_INVALID_STATE,
@@ -235,6 +236,11 @@ function getIterator(obj, kind = 'sync', method) {
235236
method=obj[SymbolAsyncIterator];
236237
if(method===undefined){
237238
constsyncMethod=obj[SymbolIterator];
239+
240+
if(syncMethod===undefined){
241+
thrownewERR_ARG_NOT_ITERABLE(obj);
242+
}
243+
238244
constsyncIteratorRecord=getIterator(obj,'sync',syncMethod);
239245
returncreateAsyncFromSyncIterator(syncIteratorRecord);
240246
}
@@ -243,6 +249,10 @@ function getIterator(obj, kind = 'sync', method) {
243249
}
244250
}
245251

252+
if(method===undefined){
253+
thrownewERR_ARG_NOT_ITERABLE(obj);
254+
}
255+
246256
constiterator=FunctionPrototypeCall(method,obj);
247257
if(typeofiterator!=='object'||iterator===null){
248258
thrownewERR_INVALID_STATE.TypeError('The iterator method must return an object');
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
require('../common');
4+
constassert=require('node:assert');
5+
6+
assert.throws(
7+
()=>ReadableStream.from({}),
8+
{code: 'ERR_ARG_NOT_ITERABLE',name: 'TypeError'},
9+
);

0 commit comments

Comments
 (0)