1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Let Annotation._collectActions return null when no actions are present

Rather than returning an *empty* Object[1] we should be returning `null` instead, since that's consistent with existing API-functionality.
To avoid having to *manually* track if the Object is empty, this patch also introduces a small helper function to check its size.
This commit is contained in:
Jonas Jenwald 2020-10-29 14:17:32 +01:00
parent 8540b4cc76
commit a1e5581a0b
2 changed files with 18 additions and 10 deletions

View file

@ -25,6 +25,7 @@ import {
escapeString,
getModificationDate,
isString,
objectSize,
OPS,
shadow,
stringToPDFString,
@ -1460,18 +1461,20 @@ class WidgetAnnotation extends Annotation {
if (dict.has("AA")) {
const additionalActions = dict.get("AA");
for (const key of additionalActions.getKeys()) {
if (key in AnnotationActionEventType) {
const actionDict = additionalActions.getRaw(key);
const parents = new RefSet();
const list = [];
this._collectJS(actionDict, xref, list, parents);
if (list.length > 0) {
actions[AnnotationActionEventType[key]] = list;
}
const action = AnnotationActionEventType[key];
if (!action) {
continue;
}
const actionDict = additionalActions.getRaw(key);
const parents = new RefSet();
const list = [];
this._collectJS(actionDict, xref, list, parents);
if (list.length > 0) {
actions[action] = list;
}
}
}
// Collect the Action if any (we may have one on pushbutton)
// Collect the Action if any (we may have one on pushbutton).
if (dict.has("A")) {
const actionDict = dict.get("A");
const parents = new RefSet();
@ -1481,7 +1484,7 @@ class WidgetAnnotation extends Annotation {
actions.Action = list;
}
}
return actions;
return objectSize(actions) > 0 ? actions : null;
}
getFieldObject() {