1
0
Fork 0
mirror of synced 2024-06-30 20:10:54 +12:00
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",
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
"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:memory": "jest --maxWorkers=2 --logHeapUsage --forceExit",
"test:watch": "jest --watch",

View file

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