From 322b1072afa14c243ea443bda5044981747dede0 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 31 Oct 2020 11:24:39 +0100 Subject: [PATCH] Use optional chaining in `web/pdf_history.js` Since we're now free to use e.g. optional chaining everywhere *except* for the worker, we can thus simplify this code a bit. --- web/pdf_history.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/web/pdf_history.js b/web/pdf_history.js index 51e6038fd156d..a4e86774158f9 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -290,7 +290,7 @@ class PDFHistory { return; } - if (this._destination && this._destination.page === pageNumber) { + if (this._destination?.page === pageNumber) { // When the new page is identical to the one in `this._destination`, we // don't want to add a potential duplicate entry in the browser history. return; @@ -388,8 +388,7 @@ class PDFHistory { if ( typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME") && - window.history.state && - window.history.state.chromecomState + window.history.state?.chromecomState ) { // history.state.chromecomState is managed by chromecom.js. newState.chromecomState = window.history.state.chromecomState; @@ -397,7 +396,7 @@ class PDFHistory { this._updateInternalState(destination, newState.uid); let newUrl; - if (this._updateUrl && destination && destination.hash) { + if (this._updateUrl && destination?.hash) { const baseUrl = document.location.href.split("#")[0]; // Prevent errors in Firefox. if (!baseUrl.startsWith("file://")) { @@ -494,7 +493,7 @@ class PDFHistory { return false; } const [perfEntry] = performance.getEntriesByType("navigation"); - if (!perfEntry || perfEntry.type !== "reload") { + if (perfEntry?.type !== "reload") { return false; } } else { @@ -523,7 +522,7 @@ class PDFHistory { clearTimeout(this._updateViewareaTimeout); this._updateViewareaTimeout = null; } - if (removeTemporary && destination && destination.temporary) { + if (removeTemporary && destination?.temporary) { // When the `destination` comes from the browser history, // we no longer treat it as a *temporary* position. delete destination.temporary; @@ -633,8 +632,7 @@ class PDFHistory { if ( (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME") && - state && - state.chromecomState && + state?.chromecomState && !this._isValidState(state)) || !state ) {