Repository navigation
AsyncContext proposal integration - #13063
nicolo-ribaudo wants to merge 20 commits into
Conversation
This PR updates HTML to integrate with 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 PR does not yet handle events, since the exact behavior of those with AsyncContext is still pending to be fully decided. But it covers microtasks, timers, deferred script execution, focus/blur and others. This patch does not include any changes to the `error` and `unhandledrejection` event handling, as well as to `HostEnqueueFinalizationRegistryCleanupJob`. This relies on the assumption that the changes in tc39/proposal-async-context#148 and tc39/proposal-async-context#150 will be accepted. Otherwise, error contexts will need to be handled in HTML. This patch relies on PR [TODO] to define the `[PropagatesAsyncContext]` extended attribute in WebIDL.
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
The mapping captured when the container navigates is threaded through navigate and attempt to populate the history entry's document, stored on the created Document, and consumed by completely finish loading a document to fire the load event on the container. Navigations initiated inside the frame reach navigate without the argument, so their load events do not inherit the embedder's context. The frame element is covered transitively, since navigate an iframe or frame is shared. Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
The details, dialog and popover elements all queue their toggle event through a toggle task tracker. The various algorithms to queue firing those events (which are always run synchronously with the mutation) capture the context and use it to actually fire the event. Closing a dialog captures once and uses the same mapping for both the toggle event and the close event. beforetoggle and cancel are fired synchronously and so are already transparent to AsyncContext.
|
I updated the PR (and PR description) to also cover custom element reactions. That was the last big piece missing. |
|
I run the DetailsReview —
|
| # | Issue | Fix at |
|---|---|---|
| E1 | run (#async-context-mapping-run): the <li> holding the nested <ol> ("Let returnValue be…") has no </li> |
source:5408-5416 |
| E2 | Form-restore autocomplete step starts lowercase: "<li><p><span>enqueue a custom element callback reaction" |
source:80657 |
| E3 | "an user agent decision" → "a user agent decision" | source:80650 |
| E4 | Bad wraps: "media loading⏎Async⏎Context Mapping" in the resource fetch algorithm; "Async Context⏎Mapping⏎« »" for the autoplay pause |
source:39948-39950, :40834-40836 |
| E5 | Stray extra blank line added after "Assert: handler is a string." (timer initialization steps, from 33f8f03b) |
source:131518 |
| E6 | Default fetch and process the linked resource: the touched "Process the linked resource … and acMapping." step still lacks </p> |
source:17198 |
| E7 | The embed element setup steps preamble: "…element given Async Context Mapping acMapping are" is missing an article and repeats "given". Use "…for an embed element element and an Async Context Mapping acMapping are as follows:" |
source:36557-36558 |
| E8 | Queue a dialog/popover toggle event task: "…and the source attribute initialized to source, and with acMapping" has two "and"s. Use "…initialized to source, with acMapping" |
source:67597, :93432 |
| E9 | Map iteration uses ->; Infra uses → (notify about rejected promises) |
source:121208 |
| E10 | HostPromiseRejectionTracker: "map … <span data-x="map exists">contains</span> promise" — link text doesn't match Infra. Use "…map[promise] exists" |
source:122850-122851 |
| E11 | Redundant data-x="clear AsyncContext for events" where the text already matches (Wattsi matches case-insensitively and collapses whitespace) |
source:137782, :137795, :138461, :138486, :138496, and the three EventSource sites from 134809 on |
| E12 | [JSASYNCCONTEXT] sits between [JSERRORSTACKACCESSOR] and [JSERRORSTACKS]; [PropagatesAsyncContext] sits between [Global] and [LegacyFactoryFunction] in an alphabetical run |
source:163277, :2969 |
5. Commits and tests
33f8f03b's message is stale against this branch. It says the patch "does not include any
changes to theerrorandunhandledrejectionevent handling" (03920812/f88a6c2anow do).
It also says it "relies on PR [TODO] to define the[PropagatesAsyncContext]extended
attribute", which should name Add an extended attribute to allow propagating TC39's AsyncContext webidl#1568. If the commits are squashed on merge this
doesn't matter; otherwise trim the body.- No commit misuses
Editorial:. All 20 are normative and none is prefixed. - WPT: web-platform-tests has no AsyncContext tests yet (checked at
a91f536d), so there's nothing to
audit against the diff. The core commits (33f8f03b/ccf42e82/ea34c8a4) will need:setTimeout/setInterval(string and function handlers, and repeat reuse)queueMicrotask,requestAnimationFrame,toBlob,getAsString(all blocked on §1.2)<script src>andtype=moduleload/error- the microtask checkpoint's « » reset (a microtask queued from a classic script must not
inherit the script's mapping) - cross-origin
focus/blur/change
6. Checked and fine — don't "fix" these
- Apparent duplicate declarations that aren't. These are all separate algorithms, separate task
closures, or the same value in exclusive branches:stepsin rundocument/acMappingin completely finish loading (acMapping is used atsource:115021
and:115027)globalin notify about rejected promisesloadingAcMapping/playbackAcMappingin the resource fetch algorithm and ready states
- Timers. The snapshot is taken before the task is created. Abort these steps inside the run
wrapper scopes correctly, andsetIntervalre-captures inside the wrapper, so repeats keep the
original mapping. That's what
WI "Schedulers"
asks for. - Microtask checkpoint. The « » wrapper and its note are needed: clean up after running
script reaches the checkpoint inside execute the script element's mapping. Moving notify about
rejected promises inside the wrapper is harmless, because it only queues a task. - Event loop invariant. The
Assertplus the note at Perform oldestTask's steps state that
every task starts in « », which is what the "events run in the empty context unless otherwise
specified" rule in
EV §8.1
relies on. - iframe
container load Async Context Mapping. It's set for both fetch andjavascript:
documents, read and cleared in completely finish loading, and cleared in abort a document
load. Self-navigations pass null, so they fire in « ». - Media
abort/emptiedin the load algorithm. These deliberately use the new load's
mapping, and a note says so. The internal pause steps' split (timeupdatewith the playback
mapping,pausewith the caller's) is deliberate too. - Unchanged on purpose:
<source>error,AudioTrackList/VideoTrackList/TextTrackList
events, andcuechange.
EV "Events fired on other objects"
says they run in the empty context, which is what the unchanged text already does. - Custom element reactions. A snapshot per reaction, with upgrades running in the enqueuer's
context, matches
CE "Propagation model"
and
CE "Constructors and upgrades",
including the.click()-on-summarycase that lands on the backup element queue.
Ref #10432
This PR integrates the AsyncContext proposal into HTML APIs. This PR includes:
It follows the design decisions discussed at past WHATNOT meetings, and written down in https://github.com/tc39/proposal-async-context/blob/master/WEB-INTEGRATION.md / https://github.com/tc39/proposal-async-context/blob/master/web-integration/html__events.md
For custom element reactions it follows what's currently described in detail at https://github.com/tc39/proposal-async-context/blob/main/web-integration/html__custom-elements.md. That's a new document, but it's the behavior we get by applying the two bullet points we had in
WEB-INTEGRATION.mdabout custom elements.I am maintaining a
gh stackparallel to this PR with the same changes at https://github.com/nicolo-ribaudo/html/pulls?q=sort%3Acreated-desc%20is%3Apr%20label%3A%22async%20context%22: it was originally there to help myself with tracking the status of what I was doing, but I believe it can also be useful for reviewers to see more detailed context behind why some changes are the way they are (each of those PRs has a semi-detailed list of decisions and things to test in WPT).There currently are some open questions:
[PropagatesAsyncContextToEvents]extended attribute defined in AsyncContext propagation to events dom#1451 or not, as at least for HTML the benefits are not super clear. PRs in the stack that use it are at https://github.com/nicolo-ribaudo/html/issues?q=sort%3Acreated-desc%20label%3A%22uses%20PropagatesAsyncContextToEvents%22.<img>and media element algorithms with regards to the exact timing that something happens.EventSourceconstructor alive for as long as that connection is open / being reopened (Propagate AsyncContext for EventSource events nicolo-ribaudo/html#11)Corresponding PRs in other specs that need to land at the same time (they cyclically depend on each other) are whatwg/webidl#1568 and whatwg/dom#1451.
I also have a pending WebIDL PR to open to capture the context for rejection in WebIDL-managed promises, so that theUPDATE: we might make the change in the ECMAScript proposal instead.Expose Async Context Mappings on promise rejection eventscommit works for them as well as it does for JS-created ones.(See WHATWG Working Mode: Changes for more details.)
/browsing-the-web.html ( diff )
/canvas.html ( diff )
/custom-elements.html ( diff )
/dnd.html ( diff )
/document-lifecycle.html ( diff )
/dom.html ( diff )
/iframe-embed-object.html ( diff )
/imagebitmap-and-animations.html ( diff )
/images.html ( diff )
/index.html ( diff )
/infrastructure.html ( diff )
/input.html ( diff )
/interaction.html ( diff )
/interactive-elements.html ( diff )
/links.html ( diff )
/media.html ( diff )
/obsolete.html ( diff )
/popover.html ( diff )
/references.html ( diff )
/scripting.html ( diff )
/semantics.html ( diff )
/server-sent-events.html ( diff )
/timers-and-user-prompts.html ( diff )
/webappapis.html ( diff )
/workers.html ( diff )