Convert PDFDocument._getLinearizationPage to an async method

This, ever so slightly, simplifies the code and reduces overall indentation.
This commit is contained in:
Jonas Jenwald 2021-11-26 19:57:47 +01:00
parent 080996ac68
commit 4c56214ab4

View File

@ -1261,7 +1261,7 @@ class PDFDocument {
]); ]);
} }
_getLinearizationPage(pageIndex) { async _getLinearizationPage(pageIndex) {
const { catalog, linearization } = this; const { catalog, linearization } = this;
if ( if (
typeof PDFJSDev === "undefined" || typeof PDFJSDev === "undefined" ||
@ -1274,9 +1274,8 @@ class PDFDocument {
} }
const ref = Ref.get(linearization.objectNumberFirst, 0); const ref = Ref.get(linearization.objectNumberFirst, 0);
return this.xref try {
.fetchAsync(ref) const obj = await this.xref.fetchAsync(ref);
.then(obj => {
// Ensure that the object that was found is actually a Page dictionary. // Ensure that the object that was found is actually a Page dictionary.
if ( if (
isDict(obj, "Page") || isDict(obj, "Page") ||
@ -1288,14 +1287,12 @@ class PDFDocument {
return [obj, ref]; return [obj, ref];
} }
throw new FormatError( throw new FormatError(
"The Linearization dictionary doesn't point " + "The Linearization dictionary doesn't point to a valid Page dictionary."
"to a valid Page dictionary."
); );
}) } catch (reason) {
.catch(reason => {
info(reason); info(reason);
return catalog.getPageDict(pageIndex); return catalog.getPageDict(pageIndex);
}); }
} }
getPage(pageIndex) { getPage(pageIndex) {