mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
stream: throw TypeError when criteria fulfilled in getIterator
PR-URL: https://github.com/nodejs/node/pull/53825 Fixes: https://github.com/nodejs/node/issues/53819 Refs: https://github.com/nodejs/node/issues/53819 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
This commit is contained in:
parent
7941b4b333
commit
1fd170a7fc
@ -18,6 +18,7 @@ const {
|
||||
|
||||
const {
|
||||
codes: {
|
||||
ERR_ARG_NOT_ITERABLE,
|
||||
ERR_INVALID_ARG_VALUE,
|
||||
ERR_INVALID_STATE,
|
||||
ERR_OPERATION_FAILED,
|
||||
@ -235,6 +236,11 @@ function getIterator(obj, kind = 'sync', method) {
|
||||
method = obj[SymbolAsyncIterator];
|
||||
if (method === undefined) {
|
||||
const syncMethod = obj[SymbolIterator];
|
||||
|
||||
if (syncMethod === undefined) {
|
||||
throw new ERR_ARG_NOT_ITERABLE(obj);
|
||||
}
|
||||
|
||||
const syncIteratorRecord = getIterator(obj, 'sync', syncMethod);
|
||||
return createAsyncFromSyncIterator(syncIteratorRecord);
|
||||
}
|
||||
@ -243,6 +249,10 @@ function getIterator(obj, kind = 'sync', method) {
|
||||
}
|
||||
}
|
||||
|
||||
if (method === undefined) {
|
||||
throw new ERR_ARG_NOT_ITERABLE(obj);
|
||||
}
|
||||
|
||||
const iterator = FunctionPrototypeCall(method, obj);
|
||||
if (typeof iterator !== 'object' || iterator === null) {
|
||||
throw new ERR_INVALID_STATE.TypeError('The iterator method must return an object');
|
||||
|
9
test/parallel/test-webstream-readable-from.js
Normal file
9
test/parallel/test-webstream-readable-from.js
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('node:assert');
|
||||
|
||||
assert.throws(
|
||||
() => ReadableStream.from({}),
|
||||
{ code: 'ERR_ARG_NOT_ITERABLE', name: 'TypeError' },
|
||||
);
|
Loading…
Reference in New Issue
Block a user