Skip to content
Draft
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
6 changes: 6 additions & 0 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,12 @@ function createReadableStreamState() {
}

function readableStreamFromIterable(iterable) {
// Web IDL async_sequence conversion only accepts ECMAScript objects.
// In particular, strings must not be treated as iterable inputs here.
if ((typeof iterable !== 'object' || iterable === null) &&
typeof iterable !== 'function') {
throw new ERR_ARG_NOT_ITERABLE(iterable);
}
let stream;
const iteratorGetter = iterable[SymbolAsyncIterator] ?? iterable[SymbolIterator];
if (iteratorGetter == null || typeof iteratorGetter !== 'function') {
Expand Down
6 changes: 1 addition & 5 deletions test/fixtures/wpt/streams/readable-streams/from.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ const iterableFactories = [
return ['a', 'b'][Symbol.iterator]();
}],

['a string', () => {
// This iterates over the code points of the string.
return 'ab';
}],

['a Set', () => {
return new Set(['a', 'b']);
}],
Expand Down Expand Up @@ -144,6 +139,7 @@ const badIterables = [
['Object.create(null)', Object.create(null)],
['a function', () => 42],
['a symbol', Symbol()],
['a string', 'ab'],
['an object with a non-callable @@iterator method', {
[Symbol.iterator]: 42
}],
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-webstream-readable-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ assert.throws(
{ code: 'ERR_ARG_NOT_ITERABLE', name: 'TypeError' },
);

assert.throws(
() => ReadableStream.from('abc'),
{ code: 'ERR_ARG_NOT_ITERABLE', name: 'TypeError' },
);

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