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,
|
escapeString,
|
||||||
getModificationDate,
|
getModificationDate,
|
||||||
isString,
|
isString,
|
||||||
|
objectSize,
|
||||||
OPS,
|
OPS,
|
||||||
shadow,
|
shadow,
|
||||||
stringToPDFString,
|
stringToPDFString,
|
||||||
@ -1460,18 +1461,20 @@ class WidgetAnnotation extends Annotation {
|
|||||||
if (dict.has("AA")) {
|
if (dict.has("AA")) {
|
||||||
const additionalActions = dict.get("AA");
|
const additionalActions = dict.get("AA");
|
||||||
for (const key of additionalActions.getKeys()) {
|
for (const key of additionalActions.getKeys()) {
|
||||||
if (key in AnnotationActionEventType) {
|
const action = AnnotationActionEventType[key];
|
||||||
|
if (!action) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const actionDict = additionalActions.getRaw(key);
|
const actionDict = additionalActions.getRaw(key);
|
||||||
const parents = new RefSet();
|
const parents = new RefSet();
|
||||||
const list = [];
|
const list = [];
|
||||||
this._collectJS(actionDict, xref, list, parents);
|
this._collectJS(actionDict, xref, list, parents);
|
||||||
if (list.length > 0) {
|
if (list.length > 0) {
|
||||||
actions[AnnotationActionEventType[key]] = list;
|
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")) {
|
if (dict.has("A")) {
|
||||||
const actionDict = dict.get("A");
|
const actionDict = dict.get("A");
|
||||||
const parents = new RefSet();
|
const parents = new RefSet();
|
||||||
@ -1481,7 +1484,7 @@ class WidgetAnnotation extends Annotation {
|
|||||||
actions.Action = list;
|
actions.Action = list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return actions;
|
return objectSize(actions) > 0 ? actions : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFieldObject() {
|
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.
|
// Ensures that the returned Object has a `null` prototype.
|
||||||
function objectFromEntries(iterable) {
|
function objectFromEntries(iterable) {
|
||||||
return Object.assign(Object.create(null), Object.fromEntries(iterable));
|
return Object.assign(Object.create(null), Object.fromEntries(iterable));
|
||||||
@ -1040,6 +1044,7 @@ export {
|
|||||||
isString,
|
isString,
|
||||||
isSameOrigin,
|
isSameOrigin,
|
||||||
createValidAbsoluteUrl,
|
createValidAbsoluteUrl,
|
||||||
|
objectSize,
|
||||||
objectFromEntries,
|
objectFromEntries,
|
||||||
IsLittleEndianCached,
|
IsLittleEndianCached,
|
||||||
IsEvalSupportedCached,
|
IsEvalSupportedCached,
|
||||||
|
Loading…
Reference in New Issue
Block a user