mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-31 11:27:21 +02:00
Shorten the Catalog.prototype.jsActions getter, and related code, a tiny bit
This is possible thanks to modern language features.
This commit is contained in:
parent
1609bd87c5
commit
8d1afad39b
@ -1241,13 +1241,9 @@ class Catalog {
|
|||||||
let javaScript = null;
|
let javaScript = null;
|
||||||
|
|
||||||
function appendIfJavaScriptDict(name, jsDict) {
|
function appendIfJavaScriptDict(name, jsDict) {
|
||||||
if (!(jsDict instanceof Dict)) {
|
if (!(jsDict instanceof Dict) || !isName(jsDict.get("S"), "JavaScript")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isName(jsDict.get("S"), "JavaScript")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let js = jsDict.get("JS");
|
let js = jsDict.get("JS");
|
||||||
if (js instanceof BaseStream) {
|
if (js instanceof BaseStream) {
|
||||||
js = js.getString();
|
js = js.getString();
|
||||||
@ -1260,7 +1256,7 @@ class Catalog {
|
|||||||
);
|
);
|
||||||
// Skip empty entries, similar to the `_collectJS` function.
|
// Skip empty entries, similar to the `_collectJS` function.
|
||||||
if (js) {
|
if (js) {
|
||||||
(javaScript ||= new Map()).set(name, js);
|
(javaScript ??= new Map()).set(name, js);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1291,14 +1287,10 @@ class Catalog {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (javaScript) {
|
if (javaScript) {
|
||||||
actions ||= Object.create(null);
|
actions ??= Object.create(null);
|
||||||
|
|
||||||
for (const [key, val] of javaScript) {
|
for (const [key, val] of javaScript) {
|
||||||
if (key in actions) {
|
(actions[key] ??= []).push(val);
|
||||||
actions[key].push(val);
|
|
||||||
} else {
|
|
||||||
actions[key] = [val];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return shadow(this, "jsActions", actions);
|
return shadow(this, "jsActions", actions);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user