From 6be7814e559362312f4bfbc19c1a4e1287021ca2 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 12 Jan 2024 15:22:49 +0000 Subject: [PATCH] Copy context over, ignoring functions. --- packages/server/src/jsRunner.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/server/src/jsRunner.ts b/packages/server/src/jsRunner.ts index 08816aad42..5d3face3d8 100644 --- a/packages/server/src/jsRunner.ts +++ b/packages/server/src/jsRunner.ts @@ -33,6 +33,15 @@ export function init() { } } + const global = bbCtx.jsContext.global + for (const [key, value] of Object.entries(ctx)) { + if (typeof value === "function") { + // Can't copy functions into the isolate, so we just ignore them + continue + } + global.setSync(key, new ivm.ExternalCopy(value).copyInto()) + } + const script = bbCtx.jsIsolate.compileScriptSync(js) return script.runSync(bbCtx.jsContext, { timeout: env.JS_PER_EXECUTION_TIME_LIMIT_MS,