fix: properly detect function literals (#5296)

This commit is contained in:
Yury Semikhatsky 2021-02-03 16:56:36 -08:00 committed by GitHub
parent 847bea2f83
commit 6ae2e576d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,7 @@ export default class UtilityScript {
const handles = argsAndHandles.slice(argCount);
const parameters = args.map(a => parseEvaluationResultValue(a, handles));
expression = expression.trim();
if (expression.startsWith('function ') || expression.startsWith('async function '))
if (/^(async)?\s*function(\s|\()/.test(expression))
expression = '(' + expression + ')';
let result = global.eval(expression);
if (isFunction === true) {