From cd94a44ca1b02315300fbdf22e5db07e382e028d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald <jonas.jenwald@gmail.com> Date: Sat, 16 Oct 2021 12:16:40 +0200 Subject: [PATCH] Remove some duplication in *simple* shadowed getters in `src/core/`-code In these cases there's no good reason, in my opinion, to duplicate the `shadow`-lines since that unnecessarily increases the risk of simple typos (see the previous patch). --- src/core/catalog.js | 18 ++++++++++-------- src/core/document.js | 28 ++++++++++++++++------------ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/core/catalog.js b/src/core/catalog.js index 64c214344..2ace6fa40 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -82,10 +82,11 @@ class Catalog { get version() { const version = this._catDict.get("Version"); - if (!isName(version)) { - return shadow(this, "version", null); - } - return shadow(this, "version", version.name); + return shadow( + this, + "version", + version instanceof Name ? version.name : null + ); } /** @@ -94,10 +95,11 @@ class Catalog { */ get needsRendering() { const needsRendering = this._catDict.get("NeedsRendering"); - if (!isBool(needsRendering)) { - return shadow(this, "needsRendering", false); - } - return shadow(this, "needsRendering", needsRendering); + return shadow( + this, + "needsRendering", + typeof needsRendering === "boolean" ? needsRendering : false + ); } get collection() { diff --git a/src/core/document.js b/src/core/document.js index 02161e2c1..21373afc2 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -263,12 +263,13 @@ class Page { } get xfaData() { - if (this.xfaFactory) { - return shadow(this, "xfaData", { - bbox: this.xfaFactory.getBoundingBox(this.pageIndex), - }); - } - return shadow(this, "xfaData", null); + return shadow( + this, + "xfaData", + this.xfaFactory + ? { bbox: this.xfaFactory.getBoundingBox(this.pageIndex) } + : null + ); } save(handler, task, annotationStorage) { @@ -784,11 +785,14 @@ class PDFDocument { } get numPages() { + let num = 0; if (this.xfaFactory) { - return shadow(this, "numPages", this.xfaFactory.numberPages); + num = this.xfaFactory.numberPages; + } else if (this.linearization) { + num = this.linearization.numPages; + } else { + num = this.catalog.numPages; } - const linearization = this.linearization; - const num = linearization ? linearization.numPages : this.catalog.numPages; return shadow(this, "numPages", num); } @@ -883,16 +887,16 @@ class PDFDocument { } get xfaFactory() { + let data; if ( this.pdfManager.enableXfa && this.catalog.needsRendering && this.formInfo.hasXfa && !this.formInfo.hasAcroForm ) { - const data = this.xfaData; - return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null); + data = this.xfaData; } - return shadow(this, "xfaFactory", null); + return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null); } get isPureXfa() {