From fbe90b63ec7b1b409cd6abfd7516ff280328ba2a Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 28 Jul 2020 14:33:39 +0200 Subject: [PATCH] [src/core/worker.js] Remove a useless Promise handler from the `pdfManagerReady` function Looking carefully at this code, you'll notice that the `loadDocument` function has no less than *three* Promise handling functions. This obviously makes no sense, since a Promise can only have one resolve and one reject handler. Hence the final `onFailure`-case is unreachable, which only serves to add confusion when reading the code. Note that this code has been re-factored more than once over the years, but it seems as if this may even have been incorrect already in PR 3310 (and no-one have noticed for seven years :-). --- src/core/worker.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/core/worker.js b/src/core/worker.js index 6f90cee8e..269bb6ab2 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -371,25 +371,21 @@ class WorkerMessageHandler { function pdfManagerReady() { ensureNotTerminated(); - loadDocument(false).then( - onSuccess, - function loadFailure(ex) { + loadDocument(false).then(onSuccess, function (reason) { + ensureNotTerminated(); + + // Try again with recoveryMode == true + if (!(reason instanceof XRefParseException)) { + onFailure(reason); + return; + } + pdfManager.requestLoadedStream(); + pdfManager.onLoadedStream().then(function () { ensureNotTerminated(); - // Try again with recoveryMode == true - if (!(ex instanceof XRefParseException)) { - onFailure(ex); - return; - } - pdfManager.requestLoadedStream(); - pdfManager.onLoadedStream().then(function () { - ensureNotTerminated(); - - loadDocument(true).then(onSuccess, onFailure); - }); - }, - onFailure - ); + loadDocument(true).then(onSuccess, onFailure); + }); + }); } ensureNotTerminated();