Merge pull request #18871 from Snuffleupagus/PDFDocument-more-ensure
Improve the promise-caching in the `PDFDocument.fieldObjects` getter
This commit is contained in:
commit
1269c6a4f9
@ -1871,14 +1871,17 @@ class PDFDocument {
|
||||
}
|
||||
|
||||
get fieldObjects() {
|
||||
if (!this.formInfo.hasFields) {
|
||||
return shadow(this, "fieldObjects", Promise.resolve(null));
|
||||
const promise = this.pdfManager
|
||||
.ensureDoc("formInfo")
|
||||
.then(async formInfo => {
|
||||
if (!formInfo.hasFields) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const promise = Promise.all([
|
||||
const [annotationGlobals, acroForm] = await Promise.all([
|
||||
this.pdfManager.ensureDoc("annotationGlobals"),
|
||||
this.pdfManager.ensureCatalog("acroForm"),
|
||||
]).then(async ([annotationGlobals, acroForm]) => {
|
||||
]);
|
||||
if (!annotationGlobals) {
|
||||
return null;
|
||||
}
|
||||
@ -1944,12 +1947,7 @@ class PDFDocument {
|
||||
}
|
||||
|
||||
get calculationOrderIds() {
|
||||
const acroForm = this.catalog.acroForm;
|
||||
if (!acroForm?.has("CO")) {
|
||||
return shadow(this, "calculationOrderIds", null);
|
||||
}
|
||||
|
||||
const calculationOrder = acroForm.get("CO");
|
||||
const calculationOrder = this.catalog.acroForm?.get("CO");
|
||||
if (!Array.isArray(calculationOrder) || calculationOrder.length === 0) {
|
||||
return shadow(this, "calculationOrderIds", null);
|
||||
}
|
||||
@ -1960,10 +1958,7 @@ class PDFDocument {
|
||||
ids.push(id.toString());
|
||||
}
|
||||
}
|
||||
if (ids.length === 0) {
|
||||
return shadow(this, "calculationOrderIds", null);
|
||||
}
|
||||
return shadow(this, "calculationOrderIds", ids);
|
||||
return shadow(this, "calculationOrderIds", ids.length ? ids : null);
|
||||
}
|
||||
|
||||
get annotationGlobals() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user