Skip to content

Commit 39803a9

Browse files
committed
Replace a number of semi-private methods with actual private ones in src/core/document.js
There's a few remaining cases that are used with either cached getters or `BasePdfManager.prototype.ensure`-methods, and those cannot be converted.
1 parent 0ded85e commit 39803a9

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

src/core/document.js

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ class Page {
141141
});
142142
}
143143

144-
/**
145-
* @private
146-
*/
147-
_getInheritableProperty(key, getArray = false) {
144+
#getInheritableProperty(key, getArray = false) {
148145
const value = getInheritableProperty({
149146
dict: this.pageDict,
150147
key,
@@ -168,7 +165,7 @@ class Page {
168165
// For robustness: The spec states that a \Resources entry has to be
169166
// present, but can be empty. Some documents still omit it; in this case
170167
// we return an empty dictionary.
171-
const resources = this._getInheritableProperty("Resources");
168+
const resources = this.#getInheritableProperty("Resources");
172169

173170
return shadow(
174171
this,
@@ -177,12 +174,12 @@ class Page {
177174
);
178175
}
179176

180-
_getBoundingBox(name) {
177+
#getBoundingBox(name) {
181178
if (this.xfaData) {
182179
return this.xfaData.bbox;
183180
}
184181
const box = lookupNormalRect(
185-
this._getInheritableProperty(name, /* getArray = */ true),
182+
this.#getInheritableProperty(name, /* getArray = */ true),
186183
null
187184
);
188185

@@ -200,7 +197,7 @@ class Page {
200197
return shadow(
201198
this,
202199
"mediaBox",
203-
this._getBoundingBox("MediaBox") || LETTER_SIZE_MEDIABOX
200+
this.#getBoundingBox("MediaBox") || LETTER_SIZE_MEDIABOX
204201
);
205202
}
206203

@@ -209,7 +206,7 @@ class Page {
209206
return shadow(
210207
this,
211208
"cropBox",
212-
this._getBoundingBox("CropBox") || this.mediaBox
209+
this.#getBoundingBox("CropBox") || this.mediaBox
213210
);
214211
}
215212

@@ -240,7 +237,7 @@ class Page {
240237
}
241238

242239
get rotate() {
243-
let rotate = this._getInheritableProperty("Rotate") || 0;
240+
let rotate = this.#getInheritableProperty("Rotate") || 0;
244241

245242
// Normalize rotation so it's a multiple of 90 and between 0 and 270.
246243
if (rotate % 90 !== 0) {
@@ -255,10 +252,7 @@ class Page {
255252
return shadow(this, "rotate", rotate);
256253
}
257254

258-
/**
259-
* @private
260-
*/
261-
_onSubStreamError(reason, objId) {
255+
#onSubStreamError(reason, objId) {
262256
if (this.evaluatorOptions.ignoreErrors) {
263257
warn(`getContentStream - ignoring sub-stream (${objId}): "${reason}".`);
264258
return;
@@ -278,7 +272,7 @@ class Page {
278272
if (Array.isArray(content)) {
279273
return new StreamsSequenceStream(
280274
content,
281-
this._onSubStreamError.bind(this)
275+
this.#onSubStreamError.bind(this)
282276
);
283277
}
284278
// Replace non-existent page content with empty content.
@@ -405,7 +399,7 @@ class Page {
405399
}
406400

407401
async loadResources(keys) {
408-
// TODO: add async `_getInheritableProperty` and remove this.
402+
// TODO: add async `#getInheritableProperty` and remove this.
409403
await (this.resourcesPromise ??= this.pdfManager.ensure(this, "resources"));
410404

411405
await ObjectLoader.load(this.resources, keys, this.xref);
@@ -742,7 +736,7 @@ class Page {
742736
}
743737

744738
get annotations() {
745-
const annots = this._getInheritableProperty("Annots");
739+
const annots = this.#getInheritableProperty("Annots");
746740
return shadow(this, "annotations", Array.isArray(annots) ? annots : []);
747741
}
748742

@@ -1045,10 +1039,7 @@ class PDFDocument {
10451039
return shadow(this, "numPages", num);
10461040
}
10471041

1048-
/**
1049-
* @private
1050-
*/
1051-
_hasOnlyDocumentSignatures(fields, recursionDepth = 0) {
1042+
#hasOnlyDocumentSignatures(fields, recursionDepth = 0) {
10521043
const RECURSION_LIMIT = 10;
10531044

10541045
if (!Array.isArray(fields)) {
@@ -1061,10 +1052,10 @@ class PDFDocument {
10611052
}
10621053
if (field.has("Kids")) {
10631054
if (++recursionDepth > RECURSION_LIMIT) {
1064-
warn("_hasOnlyDocumentSignatures: maximum recursion depth reached");
1055+
warn("#hasOnlyDocumentSignatures: maximum recursion depth reached");
10651056
return false;
10661057
}
1067-
return this._hasOnlyDocumentSignatures(
1058+
return this.#hasOnlyDocumentSignatures(
10681059
field.get("Kids"),
10691060
recursionDepth
10701061
);
@@ -1393,7 +1384,7 @@ class PDFDocument {
13931384
const sigFlags = acroForm.get("SigFlags");
13941385
const hasSignatures = !!(sigFlags & 0x1);
13951386
const hasOnlyDocumentSignatures =
1396-
hasSignatures && this._hasOnlyDocumentSignatures(fields);
1387+
hasSignatures && this.#hasOnlyDocumentSignatures(fields);
13971388
formInfo.hasAcroForm = hasFields && !hasOnlyDocumentSignatures;
13981389
formInfo.hasSignatures = hasSignatures;
13991390
} catch (ex) {
@@ -1520,7 +1511,7 @@ class PDFDocument {
15201511
]);
15211512
}
15221513

1523-
async _getLinearizationPage(pageIndex) {
1514+
async #getLinearizationPage(pageIndex) {
15241515
const { catalog, linearization, xref } = this;
15251516
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
15261517
assert(
@@ -1573,7 +1564,7 @@ class PDFDocument {
15731564
if (xfaFactory) {
15741565
promise = Promise.resolve([Dict.empty, null]);
15751566
} else if (linearization?.pageFirst === pageIndex) {
1576-
promise = this._getLinearizationPage(pageIndex);
1567+
promise = this.#getLinearizationPage(pageIndex);
15771568
} else {
15781569
promise = catalog.getPageDict(pageIndex);
15791570
}

0 commit comments

Comments
 (0)