perf(web): optimize AbortController
Use regular class constructor and symbol "private" attributes
Lazy init Set of follower signals
Boolean,
Set,
SetPrototypeAdd,
- SetPrototypeClear,
SetPrototypeDelete,
Symbol,
SymbolToStringTag,
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]();
}
[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) {
+ this[aborted] = true;
+ if (this[abortAlgos] !== null) {
+ for (const algorithm of this[abortAlgos]) {
algorithm();
}
- SetPrototypeClear(this.#abortAlgorithms);
+ this[abortAlgos] = null;
+ }
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) {
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]() {
