advanced syntax/script: print widget id in console.log messages

This commit is contained in:
jean-emmanuel 2025-03-13 11:51:49 +01:00
parent e84c1d0435
commit 8655a2866c
2 changed files with 25 additions and 3 deletions

View file

@ -836,7 +836,15 @@ class Widget extends EventEmitter {
if (!this.parsers[code]) this.parsers[code] = vm.compile(code, defaultScope)
let r = this.parsers[code](jsScope, this.parsersLocalScope)
let r
vm.setWidget(this)
try {
r = this.parsers[code](jsScope, this.parsersLocalScope)
} catch (err) {
vm.setWidget()
throw err
}
vm.setWidget()
if (r === undefined) r = ''
@ -852,7 +860,15 @@ class Widget extends EventEmitter {
if (!this.parsers[code]) this.parsers[code] = vm.compile('return ' + code.trim(), defaultScope)
let r = this.parsers[code](jsScope, this.parsersLocalScope)
let r
vm.setWidget(this)
try {
r = this.parsers[code](jsScope, this.parsersLocalScope)
} catch (err) {
vm.setWidget()
throw err
}
vm.setWidget()
if (r === undefined) r = ''

View file

@ -75,7 +75,13 @@ class Vm {
registerGlobals() {
this.sandbox.contentWindow.console = console
this.sandbox.contentWindow.console = {
...console,
log: (msg)=>{
this.getWidget().log(msg)
}
}
this.sandbox.contentWindow.setTimeout =
this.sandbox.contentWindow.setInterval = ()=>{
throw 'setTimeout and setInterval can\'t be used in the JS sandbox'