Repository navigation
feat(runtime): AbortController, AbortSignal, EventTarget and DOMException - #42
Merged
Merged
Conversation
…tion Adds DOMException, Event, CustomEvent, EventTarget, AbortSignal (with abort, timeout and any, onabort, throwIfAborted) and AbortController as globals on every engine; each is installed only when the global is missing. Nothing provided them before, so `new AbortController()` threw a ReferenceError and cancellation APIs had to take duck-typed signals. addEventListener supports once, capture, passive and signal. A timeout signal is held weakly by its timer, and composites from any() stay reachable only while something listens for their abort.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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.
Nothing provided these globals, so
new AbortController()threw aReferenceError, and APIs that take anAbortSignalhad to accept duck-typed objects.Changes
New
runtime/src/js/events.jsinstallsDOMException,Event,CustomEvent,EventTarget,AbortSignalandAbortController. It runs on both engines, next tocrypto.js, and installs each global only when it's missing.EventTarget:addEventListeneroptionsonce,capture,passiveandsignal;handleEventobjects; duplicate registrations ignored;stopImmediatePropagation;preventDefaulton cancelable events. A throwing listener is reported asynchronously and doesn't stop the others.AbortSignal:aborted,reason,onabort,throwIfAborted(), plus the staticabort(),timeout(ms)andany(signals).DOMExceptions (AbortError,TimeoutError).any()flattens composites, and every affected signal is aborted before the firstabortevent fires.timeout()signal is held weakly by its timer, with aFinalizationRegistrycancelling the timer. Composites and timeout signals are kept alive only while something listens for their abort.DOMException:name/message/code, the legacy code constants,instanceof Error.It's written with plain functions and WeakMap state (no classes or private fields), so Hermes and QuickJS can run it.
Testing
The same 26-check script ran on every engine below. On Node, it first deletes Node's own globals, so it checks this implementation, and it also passes against Node's native ones.
timeout()isn't firedtimeout()firing