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,
|
this.pageDict,
|
||||||
PageActionEventType
|
PageActionEventType
|
||||||
);
|
);
|
||||||
|
|
||||||
return shadow(this, "jsActions", actions);
|
return shadow(this, "jsActions", actions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1189,19 +1188,28 @@ class PDFDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get hasJSActions() {
|
get hasJSActions() {
|
||||||
return shadow(
|
const promise = this.pdfManager.ensure(this, "_parseHasJSActions");
|
||||||
this,
|
return shadow(this, "hasJSActions", promise);
|
||||||
"hasJSActions",
|
}
|
||||||
this.fieldObjects.then(fieldObjects => {
|
|
||||||
return (
|
/**
|
||||||
(fieldObjects !== null &&
|
* @private
|
||||||
Object.values(fieldObjects).some(fieldObject =>
|
*/
|
||||||
fieldObject.some(object => object.actions !== null)
|
async _parseHasJSActions() {
|
||||||
)) ||
|
const [catalogJsActions, fieldObjects] = await Promise.all([
|
||||||
!!this.catalog.jsActions
|
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() {
|
get calculationOrderIds() {
|
||||||
|
@ -856,9 +856,6 @@ class Catalog {
|
|||||||
return shadow(this, "viewerPreferences", prefs);
|
return shadow(this, "viewerPreferences", prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* NOTE: "JavaScript" actions are, for now, handled by `get javaScript` below.
|
|
||||||
*/
|
|
||||||
get openAction() {
|
get openAction() {
|
||||||
const obj = this._catDict.get("OpenAction");
|
const obj = this._catDict.get("OpenAction");
|
||||||
const openAction = Object.create(null);
|
const openAction = Object.create(null);
|
||||||
@ -923,9 +920,9 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (javaScript === null) {
|
if (javaScript === null) {
|
||||||
javaScript = Object.create(null);
|
javaScript = new Map();
|
||||||
}
|
}
|
||||||
javaScript[name] = stringToPDFString(js);
|
javaScript.set(name, stringToPDFString(js));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj && obj.has("JavaScript")) {
|
if (obj && obj.has("JavaScript")) {
|
||||||
@ -955,23 +952,23 @@ class Catalog {
|
|||||||
return shadow(
|
return shadow(
|
||||||
this,
|
this,
|
||||||
"javaScript",
|
"javaScript",
|
||||||
javaScript ? Object.values(javaScript) : null
|
javaScript ? [...javaScript.values()] : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get jsActions() {
|
get jsActions() {
|
||||||
const js = this._collectJavaScript();
|
const javaScript = this._collectJavaScript();
|
||||||
let actions = collectActions(
|
let actions = collectActions(
|
||||||
this.xref,
|
this.xref,
|
||||||
this._catDict,
|
this._catDict,
|
||||||
DocumentActionEventType
|
DocumentActionEventType
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!actions && js) {
|
if (javaScript) {
|
||||||
actions = Object.create(null);
|
if (!actions) {
|
||||||
}
|
actions = Object.create(null);
|
||||||
if (actions && js) {
|
}
|
||||||
for (const [key, val] of Object.entries(js)) {
|
for (const [key, val] of javaScript) {
|
||||||
if (key in actions) {
|
if (key in actions) {
|
||||||
actions[key].push(val);
|
actions[key].push(val);
|
||||||
} else {
|
} else {
|
||||||
@ -979,7 +976,6 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return shadow(this, "jsActions", actions);
|
return shadow(this, "jsActions", actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1014,6 +1014,23 @@ describe("api", function () {
|
|||||||
.catch(done.fail);
|
.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) {
|
it("gets JSActions (none)", function (done) {
|
||||||
const promise = pdfDocument.getJSActions();
|
const promise = pdfDocument.getJSActions();
|
||||||
promise
|
promise
|
||||||
|
Loading…
Reference in New Issue
Block a user