Change the LoopbackPort class to use a Set internally

This is a tiny bit more compact, thanks to the `Set.prototype.delete` method.
This commit is contained in:
Jonas Jenwald 2023-02-09 12:34:41 +01:00
parent ff3b9ccf6e
commit 9d29abdfa0

View File

@ -1909,7 +1909,7 @@ class PDFPageProxy {
}
class LoopbackPort {
#listeners = [];
#listeners = new Set();
#deferred = Promise.resolve();
@ -1926,16 +1926,15 @@ class LoopbackPort {
}
addEventListener(name, listener) {
this.#listeners.push(listener);
this.#listeners.add(listener);
}
removeEventListener(name, listener) {
const i = this.#listeners.indexOf(listener);
this.#listeners.splice(i, 1);
this.#listeners.delete(listener);
}
terminate() {
this.#listeners.length = 0;
this.#listeners.clear();
}
}