From f0bf62ff54199745d902546cbb73ca1922e7daf1 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sat, 22 Aug 2020 23:38:50 +0200 Subject: [PATCH] Mark the `catDict` member as private in the `Catalog` class Not only is `catDict` never accessed anymore outside of this file, it should also never happen since it's internal to the catalog. If data from it is needed elsewhere, the catalog should provide a getter for it that can do basic data integrity checks and abstract away any unnecessary details. --- src/core/obj.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/core/obj.js b/src/core/obj.js index e7d8303a0..f4b9d2e85 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -65,8 +65,8 @@ class Catalog { this.pdfManager = pdfManager; this.xref = xref; - this.catDict = xref.getCatalogObj(); - if (!isDict(this.catDict)) { + this._catDict = xref.getCatalogObj(); + if (!isDict(this._catDict)) { throw new FormatError("Catalog object is not a dictionary."); } @@ -77,7 +77,7 @@ class Catalog { } get version() { - const version = this.catDict.get("Version"); + const version = this._catDict.get("Version"); if (!isName(version)) { return shadow(this, "version", null); } @@ -87,7 +87,7 @@ class Catalog { get collection() { let collection = null; try { - const obj = this.catDict.get("Collection"); + const obj = this._catDict.get("Collection"); if (isDict(obj) && obj.size > 0) { collection = obj; } @@ -103,7 +103,7 @@ class Catalog { get acroForm() { let acroForm = null; try { - const obj = this.catDict.get("AcroForm"); + const obj = this._catDict.get("AcroForm"); if (isDict(obj) && obj.size > 0) { acroForm = obj; } @@ -117,7 +117,7 @@ class Catalog { } get metadata() { - const streamRef = this.catDict.getRaw("Metadata"); + const streamRef = this._catDict.getRaw("Metadata"); if (!isRef(streamRef)) { return shadow(this, "metadata", null); } @@ -152,7 +152,7 @@ class Catalog { } get toplevelPagesDict() { - const pagesObj = this.catDict.get("Pages"); + const pagesObj = this._catDict.get("Pages"); if (!isDict(pagesObj)) { throw new FormatError("Invalid top-level pages dictionary."); } @@ -176,7 +176,7 @@ class Catalog { * @private */ _readDocumentOutline() { - let obj = this.catDict.get("Outlines"); + let obj = this._catDict.get("Outlines"); if (!isDict(obj)) { return null; } @@ -297,7 +297,7 @@ class Catalog { get optionalContentConfig() { let config = null; try { - const properties = this.catDict.get("OCProperties"); + const properties = this._catDict.get("OCProperties"); if (!properties) { return shadow(this, "optionalContentConfig", null); } @@ -410,12 +410,12 @@ class Catalog { * @private */ _readDests() { - const obj = this.catDict.get("Names"); + const obj = this._catDict.get("Names"); if (obj && obj.has("Dests")) { return new NameTree(obj.getRaw("Dests"), this.xref); - } else if (this.catDict.has("Dests")) { + } else if (this._catDict.has("Dests")) { // Simple destination dictionary. - return this.catDict.get("Dests"); + return this._catDict.get("Dests"); } return undefined; } @@ -437,7 +437,7 @@ class Catalog { * @private */ _readPageLabels() { - const obj = this.catDict.getRaw("PageLabels"); + const obj = this._catDict.getRaw("PageLabels"); if (!obj) { return null; } @@ -537,7 +537,7 @@ class Catalog { } get pageLayout() { - const obj = this.catDict.get("PageLayout"); + const obj = this._catDict.get("PageLayout"); // Purposely use a non-standard default value, rather than 'SinglePage', to // allow differentiating between `undefined` and /SinglePage since that does // affect the Scroll mode (continuous/non-continuous) used in Adobe Reader. @@ -558,7 +558,7 @@ class Catalog { } get pageMode() { - const obj = this.catDict.get("PageMode"); + const obj = this._catDict.get("PageMode"); let pageMode = "UseNone"; // Default value. if (isName(obj)) { @@ -596,7 +596,7 @@ class Catalog { NumCopies: Number.isInteger, }; - const obj = this.catDict.get("ViewerPreferences"); + const obj = this._catDict.get("ViewerPreferences"); let prefs = null; if (isDict(obj)) { @@ -721,7 +721,7 @@ class Catalog { * NOTE: "JavaScript" actions are, for now, handled by `get javaScript` below. */ get openAction() { - const obj = this.catDict.get("OpenAction"); + const obj = this._catDict.get("OpenAction"); let openAction = null; if (isDict(obj)) { @@ -754,7 +754,7 @@ class Catalog { } get attachments() { - const obj = this.catDict.get("Names"); + const obj = this._catDict.get("Names"); let attachments = null; if (obj && obj.has("EmbeddedFiles")) { @@ -772,7 +772,7 @@ class Catalog { } get javaScript() { - const obj = this.catDict.get("Names"); + const obj = this._catDict.get("Names"); let javaScript = null; function appendIfJavaScriptDict(jsDict) { @@ -808,7 +808,7 @@ class Catalog { } // Append OpenAction "JavaScript" actions to the JavaScript array. - const openAction = this.catDict.get("OpenAction"); + const openAction = this._catDict.get("OpenAction"); if (isDict(openAction) && isName(openAction.get("S"), "JavaScript")) { appendIfJavaScriptDict(openAction); } @@ -853,7 +853,7 @@ class Catalog { getPageDict(pageIndex) { const capability = createPromiseCapability(); - const nodesToVisit = [this.catDict.getRaw("Pages")]; + const nodesToVisit = [this._catDict.getRaw("Pages")]; const visitedNodes = new RefSet(); const xref = this.xref, pageKidsCountCache = this.pageKidsCountCache;