From 499610779ecf7e67c5cc97baca3d7bc235556120 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 23 Sep 2022 13:25:15 +0200 Subject: [PATCH 1/2] 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; } } From cf038d03682e078ed6b3f086c43bb8856a537c69 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 23 Sep 2022 13:26:19 +0200 Subject: [PATCH 2/2] [api-minor] Stop exposing the `LoopbackPort` class in the API This was done all the way back in PR 8361, for a mozilla-central test that's since been removed. As can be seen in the following search results, there's no `LoopbackPort` invocation outside of the PDF.js code itself: https://searchfox.org/mozilla-central/search?q=LoopbackPort&path= Given that the `LoopbackPort` is only used in connection with "fake workers", which is something that we don't officially recommend/support, this doesn't seem like functionality that we want to keep exposing in the public API. --- src/pdf.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pdf.js b/src/pdf.js index 8a5527812..e522dac3d 100644 --- a/src/pdf.js +++ b/src/pdf.js @@ -43,7 +43,6 @@ import { import { build, getDocument, - LoopbackPort, PDFDataRangeTransport, PDFWorker, setPDFNetworkStreamFactory, @@ -128,7 +127,6 @@ export { InvalidPDFException, isPdfFile, loadScript, - LoopbackPort, MissingPDFException, OPS, PasswordResponses,