diff --git a/src/core/worker.js b/src/core/worker.js index e285d6491bcac..533d8d01286ae 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -189,7 +189,7 @@ class WorkerMessageHandler { return { numPages, fingerprints, htmlForXfa }; } - function getPdfManager({ + async function getPdfManager({ data, password, disableAutoFetch, @@ -211,32 +211,20 @@ class WorkerMessageHandler { password, rangeChunkSize, }; - const pdfManagerCapability = Promise.withResolvers(); - let newPdfManager; if (data) { - try { - pdfManagerArgs.source = data; + pdfManagerArgs.source = data; - newPdfManager = new LocalPdfManager(pdfManagerArgs); - pdfManagerCapability.resolve(newPdfManager); - } catch (ex) { - pdfManagerCapability.reject(ex); - } - return pdfManagerCapability.promise; + return new LocalPdfManager(pdfManagerArgs); } + const pdfStream = new PDFWorkerStream(handler), + fullRequest = pdfStream.getFullReader(); - let pdfStream, + const pdfManagerCapability = Promise.withResolvers(); + let newPdfManager, cachedChunks = [], loaded = 0; - try { - pdfStream = new PDFWorkerStream(handler); - } catch (ex) { - pdfManagerCapability.reject(ex); - return pdfManagerCapability.promise; - } - const fullRequest = pdfStream.getFullReader(); fullRequest.headersReady .then(function () { if (!fullRequest.isRangeSupported) { @@ -315,7 +303,7 @@ class WorkerMessageHandler { cancelXHRs = null; }); - cancelXHRs = function (reason) { + cancelXHRs = reason => { pdfStream.cancelAllRequests(reason); };