{"record":{"id":"1ec7ee0981902148","repo":"karatelabs/karate","slug":"name-is-not-a-valid-function-name-in-strict-mode","errorCode":null,"errorMessage":"'${name}' is not a valid function name in strict mode","messagePattern":"'(.+?)' is not a valid function name in strict mode","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":993,"sourceCode":"            Node child = fn.get(i);\n            if (!child.isToken() && child.type == NodeType.BLOCK) {\n                return hasUseStrictPrologue(child);\n            }\n        }\n        return false;\n    }\n\n    /** A strict function may not be named {@code eval} / {@code arguments}. The name\n     *  is the single IDENT token between {@code function} and the parameter list;\n     *  arrows and anonymous expressions reach FN_DECL_ARGS first and return. */\n    private static void checkFunctionName(Node fn) {\n        // an `async function` puts the contextual `async` IDENT before the keyword\n        for (int i = fn.async ? 1 : 0, n = fn.size(); i < n; i++) {\n            Node child = fn.get(i);\n            if (child.isToken()) {\n                if (child.token.type == IDENT) {\n                    if (isEvalOrArguments(child.getText())) {\n                        throw new ParserException(\n                                \"'\" + child.getText() + \"' is not a valid function name in strict mode\");\n                    }\n                    return;\n                }\n            } else if (child.type == NodeType.FN_DECL_ARGS) {\n                return; // reached the parameter list — function was anonymous\n            }\n        }\n    }\n\n    /**\n     * Formal-parameter early errors over the full BoundNames of the parameter list:\n     * <ul>\n     *   <li>Duplicate bound names are a SyntaxError when the list is non-simple (any\n     *       destructuring pattern, default, or rest element), when the function is an\n     *       arrow (UniqueFormalParameters), or when the function is strict. Plain\n     *       duplicate simple params in a sloppy non-arrow function stay legal.</li>\n     *   <li>Under strict, no bound name may be {@code eval} / {@code arguments}.</li>","sourceCodeStart":975,"sourceCodeEnd":1011,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L975-L1011","documentation":"In strict mode, `eval` and `arguments` may not be used as function names. Karate's JS parser checks the identifier following a (possibly `async`) `function` keyword and rejects it when the script is parsed as strict. This mirrors the ECMAScript spec's BindingIdentifier restrictions.","triggerScenarios":"Declaring `function eval() {}`, `function arguments() {}`, or their `async` equivalents in strict-mode Karate JS (e.g. scripts where strict mode applies via module/class code or Karate's parsing configuration).","commonSituations":"Porting old utility code that used `arguments` or `eval` as names; shadowing built-ins out of habit; code that worked in sloppy mode breaking when moved into a strict context (class body, module).","solutions":["Rename the function (e.g. `collectArguments`, `evalExpr`).","If the function genuinely wraps `arguments`, access the real `arguments` object inside a normal (non-arrow) function instead of naming a function `arguments`.","Avoid the strict context: declare at top level in sloppy mode if the library permits, but renaming is the correct fix."],"exampleFix":"// before\n\"use strict\";\nfunction eval(expr) { return karate.eval(expr); }\n// after\n\"use strict\";\nfunction evalExpr(expr) { return karate.eval(expr); }","handlingStrategy":"validation","validationCode":"function assertValidFnName(src) {\n  const m = src.match(/(async\\s+)?function\\s*[&*]?\\s*([\\w$]+)/);\n  if (m && /^(eval|arguments)$/.test(m[2])) {\n    throw new Error(\"'\" + m[2] + \"' cannot be a function name in strict mode\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  karate.eval(script);\n} catch (e) {\n  if (String(e.message).includes('is not a valid function name in strict mode')) {\n    const bad = String(e.message).match(/'(\\w+)'/)[1];\n    script = script.replace(new RegExp('\\\\b' + bad + '\\\\b', 'g'), bad + '_fn');\n  } else throw e;\n}","preventionTips":["Never name functions `eval` or `arguments` — regardless of mode.","Adopt naming conventions that avoid shadowing built-ins.","Lint embedded JS with a strict-mode parser before deployment."],"tags":["javascript","strict-mode","reserved-word","parser"],"backgroundTag":"invalid-identifier","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}