Skip to content

Commit 1fd170a

Browse files
authored
stream: throw TypeError when criteria fulfilled in getIterator
PR-URL: #53825 Fixes: #53819 Refs: #53819 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Debadree Chatterjee <[email protected]>
1 parent 7941b4b commit 1fd170a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/internal/webstreams/util.js

+10
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_INVALID_STATE,
2324
ERR_OPERATION_FAILED,
@@ -235,6 +236,11 @@ function getIterator(obj, kind = 'sync', method) {
235236
method = obj[SymbolAsyncIterator];
236237
if (method === undefined) {
237238
const syncMethod = obj[SymbolIterator];
239+
240+
if (syncMethod === undefined) {
241+
throw new ERR_ARG_NOT_ITERABLE(obj);
242+
}
243+
238244
const syncIteratorRecord = getIterator(obj, 'sync', syncMethod);
239245
return createAsyncFromSyncIterator(syncIteratorRecord);
240246
}
@@ -243,6 +249,10 @@ function getIterator(obj, kind = 'sync', method) {
243249
}
244250
}
245251

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

0 commit comments

Comments
 (0)