GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: validate ReadableStream.from iterator objects · nodejs/node@c12a767

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/webstreams
    • readablestream.js
  • test
    • parallel
      • test-webstream-readable-from.js
    • wpt/status
      • streams.json
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/webstreams/readablestream.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/readablestream.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,9 @@ function readableStreamFromIterable(iterable) {
13651365
throw new ERR_ARG_NOT_ITERABLE(iterable);
13661366
}
13671367
const iterator = FunctionPrototypeCall(iteratorGetter, iterable);
1368+
if (iterator === null || (typeof iterator !== 'object' && typeof iterator !== 'function')) {
1369+
throw new ERR_INVALID_STATE.TypeError('The iterator method must return an object');
1370+
}
13681371
const startAlgorithm = nonOpStart;
13691372

13701373
async function pullAlgorithm() {
Collapse file

‎test/parallel/test-webstream-readable-from.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-webstream-readable-from.js
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,22 @@ assert.throws(
77
() => ReadableStream.from({}),
88
{ code: 'ERR_ARG_NOT_ITERABLE', name: 'TypeError' },
99
);
10+
11+
const invalidIterators = [
12+
{ [Symbol.iterator]: () => 42 },
13+
{ [Symbol.asyncIterator]: () => 42 },
14+
];
15+
16+
for (const iterable of invalidIterators) {
17+
assert.throws(
18+
() => ReadableStream.from(iterable),
19+
{ code: 'ERR_INVALID_STATE', name: 'TypeError' },
20+
);
21+
}
22+
23+
function functionIterator() {}
24+
25+
// doesNotThrow
26+
ReadableStream.from({
27+
[Symbol.iterator]: () => functionIterator,
28+
});
Collapse file

‎test/wpt/status/streams.json‎

Copy file name to clipboardExpand all lines: test/wpt/status/streams.json
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
"readable-streams/cross-realm-crash.window.js": {
99
"skip": "Browser-specific test"
1010
},
11-
"readable-streams/from.any.js": {
12-
"fail": {
13-
"note": "does not synchronously validate that the value returned by @@iterator/@@asyncIterator is an object",
14-
"expected": [
15-
"ReadableStream.from throws on invalid iterables; specifically an object with an @@iterator method returning a non-object",
16-
"ReadableStream.from throws on invalid iterables; specifically an object with an @@asyncIterator method returning a non-object"
17-
]
18-
}
19-
},
2011
"readable-streams/owning-type-message-port.any.js": {
2112
"fail": {
2213
"note": "Readable streams with type owning are not yet supported",

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.