Skip to content

Add io module for streams with handling streams in the associated document's realm#1135

Open
lutien wants to merge 4 commits into
w3c:mainfrom
lutien:streams-in-document-realm
Open

Add io module for streams with handling streams in the associated document's realm#1135
lutien wants to merge 4 commits into
w3c:mainfrom
lutien:streams-in-document-realm

Conversation

@lutien

@lutien lutien commented Jul 14, 2026

Copy link
Copy Markdown
Member

An alternative approach to #1061 to handle streams in the associated document's realm + adding the serialization of ReadableStreams as RemoteValue to demonstrate how the whole flow would look.


Preview | Diff

jgraham and others added 3 commits July 13, 2026 14:58
This adds the initial primitives for working with readable streams,
although they are not yet connected up to any other parts of the
specification.
@lutien
lutien requested a review from jgraham July 14, 2026 14:49
Comment thread index.bs Outdated

<dfn>Stream settings</dfn> is a [=struct=] with
an [=struct/item=] named <dfn for="stream settings">stream</dfn>, which is a [=readable stream=],
an [=struct/item=] named <dfn for="stream settings">navigable</dfn>, which is a <code>browsingContext.BrowsingContext</code> or null.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a navigable or directly be a realm (e.g. so that we support streams coming from workers)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking about it too. Ok, I've updated the PR to use a realm.

Comment thread index.bs
A <dfn lt="stream|IO stream" export>stream</dfn> is an abstract source of
data that can be read from or written to.

A [=BiDi Session=] has a <dfn>readable stream settings map</dfn> which is a [=/map=] between

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written this would seem to possibly keep navigables (or realms) alive as long as there's a reference to one of their streams. That feels likely to cause memory leaks.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've added the cleanup steps when the realms are gone.

Comment thread index.bs Outdated

1. If |promise| was rejected, then:

1. [=Clean up after running script=] with |environment settings|.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be outside the reaction; if the promise isn't already fulfilled the steps end up being called in a future microtask checkpoint when we're no longer top of the execution stack.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I moved it up.

Comment thread index.bs Outdated

1. [=Prepare to run script=] with |environment settings|.

1. Let |reader| be the result of [=ReadableStream/getting a reader=] for |stream|.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can fail, we need to handle the failure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added trying, is it enough, or do you want to send some specific error if it fails?

Comment thread index.bs Outdated

1. Let |reader| be the result of [=ReadableStream/getting a reader=] for |stream|.

1. Let |read result| be the result of calling {{ReadableStreamDefaultReader/read()}} for |reader|.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to use https://streams.spec.whatwg.org/#readablestreamdefaultreader-read-a-chunk instead, which then affects the logic for the rest of this section.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, alright, I've updated it.

Comment thread index.bs Outdated
Comment thread index.bs
property set to |handle id| if it's not null, or omitted otherwise, and
the <code>value</code> property set to |serialized|.

<dt>|value| is a [=platform object=] that implements {{ReadableStream}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we also want to support the case where you try to return a reader to the stream rather than the stream itself.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yeah, I'm not sure either. I guess that's a good question for the spec meeting. Let's keep it open for now.

@lutien
lutien force-pushed the streams-in-document-realm branch from bed18e3 to 743f6dc Compare July 17, 2026 09:24
@lutien
lutien requested a review from jgraham July 17, 2026 09:30
@lutien
lutien marked this pull request as ready for review July 17, 2026 09:52
@lutien

lutien commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Hey, @MattiasBuelens, I've picked up the work on the streaming API from James. So when you have time, could you also review from your side?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants