This commit is contained in:
Sam Rose 2024-01-08 09:42:54 +00:00
parent 6eb19f40cf
commit 1abfba5253
No known key found for this signature in database
2 changed files with 10 additions and 6 deletions

View File

@ -15,6 +15,7 @@
"check:types": "tsc -p tsconfig.json --noEmit --paths null", "check:types": "tsc -p tsconfig.json --noEmit --paths null",
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput", "build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
"debug": "yarn build && node --expose-gc --inspect=9222 dist/index.js", "debug": "yarn build && node --expose-gc --inspect=9222 dist/index.js",
"jest": "NODE_OPTIONS=\"--no-node-snapshot $NODE_OPTIONS\" jest",
"test": "bash scripts/test.sh", "test": "bash scripts/test.sh",
"test:memory": "jest --maxWorkers=2 --logHeapUsage --forceExit", "test:memory": "jest --maxWorkers=2 --logHeapUsage --forceExit",
"test:watch": "jest --watch", "test:watch": "jest --watch",

View File

@ -1,4 +1,3 @@
import vm from "vm"
import ivm from "isolated-vm" import ivm from "isolated-vm"
import env from "./environment" import env from "./environment"
import { setJSRunner } from "@budibase/string-templates" import { setJSRunner } from "@budibase/string-templates"
@ -8,7 +7,7 @@ import tracer from "dd-trace"
type TrackerFn = <T>(f: () => T) => T type TrackerFn = <T>(f: () => T) => T
export function init() { export function init() {
setJSRunner((js: string, ctx: vm.Context) => { setJSRunner((js: string, ctx: Record<string, any>) => {
return tracer.trace("runJS", {}, span => { return tracer.trace("runJS", {}, span => {
const perRequestLimit = env.JS_PER_REQUEST_TIME_LIMIT_MS const perRequestLimit = env.JS_PER_REQUEST_TIME_LIMIT_MS
let track: TrackerFn = f => f() let track: TrackerFn = f => f()
@ -44,10 +43,14 @@ export function init() {
} else { } else {
value = ctx[key] value = ctx[key]
} }
jail.setSync(
key, if (typeof value === "function") {
new ivm.ExternalCopy(value).copyInto({ release: true }) js = value.toString() + "\n" + js
) continue
} else {
value = new ivm.ExternalCopy(value).copyInto({ release: true })
}
jail.setSync(key, value)
} }
const script = isolate.compileScriptSync(js) const script = isolate.compileScriptSync(js)