From a39943554a57c6d90634b8a38f33567d29c25900 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 8 Jan 2020 15:33:11 +0100 Subject: [PATCH] Simplify, and tweak, a couple of `PDFJSDev` checks This removes a couple of, thanks to preceeding code, unnecessary `typeof PDFJSDev` checks, and also fixes a couple of incorrectly implemented (my fault) checks intended for `TESTING` builds. --- src/core/jpg.js | 5 ++++- src/display/api.js | 1 - src/pdf.js | 2 +- src/shared/message_handler.js | 7 ++++--- web/app.js | 5 +---- web/ui_utils.js | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/core/jpg.js b/src/core/jpg.js index 5e0f15733..9ec0054f2 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -1291,7 +1291,10 @@ var JpegImage = (function JpegImageClosure() { }, getData({ width, height, forceRGB = false, isSourcePDF = false }) { - if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING && !LIB")) { + if ( + typeof PDFJSDev === "undefined" || + PDFJSDev.test("!PRODUCTION || TESTING") + ) { assert( isSourcePDF === true, 'JpegImage.getData: Unexpected "isSourcePDF" value for PDF files.' diff --git a/src/display/api.js b/src/display/api.js index 3168b03b0..44cb2d871 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1639,7 +1639,6 @@ const PDFWorker = (function PDFWorkerClosure() { return worker.WorkerMessageHandler; } if ( - typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS && // eslint-disable-next-line no-undef diff --git a/src/pdf.js b/src/pdf.js index faa52eb0b..de9415a1b 100644 --- a/src/pdf.js +++ b/src/pdf.js @@ -53,7 +53,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { return new PDFNetworkStream(params); }); } -} else if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { +} else if (PDFJSDev.test("CHROME")) { let PDFNetworkStream = require("./display/network.js").PDFNetworkStream; let PDFFetchStream; let isChromeWithFetchCredentials = function() { diff --git a/src/shared/message_handler.js b/src/shared/message_handler.js index 58d6fbf86..6f78aa16d 100644 --- a/src/shared/message_handler.js +++ b/src/shared/message_handler.js @@ -51,9 +51,10 @@ function wrapReason(reason) { (typeof reason === "object" && reason !== null), 'wrapReason: Expected "reason" to be a (possibly cloned) Error.' ); - } - if (typeof reason !== "object" || reason === null) { - return reason; + } else { + if (typeof reason !== "object" || reason === null) { + return reason; + } } switch (reason.name) { case "AbortException": diff --git a/web/app.js b/web/app.js index 843ab8927..af0666f42 100644 --- a/web/app.js +++ b/web/app.js @@ -731,10 +731,7 @@ const PDFViewerApplication = { if (key === "docBaseUrl" && !value) { if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) { value = document.URL.split("#")[0]; - } else if ( - typeof PDFJSDev !== "undefined" && - PDFJSDev.test("MOZCENTRAL || CHROME") - ) { + } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { value = this.baseUrl; } } diff --git a/web/ui_utils.js b/web/ui_utils.js index fd9c4e461..db12afa12 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -745,7 +745,7 @@ function waitOnEventOrTimeout({ target, name, delay = 0 }) { const animationStarted = new Promise(function(resolve) { if ( typeof PDFJSDev !== "undefined" && - PDFJSDev.test("LIB") && + PDFJSDev.test("LIB && TESTING") && typeof window === "undefined" ) { // Prevent "ReferenceError: window is not defined" errors when running the