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:
parent
8540b4cc76
commit
a1e5581a0b
@ -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() {
|
||||
|
@ -585,6 +585,10 @@ function string32(value) {
|
||||
);
|
||||
}
|
||||
|
||||
function objectSize(obj) {
|
||||
return Object.keys(obj).length;
|
||||
}
|
||||
|
||||
// Ensures that the returned Object has a `null` prototype.
|
||||
function objectFromEntries(iterable) {
|
||||
return Object.assign(Object.create(null), Object.fromEntries(iterable));
|
||||
@ -1040,6 +1044,7 @@ export {
|
||||
isString,
|
||||
isSameOrigin,
|
||||
createValidAbsoluteUrl,
|
||||
objectSize,
|
||||
objectFromEntries,
|
||||
IsLittleEndianCached,
|
||||
IsEvalSupportedCached,
|
||||
|
Loading…
Reference in New Issue
Block a user