Skip to content

Commit d90ec29

Browse files
Merge pull request #19964 from Snuffleupagus/core-catalog-private
Replace semi-private fields/methods with actual private ones in `src/core/catalog.js`
2 parents f11d8b0 + a90e46b commit d90ec29

File tree

1 file changed

+68
-69
lines changed

1 file changed

+68
-69
lines changed

src/core/catalog.js

Lines changed: 68 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,49 @@ function fetchRemoteDest(action) {
8585
}
8686

8787
class Catalog {
88+
#actualNumPages = null;
89+
90+
#catDict = null;
91+
92+
builtInCMapCache = new Map();
93+
94+
fontCache = new RefSetCache();
95+
96+
globalColorSpaceCache = new GlobalColorSpaceCache();
97+
98+
globalImageCache = new GlobalImageCache();
99+
100+
nonBlendModesSet = new RefSet();
101+
102+
pageDictCache = new RefSetCache();
103+
104+
pageIndexCache = new RefSetCache();
105+
106+
pageKidsCountCache = new RefSetCache();
107+
108+
standardFontDataCache = new Map();
109+
110+
systemFontCache = new Map();
111+
88112
constructor(pdfManager, xref) {
89113
this.pdfManager = pdfManager;
90114
this.xref = xref;
91115

92-
this._catDict = xref.getCatalogObj();
93-
if (!(this._catDict instanceof Dict)) {
116+
this.#catDict = xref.getCatalogObj();
117+
if (!(this.#catDict instanceof Dict)) {
94118
throw new FormatError("Catalog object is not a dictionary.");
95119
}
96120
// Given that `XRef.parse` will both fetch *and* validate the /Pages-entry,
97121
// the following call must always succeed here:
98122
this.toplevelPagesDict; // eslint-disable-line no-unused-expressions
99-
100-
this._actualNumPages = null;
101-
102-
this.fontCache = new RefSetCache();
103-
this.builtInCMapCache = new Map();
104-
this.standardFontDataCache = new Map();
105-
this.globalColorSpaceCache = new GlobalColorSpaceCache();
106-
this.globalImageCache = new GlobalImageCache();
107-
this.pageKidsCountCache = new RefSetCache();
108-
this.pageIndexCache = new RefSetCache();
109-
this.pageDictCache = new RefSetCache();
110-
this.nonBlendModesSet = new RefSet();
111-
this.systemFontCache = new Map();
112123
}
113124

114125
cloneDict() {
115-
return this._catDict.clone();
126+
return this.#catDict.clone();
116127
}
117128

118129
get version() {
119-
const version = this._catDict.get("Version");
130+
const version = this.#catDict.get("Version");
120131
if (version instanceof Name) {
121132
if (PDF_VERSION_REGEXP.test(version.name)) {
122133
return shadow(this, "version", version.name);
@@ -127,7 +138,7 @@ class Catalog {
127138
}
128139

129140
get lang() {
130-
const lang = this._catDict.get("Lang");
141+
const lang = this.#catDict.get("Lang");
131142
return shadow(
132143
this,
133144
"lang",
@@ -140,7 +151,7 @@ class Catalog {
140151
* `false` for XFA Foreground documents.
141152
*/
142153
get needsRendering() {
143-
const needsRendering = this._catDict.get("NeedsRendering");
154+
const needsRendering = this.#catDict.get("NeedsRendering");
144155
return shadow(
145156
this,
146157
"needsRendering",
@@ -151,7 +162,7 @@ class Catalog {
151162
get collection() {
152163
let collection = null;
153164
try {
154-
const obj = this._catDict.get("Collection");
165+
const obj = this.#catDict.get("Collection");
155166
if (obj instanceof Dict && obj.size > 0) {
156167
collection = obj;
157168
}
@@ -167,7 +178,7 @@ class Catalog {
167178
get acroForm() {
168179
let acroForm = null;
169180
try {
170-
const obj = this._catDict.get("AcroForm");
181+
const obj = this.#catDict.get("AcroForm");
171182
if (obj instanceof Dict && obj.size > 0) {
172183
acroForm = obj;
173184
}
@@ -181,12 +192,12 @@ class Catalog {
181192
}
182193

183194
get acroFormRef() {
184-
const value = this._catDict.getRaw("AcroForm");
195+
const value = this.#catDict.getRaw("AcroForm");
185196
return shadow(this, "acroFormRef", value instanceof Ref ? value : null);
186197
}
187198

188199
get metadata() {
189-
const streamRef = this._catDict.getRaw("Metadata");
200+
const streamRef = this.#catDict.getRaw("Metadata");
190201
if (!(streamRef instanceof Ref)) {
191202
return shadow(this, "metadata", null);
192203
}
@@ -225,7 +236,7 @@ class Catalog {
225236
get markInfo() {
226237
let markInfo = null;
227238
try {
228-
markInfo = this._readMarkInfo();
239+
markInfo = this.#readMarkInfo();
229240
} catch (ex) {
230241
if (ex instanceof MissingDataException) {
231242
throw ex;
@@ -235,11 +246,8 @@ class Catalog {
235246
return shadow(this, "markInfo", markInfo);
236247
}
237248

238-
/**
239-
* @private
240-
*/
241-
_readMarkInfo() {
242-
const obj = this._catDict.get("MarkInfo");
249+
#readMarkInfo() {
250+
const obj = this.#catDict.get("MarkInfo");
243251
if (!(obj instanceof Dict)) {
244252
return null;
245253
}
@@ -273,7 +281,7 @@ class Catalog {
273281
}
274282

275283
#readStructTreeRoot() {
276-
const rawObj = this._catDict.getRaw("StructTreeRoot");
284+
const rawObj = this.#catDict.getRaw("StructTreeRoot");
277285
const obj = this.xref.fetchIfRef(rawObj);
278286
if (!(obj instanceof Dict)) {
279287
return null;
@@ -285,7 +293,7 @@ class Catalog {
285293
}
286294

287295
get toplevelPagesDict() {
288-
const pagesObj = this._catDict.get("Pages");
296+
const pagesObj = this.#catDict.get("Pages");
289297
if (!(pagesObj instanceof Dict)) {
290298
throw new FormatError("Invalid top-level pages dictionary.");
291299
}
@@ -295,7 +303,7 @@ class Catalog {
295303
get documentOutline() {
296304
let obj = null;
297305
try {
298-
obj = this._readDocumentOutline();
306+
obj = this.#readDocumentOutline();
299307
} catch (ex) {
300308
if (ex instanceof MissingDataException) {
301309
throw ex;
@@ -305,11 +313,8 @@ class Catalog {
305313
return shadow(this, "documentOutline", obj);
306314
}
307315

308-
/**
309-
* @private
310-
*/
311-
_readDocumentOutline() {
312-
let obj = this._catDict.get("Outlines");
316+
#readDocumentOutline() {
317+
let obj = this.#catDict.get("Outlines");
313318
if (!(obj instanceof Dict)) {
314319
return null;
315320
}
@@ -391,7 +396,7 @@ class Catalog {
391396
get permissions() {
392397
let permissions = null;
393398
try {
394-
permissions = this._readPermissions();
399+
permissions = this.#readPermissions();
395400
} catch (ex) {
396401
if (ex instanceof MissingDataException) {
397402
throw ex;
@@ -401,10 +406,7 @@ class Catalog {
401406
return shadow(this, "permissions", permissions);
402407
}
403408

404-
/**
405-
* @private
406-
*/
407-
_readPermissions() {
409+
#readPermissions() {
408410
const encrypt = this.xref.trailer.get("Encrypt");
409411
if (!(encrypt instanceof Dict)) {
410412
return null;
@@ -433,7 +435,7 @@ class Catalog {
433435
get optionalContentConfig() {
434436
let config = null;
435437
try {
436-
const properties = this._catDict.get("OCProperties");
438+
const properties = this.#catDict.get("OCProperties");
437439
if (!properties) {
438440
return shadow(this, "optionalContentConfig", null);
439441
}
@@ -645,11 +647,11 @@ class Catalog {
645647
}
646648

647649
setActualNumPages(num = null) {
648-
this._actualNumPages = num;
650+
this.#actualNumPages = num;
649651
}
650652

651653
get hasActualNumPages() {
652-
return this._actualNumPages !== null;
654+
return this.#actualNumPages !== null;
653655
}
654656

655657
get _pagesCount() {
@@ -663,7 +665,7 @@ class Catalog {
663665
}
664666

665667
get numPages() {
666-
return this.hasActualNumPages ? this._actualNumPages : this._pagesCount;
668+
return this.#actualNumPages ?? this._pagesCount;
667669
}
668670

669671
get destinations() {
@@ -721,22 +723,22 @@ class Catalog {
721723
}
722724

723725
#readDests() {
724-
const obj = this._catDict.get("Names");
726+
const obj = this.#catDict.get("Names");
725727
const rawDests = [];
726728
if (obj?.has("Dests")) {
727729
rawDests.push(new NameTree(obj.getRaw("Dests"), this.xref));
728730
}
729-
if (this._catDict.has("Dests")) {
731+
if (this.#catDict.has("Dests")) {
730732
// Simple destination dictionary.
731-
rawDests.push(this._catDict.get("Dests"));
733+
rawDests.push(this.#catDict.get("Dests"));
732734
}
733735
return rawDests;
734736
}
735737

736738
get pageLabels() {
737739
let obj = null;
738740
try {
739-
obj = this._readPageLabels();
741+
obj = this.#readPageLabels();
740742
} catch (ex) {
741743
if (ex instanceof MissingDataException) {
742744
throw ex;
@@ -746,11 +748,8 @@ class Catalog {
746748
return shadow(this, "pageLabels", obj);
747749
}
748750

749-
/**
750-
* @private
751-
*/
752-
_readPageLabels() {
753-
const obj = this._catDict.getRaw("PageLabels");
751+
#readPageLabels() {
752+
const obj = this.#catDict.getRaw("PageLabels");
754753
if (!obj) {
755754
return null;
756755
}
@@ -847,7 +846,7 @@ class Catalog {
847846
}
848847

849848
get pageLayout() {
850-
const obj = this._catDict.get("PageLayout");
849+
const obj = this.#catDict.get("PageLayout");
851850
// Purposely use a non-standard default value, rather than 'SinglePage', to
852851
// allow differentiating between `undefined` and /SinglePage since that does
853852
// affect the Scroll mode (continuous/non-continuous) used in Adobe Reader.
@@ -868,7 +867,7 @@ class Catalog {
868867
}
869868

870869
get pageMode() {
871-
const obj = this._catDict.get("PageMode");
870+
const obj = this.#catDict.get("PageMode");
872871
let pageMode = "UseNone"; // Default value.
873872

874873
if (obj instanceof Name) {
@@ -886,7 +885,7 @@ class Catalog {
886885
}
887886

888887
get viewerPreferences() {
889-
const obj = this._catDict.get("ViewerPreferences");
888+
const obj = this.#catDict.get("ViewerPreferences");
890889
if (!(obj instanceof Dict)) {
891890
return shadow(this, "viewerPreferences", null);
892891
}
@@ -1012,7 +1011,7 @@ class Catalog {
10121011
}
10131012

10141013
get openAction() {
1015-
const obj = this._catDict.get("OpenAction");
1014+
const obj = this.#catDict.get("OpenAction");
10161015
const openAction = Object.create(null);
10171016

10181017
if (obj instanceof Dict) {
@@ -1040,7 +1039,7 @@ class Catalog {
10401039
}
10411040

10421041
get attachments() {
1043-
const obj = this._catDict.get("Names");
1042+
const obj = this.#catDict.get("Names");
10441043
let attachments = null;
10451044

10461045
if (obj instanceof Dict && obj.has("EmbeddedFiles")) {
@@ -1056,7 +1055,7 @@ class Catalog {
10561055
}
10571056

10581057
get xfaImages() {
1059-
const obj = this._catDict.get("Names");
1058+
const obj = this.#catDict.get("Names");
10601059
let xfaImages = null;
10611060

10621061
if (obj instanceof Dict && obj.has("XFAImages")) {
@@ -1074,8 +1073,8 @@ class Catalog {
10741073
return shadow(this, "xfaImages", xfaImages);
10751074
}
10761075

1077-
_collectJavaScript() {
1078-
const obj = this._catDict.get("Names");
1076+
#collectJavaScript() {
1077+
const obj = this.#catDict.get("Names");
10791078
let javaScript = null;
10801079

10811080
function appendIfJavaScriptDict(name, jsDict) {
@@ -1112,7 +1111,7 @@ class Catalog {
11121111
}
11131112
}
11141113
// Append OpenAction "JavaScript" actions, if any, to the JavaScript map.
1115-
const openAction = this._catDict.get("OpenAction");
1114+
const openAction = this.#catDict.get("OpenAction");
11161115
if (openAction) {
11171116
appendIfJavaScriptDict("OpenAction", openAction);
11181117
}
@@ -1121,10 +1120,10 @@ class Catalog {
11211120
}
11221121

11231122
get jsActions() {
1124-
const javaScript = this._collectJavaScript();
1123+
const javaScript = this.#collectJavaScript();
11251124
let actions = collectActions(
11261125
this.xref,
1127-
this._catDict,
1126+
this.#catDict,
11281127
DocumentActionEventType
11291128
);
11301129

@@ -1164,7 +1163,7 @@ class Catalog {
11641163
const nodesToVisit = [this.toplevelPagesDict];
11651164
const visitedNodes = new RefSet();
11661165

1167-
const pagesRef = this._catDict.getRaw("Pages");
1166+
const pagesRef = this.#catDict.getRaw("Pages");
11681167
if (pagesRef instanceof Ref) {
11691168
visitedNodes.put(pagesRef);
11701169
}
@@ -1301,7 +1300,7 @@ class Catalog {
13011300
const queue = [{ currentNode: this.toplevelPagesDict, posInKids: 0 }];
13021301
const visitedNodes = new RefSet();
13031302

1304-
const pagesRef = this._catDict.getRaw("Pages");
1303+
const pagesRef = this.#catDict.getRaw("Pages");
13051304
if (pagesRef instanceof Ref) {
13061305
visitedNodes.put(pagesRef);
13071306
}
@@ -1505,7 +1504,7 @@ class Catalog {
15051504
}
15061505

15071506
get baseUrl() {
1508-
const uri = this._catDict.get("URI");
1507+
const uri = this.#catDict.get("URI");
15091508
if (uri instanceof Dict) {
15101509
const base = uri.get("Base");
15111510
if (typeof base === "string") {

0 commit comments

Comments
 (0)