Use wrapper for scripts
This commit is contained in:
parent
e4285e30f1
commit
008b39abf4
|
@ -104,6 +104,11 @@ export class IsolatedVM implements VM {
|
|||
return this
|
||||
}
|
||||
|
||||
withContext(context: Record<string, any>) {
|
||||
this.#addToContext(context)
|
||||
return this
|
||||
}
|
||||
|
||||
execute(code: string): string {
|
||||
const perRequestLimit = this.#perRequestLimit
|
||||
|
||||
|
|
|
@ -4,17 +4,18 @@ import { IsolatedVM } from "../jsRunner/vm"
|
|||
const JS_TIMEOUT_MS = 1000
|
||||
class ScriptRunner {
|
||||
#code
|
||||
#vm
|
||||
|
||||
constructor(script: string, context: any) {
|
||||
this.#code = `let fn = () => {\n${script}\n}; results.out = fn();`
|
||||
this.#code = `(() => {${script}})();`
|
||||
this.#vm = new IsolatedVM({
|
||||
memoryLimit: env.JS_RUNNER_MEMORY_LIMIT,
|
||||
timeout: JS_TIMEOUT_MS,
|
||||
}).withContext(context)
|
||||
}
|
||||
|
||||
execute() {
|
||||
const vm = new IsolatedVM({
|
||||
memoryLimit: env.JS_RUNNER_MEMORY_LIMIT,
|
||||
timeout: JS_TIMEOUT_MS,
|
||||
}).withHelpers()
|
||||
const result = vm.execute(this.#code)
|
||||
const result = this.#vm.execute(this.#code)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue