Skip to content

Commit

Permalink
Merge pull request #13070 from Budibase/remove-vm2-refs
Browse files Browse the repository at this point in the history
Remove vm2 usage from script controllers
  • Loading branch information
adrinr authored Feb 19, 2024
2 parents a1af871 + 2042a95 commit 601c02a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/server/src/api/controllers/script.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Ctx } from "@budibase/types"
import { VM2 } from "../../jsRunner/vm"
import { IsolatedVM } from "../../jsRunner/vm"

export async function execute(ctx: Ctx) {
const { script, context } = ctx.request.body
const runner = new VM2(context)
const result = runner.execute(script)
const runner = new IsolatedVM().withContext(context)

const result = runner.execute(`(function(){\n${script}\n})();`)
ctx.body = result
}

Expand Down
18 changes: 16 additions & 2 deletions packages/server/src/jsRunner/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { serializeError } from "serialize-error"
import env from "../environment"
import { JsErrorTimeout, setJSRunner } from "@budibase/string-templates"
import { context } from "@budibase/backend-core"
import {
JsErrorTimeout,
setJSRunner,
setOnErrorLog,
} from "@budibase/string-templates"
import { context, logging } from "@budibase/backend-core"
import tracer from "dd-trace"

import { BuiltInVM, IsolatedVM } from "./vm"

const USE_ISOLATED_VM = true
Expand Down Expand Up @@ -41,4 +47,12 @@ export function init() {
}
})
})

if (env.LOG_JS_ERRORS) {
setOnErrorLog((error: Error) => {
logging.logWarn(
`Error while executing js: ${JSON.stringify(serializeError(error))}`
)
})
}
}

0 comments on commit 601c02a

Please # to comment.