diff --git a/src/display/api.js b/src/display/api.js index 4d8a069e8..63faea116 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -321,16 +321,12 @@ function getDocument(src) { const workerParams = { postMessageTransfers: params.postMessageTransfers, verbosity: params.verbosity, + port: GlobalWorkerOptions.workerPort, }; // Worker was not provided -- creating and owning our own. If message port // is specified in global worker options, using it. - let workerPort = GlobalWorkerOptions.workerPort; - if (workerPort) { - workerParams.port = workerPort; - worker = PDFWorker.fromPort(workerParams); - } else { - worker = new PDFWorker(workerParams); - } + worker = workerParams.port ? PDFWorker.fromPort(workerParams) : + new PDFWorker(workerParams); task._worker = worker; } var docId = task.docId; @@ -1342,8 +1338,10 @@ class LoopbackPort { * a "fake" worker will be used instead. * @class */ -var PDFWorker = (function PDFWorkerClosure() { +const PDFWorker = (function PDFWorkerClosure() { + const pdfWorkerPorts = new WeakMap(); let nextFakeWorkerId = 0; + let fakeWorkerFilesLoadedCapability; function getWorkerSrc() { if (GlobalWorkerOptions.workerSrc) { @@ -1364,8 +1362,6 @@ var PDFWorker = (function PDFWorkerClosure() { return null; } - let fakeWorkerFilesLoadedCapability; - // Loads worker code into main thread. function setupFakeWorkerGlobal() { if (fakeWorkerFilesLoadedCapability) { @@ -1373,7 +1369,7 @@ var PDFWorker = (function PDFWorkerClosure() { } fakeWorkerFilesLoadedCapability = createPromiseCapability(); - let mainWorkerMessageHandler = getMainThreadWorkerMessageHandler(); + const mainWorkerMessageHandler = getMainThreadWorkerMessageHandler(); if (mainWorkerMessageHandler) { // The worker was already loaded using a `