Make AbortSignal.any spec-compliant with a multi-pass implementation#57381
Open
rubennorte wants to merge 1 commit into
Open
Make AbortSignal.any spec-compliant with a multi-pass implementation#57381rubennorte wants to merge 1 commit into
rubennorte wants to merge 1 commit into
Conversation
Summary: `AbortSignal.any` previously processed the input signals in a single pass, attaching an abort listener to each signal as it iterated and unwinding them with a `cleanup()` call whenever it later encountered an already-aborted (or invalid) signal. This deviates from the specification, which validates the whole list, then scans it for an already-aborted signal (returning an aborted signal immediately), and only then subscribes to the remaining signals. Process the list in three passes instead: - The first pass validates that every entry is an `AbortSignal`, throwing before any other work so an invalid entry never short-circuits ahead of an earlier already-aborted one. - The second pass returns an already-aborted signal (via `AbortSignal.abort(reason)`) if any input is already aborted. No listeners are registered yet, so there is nothing to unwind on an early return. - The third pass subscribes to every signal, since all of them are valid and none is aborted at that point. This removes the need to clean up partially-registered listeners mid-setup and matches the behavior described in the DOM specification. Also remove a dead branch in `AbortController`'s `getSignal` helper. The `controller === null ? 'null' : typeof controller` expression was unreachable for `null` input because the preceding `controller[SIGNAL_KEY]` access already throws a `TypeError` on `null`/`undefined`, and it only existed by suppressing a Flow `invalid-compare` error. Use `typeof controller` directly so the suppression is no longer needed. Changelog: [General][Fixed] - Make `AbortSignal.any()` process its input signals in multiple passes to match the DOM specification Differential Revision: D110185361
|
@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110185361. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
AbortSignal.anypreviously processed the input signals in a single pass, attaching an abort listener to each signal as it iterated and unwinding them with acleanup()call whenever it later encountered an already-aborted (or invalid) signal. This deviates from the specification, which validates the whole list, then scans it for an already-aborted signal (returning an aborted signal immediately), and only then subscribes to the remaining signals.Process the list in three passes instead:
AbortSignal, throwing before any other work so an invalid entry never short-circuits ahead of an earlier already-aborted one.AbortSignal.abort(reason)) if any input is already aborted. No listeners are registered yet, so there is nothing to unwind on an early return.This removes the need to clean up partially-registered listeners mid-setup and matches the behavior described in the DOM specification.
Also remove a dead branch in
AbortController'sgetSignalhelper. Thecontroller === null ? 'null' : typeof controllerexpression was unreachable fornullinput because the precedingcontroller[SIGNAL_KEY]access already throws aTypeErroronnull/undefined, and it only existed by suppressing a Flowinvalid-compareerror. Usetypeof controllerdirectly so the suppression is no longer needed.Changelog:
[General][Fixed] - Make
AbortSignal.any()process its input signals in multiple passes to match the DOM specificationDifferential Revision: D110185361