Browse Source

Add one second timeout to execution of JS bindings

pull/4089/head
Andrew Kingston 5 years ago
parent
commit
4d6d453676
  1. 12
      packages/string-templates/src/helpers/javascript.js

12
packages/string-templates/src/helpers/javascript.js

@ -27,6 +27,16 @@ const getContextValue = (path, context) => {
return data
}
// Node polyfill for base64 encoding
const btoa = plainText => {
return Buffer.from(plainText, "utf-8").toString("base64")
}
// Node polyfill for base64 decoding
const atob = base64 => {
return Buffer.from(base64, "base64").toString("utf-8")
}
// Evaluates JS code against a certain context
module.exports.processJS = (handlebars, context) => {
try {
@ -39,7 +49,7 @@ module.exports.processJS = (handlebars, context) => {
// Create a sandbox with out context and run the JS
vm.createContext(sandboxContext)
return vm.runInNewContext(js, sandboxContext)
return vm.runInNewContext(js, sandboxContext, { timeout: 1000 })
} catch (error) {
return "Error while executing JS"
}

Loading…
Cancel
Save