summaryrefslogtreecommitdiff
path: root/ext/web/03_abort_signal.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-09-21 17:38:57 +0200
committerGitHub <noreply@github.com>2021-09-21 17:38:57 +0200
commitf827b93df42385a0a5e37b6fbd41f2808aa9aa94 (patch)
treec8431bdbff6d50ee574bd373d2acf92186bfe148 /ext/web/03_abort_signal.js
parent8375f5464b40f1713c64653ad20ed639c1e88cdd (diff)
perf(web): optimize AbortController (#12165)
- Use regular class constructor and symbol "private" attributes - Lazy init Set of follower signals
Diffstat (limited to 'ext/web/03_abort_signal.js')
-rw-r--r--ext/web/03_abort_signal.js29
1 files changed, 17 insertions, 12 deletions
diff --git a/ext/web/03_abort_signal.js b/ext/web/03_abort_signal.js
index d67bfef26..511ad216f 100644
--- a/ext/web/03_abort_signal.js
+++ b/ext/web/03_abort_signal.js
@@ -11,7 +11,6 @@
Boolean,
Set,
SetPrototypeAdd,
- SetPrototypeClear,
SetPrototypeDelete,
Symbol,
SymbolToStringTag,
@@ -21,13 +20,12 @@
const add = Symbol("add");
const signalAbort = Symbol("signalAbort");
const remove = Symbol("remove");
+ const aborted = Symbol("aborted");
+ const abortAlgos = Symbol("abortAlgos");
const illegalConstructorKey = Symbol("illegalConstructorKey");
class AbortSignal extends EventTarget {
- #aborted = false;
- #abortAlgorithms = new Set();
-
static abort() {
const signal = new AbortSignal(illegalConstructorKey);
signal[signalAbort]();
@@ -35,25 +33,30 @@
}
[add](algorithm) {
- SetPrototypeAdd(this.#abortAlgorithms, algorithm);
+ if (this[abortAlgos] === null) {
+ this[abortAlgos] = new Set();
+ }
+ SetPrototypeAdd(this[abortAlgos], algorithm);
}
[signalAbort]() {
- if (this.#aborted) {
+ if (this[aborted]) {
return;
}
- this.#aborted = true;
- for (const algorithm of this.#abortAlgorithms) {
- algorithm();
+ this[aborted] = true;
+ if (this[abortAlgos] !== null) {
+ for (const algorithm of this[abortAlgos]) {
+ algorithm();
+ }
+ this[abortAlgos] = null;
}
- SetPrototypeClear(this.#abortAlgorithms);
const event = new Event("abort");
setIsTrusted(event, true);
this.dispatchEvent(event);
}
[remove](algorithm) {
- SetPrototypeDelete(this.#abortAlgorithms, algorithm);
+ this[abortAlgos] && SetPrototypeDelete(this[abortAlgos], algorithm);
}
constructor(key = null) {
@@ -61,11 +64,13 @@
throw new TypeError("Illegal constructor.");
}
super();
+ this[aborted] = false;
+ this[abortAlgos] = null;
this[webidl.brand] = webidl.brand;
}
get aborted() {
- return Boolean(this.#aborted);
+ return Boolean(this[aborted]);
}
get [SymbolToStringTag]() {