Merge pull request #13070 from Budibase/remove-vm2-refs
Remove vm2 usage from script controllers
This commit is contained in:
commit
601c02a4ac
2 changed files with 20 additions and 5 deletions
|
@ -1,10 +1,11 @@
|
||||||
import { Ctx } from "@budibase/types"
|
import { Ctx } from "@budibase/types"
|
||||||
import { VM2 } from "../../jsRunner/vm"
|
import { IsolatedVM } from "../../jsRunner/vm"
|
||||||
|
|
||||||
export async function execute(ctx: Ctx) {
|
export async function execute(ctx: Ctx) {
|
||||||
const { script, context } = ctx.request.body
|
const { script, context } = ctx.request.body
|
||||||
const runner = new VM2(context)
|
const runner = new IsolatedVM().withContext(context)
|
||||||
const result = runner.execute(script)
|
|
||||||
|
const result = runner.execute(`(function(){\n${script}\n})();`)
|
||||||
ctx.body = result
|
ctx.body = result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
|
import { serializeError } from "serialize-error"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { JsErrorTimeout, setJSRunner } from "@budibase/string-templates"
|
import {
|
||||||
import { context } from "@budibase/backend-core"
|
JsErrorTimeout,
|
||||||
|
setJSRunner,
|
||||||
|
setOnErrorLog,
|
||||||
|
} from "@budibase/string-templates"
|
||||||
|
import { context, logging } from "@budibase/backend-core"
|
||||||
import tracer from "dd-trace"
|
import tracer from "dd-trace"
|
||||||
|
|
||||||
import { BuiltInVM, IsolatedVM } from "./vm"
|
import { BuiltInVM, IsolatedVM } from "./vm"
|
||||||
|
|
||||||
const USE_ISOLATED_VM = true
|
const USE_ISOLATED_VM = true
|
||||||
|
@ -41,4 +47,12 @@ export function init() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (env.LOG_JS_ERRORS) {
|
||||||
|
setOnErrorLog((error: Error) => {
|
||||||
|
logging.logWarn(
|
||||||
|
`Error while executing js: ${JSON.stringify(serializeError(error))}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue