From 3aead4eae2f89fe8ae2bc550ed277f5ec166eace Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 18 Sep 2020 13:08:35 +0200 Subject: [PATCH] createEnum does not take an array --- src/matrix/e2ee/common.js | 2 +- src/utils/enum.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/matrix/e2ee/common.js b/src/matrix/e2ee/common.js index 190f2fa2..52995765 100644 --- a/src/matrix/e2ee/common.js +++ b/src/matrix/e2ee/common.js @@ -17,7 +17,7 @@ limitations under the License. import anotherjson from "../../../lib/another-json/index.js"; import {createEnum} from "../../utils/enum.js"; -export const DecryptionSource = createEnum(["Sync", "Timeline", "Retry"]); +export const DecryptionSource = createEnum("Sync", "Timeline", "Retry"); // use common prefix so it's easy to clear properties that are not e2ee related during session clear export const SESSION_KEY_PREFIX = "e2ee:"; diff --git a/src/utils/enum.js b/src/utils/enum.js index 733a548b..4defcfd7 100644 --- a/src/utils/enum.js +++ b/src/utils/enum.js @@ -17,6 +17,9 @@ limitations under the License. export function createEnum(...values) { const obj = {}; for (const value of values) { + if (typeof value !== "string") { + throw new Error("Invalid enum value name" + value?.toString()); + } obj[value] = value; } return Object.freeze(obj);