From 499610779ecf7e67c5cc97baca3d7bc235556120 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 23 Sep 2022 13:25:15 +0200 Subject: [PATCH] Re-factor the `LoopbackPort` class to use *proper* private fields --- src/display/api.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 6e768be86..e449ea319 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1853,34 +1853,33 @@ class PDFPageProxy { } class LoopbackPort { - constructor() { - this._listeners = []; - this._deferred = Promise.resolve(); - } + #listeners = []; + + #deferred = Promise.resolve(); postMessage(obj, transfers) { const event = { data: structuredClone(obj, transfers), }; - this._deferred.then(() => { - for (const listener of this._listeners) { + this.#deferred.then(() => { + for (const listener of this.#listeners) { listener.call(this, event); } }); } addEventListener(name, listener) { - this._listeners.push(listener); + this.#listeners.push(listener); } removeEventListener(name, listener) { - const i = this._listeners.indexOf(listener); - this._listeners.splice(i, 1); + const i = this.#listeners.indexOf(listener); + this.#listeners.splice(i, 1); } terminate() { - this._listeners.length = 0; + this.#listeners.length = 0; } }