Fix adding to context

This commit is contained in:
Adria Navarro 2024-02-08 13:51:36 +01:00
parent 2ffe3d7153
commit c57ccbc046
2 changed files with 10 additions and 3 deletions

View File

@ -13,11 +13,16 @@ export function init() {
let { vm } = bbCtx
if (!vm) {
// 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
vm = new IsolatedVM({
memoryLimit: env.JS_RUNNER_MEMORY_LIMIT,
timeout: env.JS_PER_EXECUTION_TIME_LIMIT_MS,
perRequestLimit: env.JS_PER_REQUEST_TIME_LIMIT_MS,
}).withHelpers()
})
.withContext(ctxToPass)
.withHelpers()
bbCtx.vm = vm
}

View File

@ -185,10 +185,12 @@ export class IsolatedVM implements VM {
private addToContext(context: Record<string, any>) {
for (let key in context) {
const value = context[key]
this.jail.setSync(
key,
context[key]
//new ivm.ExternalCopy(context[key]).copyInto({ release: true })
typeof value === "function"
? value
: new ivm.ExternalCopy(value).copyInto({ release: true })
)
}
}