Use proper access methods in Dict.merge, rather than modifying the _map field manually

This commit is contained in:
Jonas Jenwald 2026-03-17 12:00:35 +01:00
parent bda7456724
commit 6c6bb19324

View File

@ -236,7 +236,7 @@ class Dict {
if (!(dict instanceof Dict)) { if (!(dict instanceof Dict)) {
continue; continue;
} }
for (const [key, value] of dict._map) { for (const [key, value] of dict.getRawEntries()) {
let property = properties.get(key); let property = properties.get(key);
if (property === undefined) { if (property === undefined) {
property = []; property = [];
@ -252,20 +252,18 @@ class Dict {
} }
for (const [name, values] of properties) { for (const [name, values] of properties) {
if (values.length === 1 || !(values[0] instanceof Dict)) { if (values.length === 1 || !(values[0] instanceof Dict)) {
mergedDict._map.set(name, values[0]); mergedDict.set(name, values[0]);
continue; continue;
} }
const subDict = new Dict(xref); const subDict = new Dict(xref);
for (const dict of values) { for (const dict of values) {
for (const [key, value] of dict._map) { for (const [key, value] of dict.getRawEntries()) {
if (!subDict._map.has(key)) { subDict.setIfNotExists(key, value);
subDict._map.set(key, value);
}
} }
} }
if (subDict.size > 0) { if (subDict.size > 0) {
mergedDict._map.set(name, subDict); mergedDict.set(name, subDict);
} }
} }
properties.clear(); properties.clear();