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

Change NameOrNumberTree.getAll to return a Map rather than an Object

Given that we're (almost) always iterating through the result of the `getAll`-calls, using a `Map` seems nicer overall since it's more suited to iteration compared to a regular Object.

Also, add a couple of `Dict`-checks in existing code touched by this patch, since it really cannot hurt to prevent *potential* errors in a corrupt PDF document.
This commit is contained in:
Jonas Jenwald 2021-04-21 12:14:33 +02:00
parent 57a1ea840f
commit 83f7009e4b
2 changed files with 21 additions and 23 deletions

View file

@ -32,9 +32,9 @@ class NameOrNumberTree {
}
getAll() {
const dict = Object.create(null);
const map = new Map();
if (!this.root) {
return dict;
return map;
}
const xref = this.xref;
// Reading Name/Number tree.
@ -59,13 +59,14 @@ class NameOrNumberTree {
continue;
}
const entries = obj.get(this._type);
if (Array.isArray(entries)) {
for (let i = 0, ii = entries.length; i < ii; i += 2) {
dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
}
if (!Array.isArray(entries)) {
continue;
}
for (let i = 0, ii = entries.length; i < ii; i += 2) {
map.set(xref.fetchIfRef(entries[i]), xref.fetchIfRef(entries[i + 1]));
}
}
return dict;
return map;
}
get(key) {