From 8da243ecfe6e21bf70ab3fb4a255a2b555ef98c7 Mon Sep 17 00:00:00 2001 From: Evan <64989416+Ferotiq@users.noreply.github.com> Date: Fri, 4 Mar 2022 05:42:09 -0600 Subject: [PATCH] remove evals (#2624) --- .../src/scripts/elements/commandline-lists.ts | 24 +++++++++++++++++-- frontend/src/scripts/elements/commandline.ts | 5 +--- frontend/src/scripts/popups/simple-popups.ts | 1 - 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/frontend/src/scripts/elements/commandline-lists.ts b/frontend/src/scripts/elements/commandline-lists.ts index 3429e08e0..abd7bd67d 100644 --- a/frontend/src/scripts/elements/commandline-lists.ts +++ b/frontend/src/scripts/elements/commandline-lists.ts @@ -3215,8 +3215,28 @@ export function pushCurrent(val: MonkeyTypes.CommandsGroup): void { current.push(val); } -export function getList(list: string): MonkeyTypes.CommandsGroup { - return eval(list); +const listsObject = { + commandsChallenges, + commandsLanguages, + commandsDifficulty, + commandsLazyMode, + commandsPaceCaret, + commandsShowAvg, + commandsMinWpm, + commandsMinAcc, + commandsMinBurst, + commandsFunbox, + commandsConfidenceMode, + commandsStopOnError, + commandsLayouts, + commandsOppositeShiftMode, + commandsTags, +}; + +export type ListsObjectKeys = keyof typeof listsObject; + +export function getList(list: ListsObjectKeys): MonkeyTypes.CommandsGroup { + return listsObject[list]; } ConfigEvent.subscribe((eventKey, eventValue) => { diff --git a/frontend/src/scripts/elements/commandline.ts b/frontend/src/scripts/elements/commandline.ts index fa6080cee..d1a5cef8e 100644 --- a/frontend/src/scripts/elements/commandline.ts +++ b/frontend/src/scripts/elements/commandline.ts @@ -668,17 +668,14 @@ $(document).on("click", "#keymap .r5 .key-space", () => { $(document).on("click", "#testModesNotice .text-button", (event) => { const commands = CommandlineLists.getList( - $(event.currentTarget).attr("commands") as string + $(event.currentTarget).attr("commands") as CommandlineLists.ListsObjectKeys ); - const func = $(event.currentTarget).attr("function"); if (commands !== undefined) { if ($(event.currentTarget).attr("commands") === "commandsTags") { CommandlineLists.updateTagCommands(); } CommandlineLists.pushCurrent(commands); show(); - } else if (func != undefined) { - eval(func); } }); diff --git a/frontend/src/scripts/popups/simple-popups.ts b/frontend/src/scripts/popups/simple-popups.ts index 74ec39194..c44abdb81 100644 --- a/frontend/src/scripts/popups/simple-popups.ts +++ b/frontend/src/scripts/popups/simple-popups.ts @@ -566,7 +566,6 @@ list["clearTagPb"] = new SimplePopup( } else { Notifications.add("Something went wrong: " + response.message, -1); } - // console.log(`clearing for ${eval("this.parameters[0]")} ${eval("this.parameters[1]")}`); }, (thisPopup) => { thisPopup.text = `Are you sure you want to clear PB for tag ${thisPopup.parameters[1]}?`;