Merge branch 'master' of github.com:Budibase/budibase into fix-context-in-js

This commit is contained in:
mike12345567 2024-02-20 11:10:52 +00:00
commit 3e21d97c47
2 changed files with 14 additions and 9 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "2.20.0", "version": "2.20.1",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*", "packages/*",

View File

@ -21,17 +21,22 @@ export function init() {
} }
try { try {
const bbCtx = context.getCurrentContext()! const bbCtx = context.getCurrentContext()
if (!bbCtx.vm) { const vm = bbCtx?.vm
bbCtx.vm = new IsolatedVM({ ? bbCtx.vm
: new IsolatedVM({
memoryLimit: env.JS_RUNNER_MEMORY_LIMIT, memoryLimit: env.JS_RUNNER_MEMORY_LIMIT,
invocationTimeout: env.JS_PER_INVOCATION_TIMEOUT_MS, invocationTimeout: env.JS_PER_INVOCATION_TIMEOUT_MS,
isolateAccumulatedTimeout: env.JS_PER_REQUEST_TIMEOUT_MS, isolateAccumulatedTimeout: env.JS_PER_REQUEST_TIMEOUT_MS,
}).withHelpers() }).withHelpers()
if (bbCtx) {
// If we have a context, we want to persist it to reuse the isolate
bbCtx.vm = vm
} }
const { helpers, ...rest } = ctx const { helpers, ...rest } = ctx
return bbCtx.vm.withContext(rest, () => bbCtx.vm!.execute(js)) return vm.withContext(rest, () => vm.execute(js))
} catch (error: any) { } catch (error: any) {
if (error.message === "Script execution timed out.") { if (error.message === "Script execution timed out.") {
throw new JsErrorTimeout() throw new JsErrorTimeout()