diff --git a/ext/web/03_abort_signal.js b/ext/web/03_abort_signal.js index 6b278ba0743da7..d46291b1471e78 100644 --- a/ext/web/03_abort_signal.js +++ b/ext/web/03_abort_signal.js @@ -85,6 +85,13 @@ webidl.assertBranded(this, AbortSignal); return this[abortReason]; } + + throwIfAborted() { + webidl.assertBranded(this, AbortSignal); + if (this[abortReason] !== undefined) { + throw this[abortReason]; + } + } } defineEventHandler(AbortSignal.prototype, "abort"); diff --git a/ext/web/lib.deno_web.d.ts b/ext/web/lib.deno_web.d.ts index 3cdc2bea6dc1ee..0f10af7f287600 100644 --- a/ext/web/lib.deno_web.d.ts +++ b/ext/web/lib.deno_web.d.ts @@ -293,6 +293,10 @@ interface AbortSignal extends EventTarget { listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions, ): void; + + /** Throws this AbortSignal's abort reason, if its AbortController has + * signaled to abort; otherwise, does nothing. */ + throwIfAborted(): void; } declare var AbortSignal: { diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index d44b673e287d47..6367800d803896 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -4799,16 +4799,8 @@ "abort": { "AbortSignal.any.html": true, "AbortSignal.any.worker.html": true, - "event.any.html": [ - "throwIfAborted() should throw abort.reason if signal aborted", - "throwIfAborted() should throw primitive abort.reason if signal aborted", - "throwIfAborted() should not throw if signal not aborted" - ], - "event.any.worker.html": [ - "throwIfAborted() should throw abort.reason if signal aborted", - "throwIfAborted() should throw primitive abort.reason if signal aborted", - "throwIfAborted() should not throw if signal not aborted" - ] + "event.any.html": true, + "event.any.worker.html": true }, "events": { "AddEventListenerOptions-once.any.html": [