Merge pull request #13076 from Budibase/fix-automation-worker-js-run

Fix - bbCtx undefined in automation-worker
This commit is contained in:
Adria Navarro 2024-02-20 12:03:32 +01:00 committed by GitHub
commit 54e72c8e5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 3 deletions

View File

@ -21,9 +21,9 @@ export function init() {
} }
try { try {
const bbCtx = context.getCurrentContext()! const bbCtx = context.getCurrentContext()
let { vm } = bbCtx let vm = bbCtx?.vm
if (!vm) { if (!vm) {
// Can't copy the native helpers into the isolate. We just ignore them as they are handled properly from the helpersSource // Can't copy the native helpers into the isolate. We just ignore them as they are handled properly from the helpersSource
const { helpers, ...ctxToPass } = ctx const { helpers, ...ctxToPass } = ctx
@ -36,7 +36,10 @@ export function init() {
.withContext(ctxToPass) .withContext(ctxToPass)
.withHelpers() .withHelpers()
bbCtx.vm = vm if (bbCtx) {
// If we have a context, we want to persist it to reuse the isolate
bbCtx.vm = vm
}
} }
return vm.execute(js) return vm.execute(js)
} catch (error: any) { } catch (error: any) {