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

Ensure that Dict.set only accepts string keys

Trying to use a non-string `key` in a `Dict` is not intended, and would basically be an implementation error. Hence we can add a non-PRODUCTION check to enforce this, complementing the existing `value` check added in PR 11672.
This commit is contained in:
Jonas Jenwald 2022-02-22 15:52:12 +01:00
parent b2f6844ce3
commit a2f9031e9a
4 changed files with 20 additions and 7 deletions

View file

@ -198,11 +198,14 @@ class Dict {
set(key, value) {
if (
(typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")) &&
value === undefined
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
unreachable('Dict.set: The "value" cannot be undefined.');
if (typeof key !== "string") {
unreachable('Dict.set: The "key" must be a string.');
} else if (value === undefined) {
unreachable('Dict.set: The "value" cannot be undefined.');
}
}
this._map[key] = value;
}