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).
This commit is contained in:
Jonas Jenwald 2021-10-16 12:16:40 +02:00
parent 1450da4168
commit cd94a44ca1
2 changed files with 26 additions and 20 deletions

View File

@ -82,10 +82,11 @@ class Catalog {
get version() { get version() {
const version = this._catDict.get("Version"); const version = this._catDict.get("Version");
if (!isName(version)) { return shadow(
return shadow(this, "version", null); this,
} "version",
return shadow(this, "version", version.name); version instanceof Name ? version.name : null
);
} }
/** /**
@ -94,10 +95,11 @@ class Catalog {
*/ */
get needsRendering() { get needsRendering() {
const needsRendering = this._catDict.get("NeedsRendering"); const needsRendering = this._catDict.get("NeedsRendering");
if (!isBool(needsRendering)) { return shadow(
return shadow(this, "needsRendering", false); this,
} "needsRendering",
return shadow(this, "needsRendering", needsRendering); typeof needsRendering === "boolean" ? needsRendering : false
);
} }
get collection() { get collection() {

View File

@ -263,12 +263,13 @@ class Page {
} }
get xfaData() { get xfaData() {
if (this.xfaFactory) { return shadow(
return shadow(this, "xfaData", { this,
bbox: this.xfaFactory.getBoundingBox(this.pageIndex), "xfaData",
}); this.xfaFactory
} ? { bbox: this.xfaFactory.getBoundingBox(this.pageIndex) }
return shadow(this, "xfaData", null); : null
);
} }
save(handler, task, annotationStorage) { save(handler, task, annotationStorage) {
@ -784,11 +785,14 @@ class PDFDocument {
} }
get numPages() { get numPages() {
let num = 0;
if (this.xfaFactory) { 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); return shadow(this, "numPages", num);
} }
@ -883,16 +887,16 @@ class PDFDocument {
} }
get xfaFactory() { get xfaFactory() {
let data;
if ( if (
this.pdfManager.enableXfa && this.pdfManager.enableXfa &&
this.catalog.needsRendering && this.catalog.needsRendering &&
this.formInfo.hasXfa && this.formInfo.hasXfa &&
!this.formInfo.hasAcroForm !this.formInfo.hasAcroForm
) { ) {
const data = this.xfaData; data = this.xfaData;
return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null);
} }
return shadow(this, "xfaFactory", null); return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null);
} }
get isPureXfa() { get isPureXfa() {