script-vm: fix setTimeout/setInterval override

This commit is contained in:
jean-emmanuel 2025-12-30 17:34:05 +01:00
parent f4af775a98
commit 1aa3fbfef5

View file

@ -53,6 +53,19 @@ class Vm {
// global context
this.globals = {}
this.globals.console = {
...console,
log: (...msg)=>{
msg = msg.map(m => typeof m == 'object' ? JSON.stringify(m) : m)
this.getWidget().log(msg.join(' '))
}
}
this.globals.setTimeout =
this.globals.setInterval = ()=>{
throw 'setTimeout and setInterval can\'t be used in the JS sandbox'
}
this.registerGlobals()
// detach sandbox
@ -75,19 +88,6 @@ class Vm {
registerGlobals() {
this.globals.console = {
...console,
log: (...msg)=>{
msg = msg.map(m => typeof m == 'object' ? JSON.stringify(m) : m)
this.getWidget().log(msg.join(' '))
}
}
this.globals.setTimeout =
this.globals.setInterval = ()=>{
throw 'setTimeout and setInterval can\'t be used in the JS sandbox'
}
this.globals.globals = globals
for (var k in this.globals) {