Skip to content

stream: reject strings in ReadableStream.from#64465

Draft
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:readable-stream-from-reject-strings
Draft

stream: reject strings in ReadableStream.from#64465
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:readable-stream-from-reject-strings

Conversation

@trivikr

@trivikr trivikr commented Jul 13, 2026

Copy link
Copy Markdown
Member

Refs: #64288
Depends on: web-platform-tests/wpt#59594

Use Web IDL async_sequence<any> semantics for ReadableStream.from().

This changes ReadableStream.from('abc') to throw a TypeError instead
of iterating over the string's Unicode code points. Web IDL async
sequences require the input value to be an ECMAScript object.

The corresponding WPT change is included provisionally. This PR should
not land until the upstream WPT PR is merged. Afterward, the Streams WPT
fixtures will be regenerated with git node wpt streams.


Assisted-by: openai:gpt-5.6-sol

Use Web IDL async_sequence semantics for ReadableStream.from(), which
require the input to be an object. This causes primitive strings to
throw a TypeError instead of being iterated by code point.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.6-sol
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/web-standards

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. web streams labels Jul 13, 2026
@jasnell

jasnell commented Jul 13, 2026

Copy link
Copy Markdown
Member

I'd rather go a different way with this... while it is not strictly spec compliant, ReadableStream.from(syncIterable) and ReadableStream.from('str') is actually useful for users. I plan on opening a new proposal for the streams spec to allow for it. Specifically, however, ReadableStream.from(str) would handle str as a single chunk (yielding the whole str), not iterating over the codepoints.

@MattiasBuelens

Copy link
Copy Markdown
Contributor

Tests have been merged in web-platform-tests/wpt@99d74f9, so you can do a proper git node wpt now. 😉

I plan on opening a new proposal for the streams spec to allow for it. Specifically, however, ReadableStream.from(str) would handle str as a single chunk (yielding the whole str), not iterating over the codepoints.

@jasnell Sure, we can discuss. For reference, the original decision for throwing on ReadableStream.from(str) was made in whatwg/streams#1310 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants