Add one second timeout to execution of JS bindings
This commit is contained in:
parent
d1916cfe49
commit
4d6d453676
|
@ -27,6 +27,16 @@ const getContextValue = (path, context) => {
|
||||||
return data
|
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
|
// Evaluates JS code against a certain context
|
||||||
module.exports.processJS = (handlebars, context) => {
|
module.exports.processJS = (handlebars, context) => {
|
||||||
try {
|
try {
|
||||||
|
@ -39,7 +49,7 @@ module.exports.processJS = (handlebars, context) => {
|
||||||
|
|
||||||
// Create a sandbox with out context and run the JS
|
// Create a sandbox with out context and run the JS
|
||||||
vm.createContext(sandboxContext)
|
vm.createContext(sandboxContext)
|
||||||
return vm.runInNewContext(js, sandboxContext)
|
return vm.runInNewContext(js, sandboxContext, { timeout: 1000 })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return "Error while executing JS"
|
return "Error while executing JS"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue