diff --git a/src/client/widgets/vm.mjs b/src/client/widgets/vm.mjs index 4a8b2cbd..24124ecd 100644 --- a/src/client/widgets/vm.mjs +++ b/src/client/widgets/vm.mjs @@ -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) {