Re-factor Catalog._collectJavaScript
to use a Map
rather than an Object
Given that this only an internal helper method, used by the `Catalog.{javaScript, jsActions}` getters, this change simplifies iteration of the returned data. We can also (slightly) re-factor the code of the `jsActions` getter, and remove an obsolete[1] JSDoc-comment from the `openAction` getter. --- [1] Not really relevant now that we've got proper scripting support.
This commit is contained in:
parent
6cf3070008
commit
4aa27cc645
@ -517,7 +517,6 @@ class Page {
|
||||
this.pageDict,
|
||||
PageActionEventType
|
||||
);
|
||||
|
||||
return shadow(this, "jsActions", actions);
|
||||
}
|
||||
}
|
||||
|
@ -856,9 +856,6 @@ class Catalog {
|
||||
return shadow(this, "viewerPreferences", prefs);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: "JavaScript" actions are, for now, handled by `get javaScript` below.
|
||||
*/
|
||||
get openAction() {
|
||||
const obj = this._catDict.get("OpenAction");
|
||||
const openAction = Object.create(null);
|
||||
@ -923,9 +920,9 @@ class Catalog {
|
||||
}
|
||||
|
||||
if (javaScript === null) {
|
||||
javaScript = Object.create(null);
|
||||
javaScript = new Map();
|
||||
}
|
||||
javaScript[name] = stringToPDFString(js);
|
||||
javaScript.set(name, stringToPDFString(js));
|
||||
}
|
||||
|
||||
if (obj && obj.has("JavaScript")) {
|
||||
@ -955,23 +952,23 @@ class Catalog {
|
||||
return shadow(
|
||||
this,
|
||||
"javaScript",
|
||||
javaScript ? Object.values(javaScript) : null
|
||||
javaScript ? [...javaScript.values()] : null
|
||||
);
|
||||
}
|
||||
|
||||
get jsActions() {
|
||||
const js = this._collectJavaScript();
|
||||
const javaScript = this._collectJavaScript();
|
||||
let actions = collectActions(
|
||||
this.xref,
|
||||
this._catDict,
|
||||
DocumentActionEventType
|
||||
);
|
||||
|
||||
if (!actions && js) {
|
||||
if (javaScript) {
|
||||
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) {
|
||||
actions[key].push(val);
|
||||
} else {
|
||||
@ -979,7 +976,6 @@ class Catalog {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return shadow(this, "jsActions", actions);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user