From 1c3069178fb3f100d05a528291889fbc80cc8079 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 24 Jan 2024 15:56:17 +0000 Subject: [PATCH] Attempt to fix tests. --- packages/server/src/jsRunner.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/server/src/jsRunner.ts b/packages/server/src/jsRunner.ts index 43a128f418..543441cb8d 100644 --- a/packages/server/src/jsRunner.ts +++ b/packages/server/src/jsRunner.ts @@ -74,16 +74,6 @@ export function init() { throw new Error(`No imports allowed. Required: ${specifier}`) }) - const perRequestLimit = env.JS_PER_REQUEST_TIME_LIMIT_MS - if (perRequestLimit) { - const cpuMs = Number(jsIsolate.cpuTime) / 1e6 - if (cpuMs > perRequestLimit) { - throw new Error( - `CPU time limit exceeded (${cpuMs}ms > ${perRequestLimit}ms)` - ) - } - } - for (const [key, value] of Object.entries(ctx)) { if (key === "helpers") { // Can't copy the native helpers into the isolate. We just ignore them as they are handled properly from the helpersSource @@ -97,6 +87,16 @@ export function init() { let { jsIsolate, jsContext, helpersModule } = bbCtx.isolateRefs! + const perRequestLimit = env.JS_PER_REQUEST_TIME_LIMIT_MS + if (perRequestLimit) { + const cpuMs = Number(jsIsolate.cpuTime) / 1e6 + if (cpuMs > perRequestLimit) { + throw new Error( + `CPU time limit exceeded (${cpuMs}ms > ${perRequestLimit}ms)` + ) + } + } + const script = jsIsolate.compileModuleSync( `import helpers from "compiled_module";${js};cb(run());`, {}