Merge pull request #13234 from Snuffleupagus/hasJSActions-MissingDataException
[api-minor] Ensure that `PDFDocumentProxy.hasJSActions` won't fail if `MissingDataException`s are thrown during the associated worker-thread parsing
This commit is contained in:
commit
ebeb3f7999
@ -523,7 +523,6 @@ class Page {
|
||||
this.pageDict,
|
||||
PageActionEventType
|
||||
);
|
||||
|
||||
return shadow(this, "jsActions", actions);
|
||||
}
|
||||
}
|
||||
@ -1189,19 +1188,28 @@ class PDFDocument {
|
||||
}
|
||||
|
||||
get hasJSActions() {
|
||||
return shadow(
|
||||
this,
|
||||
"hasJSActions",
|
||||
this.fieldObjects.then(fieldObjects => {
|
||||
return (
|
||||
(fieldObjects !== null &&
|
||||
Object.values(fieldObjects).some(fieldObject =>
|
||||
fieldObject.some(object => object.actions !== null)
|
||||
)) ||
|
||||
!!this.catalog.jsActions
|
||||
);
|
||||
})
|
||||
);
|
||||
const promise = this.pdfManager.ensure(this, "_parseHasJSActions");
|
||||
return shadow(this, "hasJSActions", promise);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
async _parseHasJSActions() {
|
||||
const [catalogJsActions, fieldObjects] = await Promise.all([
|
||||
this.pdfManager.ensureCatalog("jsActions"),
|
||||
this.pdfManager.ensure(this, "fieldObjects"),
|
||||
]);
|
||||
|
||||
if (catalogJsActions) {
|
||||
return true;
|
||||
}
|
||||
if (fieldObjects) {
|
||||
return Object.values(fieldObjects).some(fieldObject =>
|
||||
fieldObject.some(object => object.actions !== null)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
get calculationOrderIds() {
|
||||
|
@ -856,9 +856,6 @@ class Catalog {
|
||||
return shadow(this, "viewerPreferences", prefs);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: "JavaScript" actions are, for now, handled by `get javaScript` below.
|
||||
*/
|
||||
get openAction() {
|
||||
const obj = this._catDict.get("OpenAction");
|
||||
const openAction = Object.create(null);
|
||||
@ -923,9 +920,9 @@ class Catalog {
|
||||
}
|
||||
|
||||
if (javaScript === null) {
|
||||
javaScript = Object.create(null);
|
||||
javaScript = new Map();
|
||||
}
|
||||
javaScript[name] = stringToPDFString(js);
|
||||
javaScript.set(name, stringToPDFString(js));
|
||||
}
|
||||
|
||||
if (obj && obj.has("JavaScript")) {
|
||||
@ -955,23 +952,23 @@ class Catalog {
|
||||
return shadow(
|
||||
this,
|
||||
"javaScript",
|
||||
javaScript ? Object.values(javaScript) : null
|
||||
javaScript ? [...javaScript.values()] : null
|
||||
);
|
||||
}
|
||||
|
||||
get jsActions() {
|
||||
const js = this._collectJavaScript();
|
||||
const javaScript = this._collectJavaScript();
|
||||
let actions = collectActions(
|
||||
this.xref,
|
||||
this._catDict,
|
||||
DocumentActionEventType
|
||||
);
|
||||
|
||||
if (!actions && js) {
|
||||
actions = Object.create(null);
|
||||
}
|
||||
if (actions && js) {
|
||||
for (const [key, val] of Object.entries(js)) {
|
||||
if (javaScript) {
|
||||
if (!actions) {
|
||||
actions = Object.create(null);
|
||||
}
|
||||
for (const [key, val] of javaScript) {
|
||||
if (key in actions) {
|
||||
actions[key].push(val);
|
||||
} else {
|
||||
@ -979,7 +976,6 @@ class Catalog {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return shadow(this, "jsActions", actions);
|
||||
}
|
||||
|
||||
|
@ -1014,6 +1014,23 @@ describe("api", function () {
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it("gets hasJSActions, in document without javaScript", async function () {
|
||||
const hasJSActions = await pdfDocument.hasJSActions();
|
||||
|
||||
expect(hasJSActions).toEqual(false);
|
||||
});
|
||||
it("gets hasJSActions, in document with javaScript", async function () {
|
||||
const loadingTask = getDocument(
|
||||
buildGetDocumentParams("doc_actions.pdf")
|
||||
);
|
||||
const pdfDoc = await loadingTask.promise;
|
||||
const hasJSActions = await pdfDoc.hasJSActions();
|
||||
|
||||
expect(hasJSActions).toEqual(true);
|
||||
|
||||
await loadingTask.destroy();
|
||||
});
|
||||
|
||||
it("gets JSActions (none)", function (done) {
|
||||
const promise = pdfDocument.getJSActions();
|
||||
promise
|
||||
|
Loading…
Reference in New Issue
Block a user