aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-09-22 10:38:57 +1000
committerYuchen Pei <hi@ypei.me>2022-09-22 10:38:57 +1000
commit9cd506a06bd0fe86894a7bdb85062ec9a7ba4bc7 (patch)
tree19ccc8f3a0e0e5fa97e194948305d96e11651c03
parenta7c7afb09afe2d4e9e26fdeedaaefde6e3050188 (diff)
refactor: use set
-rw-r--r--main_background.js8
1 files changed, 4 insertions, 4 deletions
diff --git a/main_background.js b/main_background.js
index d37f2ba..51b645b 100644
--- a/main_background.js
+++ b/main_background.js
@@ -76,8 +76,8 @@ const RESERVED_OBJECTS = [
'browser', // only on firefox
'eval'
];
-const LOOPKEYS = { 'for': true, 'if': true, 'while': true, 'switch': true };
-const OPERATORS = { '||': true, '&&': true, '=': true, '==': true, '++': true, '--': true, '+=': true, '-=': true, '*': true };
+const LOOPKEYS = new Set(['for', 'if', 'while', 'switch']);
+const OPERATORS = new Set(['||', '&&', '=', '==', '++', '--', '+=', '-=', '*']);
// @license match, second and third capture groups are canonicalUrl
// and license name
const OPENING_LICENSE_RE = /\/[/*]\s*?(@license)\s+(\S+)\s+(\S+).*$/mi;
@@ -469,7 +469,7 @@ function fullEvaluate(script) {
function evaluateByTokenValue(toke) {
const value = toke.value;
- if (OPERATORS[value] !== undefined) {
+ if (OPERATORS.has(value)) {
// It's just an operator. Javascript doesn't have operator overloading so it must be some
// kind of primitive (I.e. a number)
} else {
@@ -500,7 +500,7 @@ function fullEvaluate(script) {
definesFunctions = true;
}
- if (LOOPKEYS[keyword] !== undefined) {
+ if (LOOPKEYS.has(keyword)) {
amtloops++;
if (amtloops > 3) {
dbg_print('%c NONTRIVIAL: Too many loops/conditionals.', 'color:red');