Skip to content

Commit

Permalink
feat(ext/web): Implement AbortSignal.prototype.throwIfAborted()
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreu Botella committed Dec 10, 2021
1 parent 542b71e commit f518bfa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 7 additions & 0 deletions ext/web/03_abort_signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 4 additions & 0 deletions ext/web/lib.deno_web.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
12 changes: 2 additions & 10 deletions tools/wpt/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit f518bfa

Please sign in to comment.