diff --git a/src/core/catalog.js b/src/core/catalog.js index 368725e95..75d54de7c 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -1241,13 +1241,9 @@ class Catalog { let javaScript = null; function appendIfJavaScriptDict(name, jsDict) { - if (!(jsDict instanceof Dict)) { + if (!(jsDict instanceof Dict) || !isName(jsDict.get("S"), "JavaScript")) { return; } - if (!isName(jsDict.get("S"), "JavaScript")) { - return; - } - let js = jsDict.get("JS"); if (js instanceof BaseStream) { js = js.getString(); @@ -1260,7 +1256,7 @@ class Catalog { ); // Skip empty entries, similar to the `_collectJS` function. if (js) { - (javaScript ||= new Map()).set(name, js); + (javaScript ??= new Map()).set(name, js); } } @@ -1291,14 +1287,10 @@ class Catalog { ); if (javaScript) { - actions ||= Object.create(null); + actions ??= Object.create(null); for (const [key, val] of javaScript) { - if (key in actions) { - actions[key].push(val); - } else { - actions[key] = [val]; - } + (actions[key] ??= []).push(val); } } return shadow(this, "jsActions", actions); diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 490262ebd..80642ee5a 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -803,27 +803,24 @@ class AnnotationElement { const fields = []; if (this._fieldObjects) { - const fieldObj = this._fieldObjects[name]; - if (fieldObj) { - for (const { page, id, exportValues } of fieldObj) { - if (page === -1) { - continue; - } - if (id === skipId) { - continue; - } - const exportValue = - typeof exportValues === "string" ? exportValues : null; + const fieldObj = this._fieldObjects[name] || []; - const domElement = document.querySelector( - `[data-element-id="${id}"]` - ); - if (domElement && !GetElementsByNameSet.has(domElement)) { - warn(`_getElementsByName - element not allowed: ${id}`); - continue; - } - fields.push({ id, exportValue, domElement }); + for (const { page, id, exportValues } of fieldObj) { + if (page === -1) { + continue; } + if (id === skipId) { + continue; + } + const exportValue = + typeof exportValues === "string" ? exportValues : null; + + const domElement = document.querySelector(`[data-element-id="${id}"]`); + if (domElement && !GetElementsByNameSet.has(domElement)) { + warn(`_getElementsByName - element not allowed: ${id}`); + continue; + } + fields.push({ id, exportValue, domElement }); } return fields; }