(sourceCode: string, parameterNames: string[] = [], options?: CreateOptions & { async?: boolean })
| 85 | createFunction<T = ((...args: any[]) => Promise<unknown>)>(sourceCode: string, parameterNames: string[], options: CreateOptions & { async: true }): ScriptError[] | T; |
| 86 | |
| 87 | createFunction<T = ((...args: any[]) => unknown)>(sourceCode: string, parameterNames: string[] = [], options?: CreateOptions & { async?: boolean }): ScriptError[] | T { |
| 88 | // insert defaults in options |
| 89 | options = { |
| 90 | lineOffset: 0, |
| 91 | columnOffset: 0, |
| 92 | filename: '<sandbox>', |
| 93 | ...options ? options : {} |
| 94 | }; |
| 95 | |
| 96 | let scriptSrc = sourceCode; |
| 97 | |
| 98 | scriptSrc = `${options.async ? 'async ' : ''}(${parameterNames.join(',')}) => { ${scriptSrc} }`; |
| 99 | |
| 100 | // create the script object, run it, and capture the generated function |
| 101 | return new Script(scriptSrc, options).runInContext(this.context, {}); |
| 102 | } |
| 103 | } |
| 104 |
no outgoing calls
no test coverage detected