Ensure that the empty dictionary won't be accidentally modified

Currently there's nothing that prevents modification of the `Dict.empty` primitive, which obviously needs to be *truly* empty to prevent any future (hard to find) bugs.
This commit is contained in:
Jonas Jenwald 2020-09-14 13:21:55 +02:00
parent b0c7a74a0c
commit a531c98cd2

View File

@ -171,7 +171,14 @@ var Dict = (function DictClosure() {
}, },
}; };
Dict.empty = new Dict(null); Dict.empty = (function () {
const emptyDict = new Dict(null);
emptyDict.set = (key, value) => {
unreachable("Should not call `set` on the empty dictionary.");
};
return emptyDict;
})();
Dict.merge = function ({ xref, dictArray, mergeSubDicts = false }) { Dict.merge = function ({ xref, dictArray, mergeSubDicts = false }) {
const mergedDict = new Dict(xref); const mergedDict = new Dict(xref);