1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Use a Map, rather than an Object, internally in the Catalog.openAction getter (PR 11644 follow-up)

This provides a work-around to avoid having to conditionally try to initialize the `openAction`-object in multiple places.
Given that `Object.fromEntries` doesn't seem to *guarantee* that a `null` prototype is used, we thus hack around that by using `Object.assign` with `Object.create(null)`.
This commit is contained in:
Jonas Jenwald 2020-10-28 14:04:09 +01:00
parent ea4d88a330
commit 9fc7cdcc9d
2 changed files with 16 additions and 14 deletions

View file

@ -25,6 +25,7 @@ import {
isBool,
isNum,
isString,
objectFromEntries,
PermissionFlag,
shadow,
stringToPDFString,
@ -786,7 +787,7 @@ class Catalog {
*/
get openAction() {
const obj = this._catDict.get("OpenAction");
let openAction = null;
const openActionMap = new Map();
if (isDict(obj)) {
// Convert the OpenAction dictionary into a format that works with
@ -798,23 +799,18 @@ class Catalog {
Catalog.parseDestDictionary({ destDict, resultObj });
if (Array.isArray(resultObj.dest)) {
if (!openAction) {
openAction = Object.create(null);
}
openAction.dest = resultObj.dest;
openActionMap.set("dest", resultObj.dest);
} else if (resultObj.action) {
if (!openAction) {
openAction = Object.create(null);
}
openAction.action = resultObj.action;
openActionMap.set("action", resultObj.action);
}
} else if (Array.isArray(obj)) {
if (!openAction) {
openAction = Object.create(null);
}
openAction.dest = obj;
openActionMap.set("dest", obj);
}
return shadow(this, "openAction", openAction);
return shadow(
this,
"openAction",
openActionMap.size > 0 ? objectFromEntries(openActionMap) : null
);
}
get attachments() {