From a531c98cd2bdc53e62011b9836f34aea41975c55 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 14 Sep 2020 13:21:55 +0200 Subject: [PATCH] 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. --- src/core/primitives.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/primitives.js b/src/core/primitives.js index 39eddf984..a1e83b165 100644 --- a/src/core/primitives.js +++ b/src/core/primitives.js @@ -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 }) { const mergedDict = new Dict(xref);