Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,9 @@ function readableStreamFromIterable(iterable) {
throw new ERR_ARG_NOT_ITERABLE(iterable);
}
const iterator = FunctionPrototypeCall(iteratorGetter, iterable);
if (iterator === null || (typeof iterator !== 'object' && typeof iterator !== 'function')) {
throw new ERR_INVALID_STATE.TypeError('The iterator method must return an object');
}
const startAlgorithm = nonOpStart;

async function pullAlgorithm() {
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-webstream-readable-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,22 @@ assert.throws(
() => ReadableStream.from({}),
{ code: 'ERR_ARG_NOT_ITERABLE', name: 'TypeError' },
);

const invalidIterators = [
{ [Symbol.iterator]: () => 42 },
{ [Symbol.asyncIterator]: () => 42 },
];

for (const iterable of invalidIterators) {
assert.throws(
() => ReadableStream.from(iterable),
{ code: 'ERR_INVALID_STATE', name: 'TypeError' },
);
}

function functionIterator() {}

// doesNotThrow
ReadableStream.from({
[Symbol.iterator]: () => functionIterator,
});
9 changes: 0 additions & 9 deletions test/wpt/status/streams.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
"readable-streams/cross-realm-crash.window.js": {
"skip": "Browser-specific test"
},
"readable-streams/from.any.js": {
"fail": {
"note": "does not synchronously validate that the value returned by @@iterator/@@asyncIterator is an object",
"expected": [
"ReadableStream.from throws on invalid iterables; specifically an object with an @@iterator method returning a non-object",
"ReadableStream.from throws on invalid iterables; specifically an object with an @@asyncIterator method returning a non-object"
]
}
},
"readable-streams/owning-type-message-port.any.js": {
"fail": {
"note": "Readable streams with type owning are not yet supported",
Expand Down
Loading