Skip to content

Add an extended attribute to allow propagating TC39's AsyncContext#1568

Open
andreubotella wants to merge 4 commits intowhatwg:mainfrom
andreubotella:propagates-async-context
Open

Add an extended attribute to allow propagating TC39's AsyncContext#1568
andreubotella wants to merge 4 commits intowhatwg:mainfrom
andreubotella:propagates-async-context

Conversation

@andreubotella
Copy link
Member

@andreubotella andreubotella commented Feb 11, 2026

This PR updates WebIDL to add the [PropagatesAsyncContext] extended attribute. This is a part of the TC39 AsyncContext proposal, which allows storing state associated with an async flow of execution in JavaScript, and preserving it across different kinds of async continuations in both JS and the web platform.

This [PropagatesAsyncContext] extended attribute can only be applied to callback function types in operation arguments. When set, the callback context will also store an Async Context Mapping, which the callback will run in.

This allows a callback-taking operation to act like an async continuation, and propagate the state associated with the async flow of execution at the time that this operation is called to the callback.

This patch relies on HTML's PR whatwg/html#12152 to define the "run with Async Context Mapping" operation. This operation must be defined in a web specs rather than in the TC39 proposal because it deals with throwing in spec algorithms, which is not a concept in the TC39 specs.

This PR is part of whatwg/html#10432.

  • At least two implementers are interested (and none opposed):
    • Chromium
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno: …
    • Node.js: …
    • webidl2.js: …
    • widlparser: …
  • MDN issue is filed: …
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)

This PR updates WebIDL to add the `[PropagatesAsyncContext]` extended
attribute. This is a part of the TC39 AsyncContext proposal, which
allows storing state associated with an async flow of execution in
JavaScript, and preserving it across different kinds of async
continuations in both JS and the web platform.

This `[PropagatesAsyncContext]` extended attribute can only be applied
to callback function types in operation arguments. When set, the
callback context will also store an Async Context Mapping, which the
callback will run in.

This allows a callback-taking operation to act like an async
continuation, and propagate the state associated with the async flow
of execution at the time that this operation is called to the
callback.

This patch relies on HTML's PR whatwg/html#12152 to define the "run
with Async Context Mapping" operation. This operation must be defined
in a web specs rather than in the TC39 proposal because it deals with
throwing in spec algorithms, which is not a concept in the TC39 specs.
@jasnell
Copy link

jasnell commented Feb 12, 2026

Spec text looks reasonable to me. Not a browser but from the perspective of both Node.js and Cloudflare Workers, consider this a +1.

@andreubotella
Copy link
Member Author

Let's try closing and reopening the PR, to see if this gets the spec preview working.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants