script: safe compile

This commit is contained in:
bordun 2020-03-24 12:17:11 +01:00
parent 4afacdba02
commit e6f5945009
2 changed files with 12 additions and 5 deletions

View file

@ -91,7 +91,7 @@
- always hidden except in project tree
- `script` property must not be wrapped in a JS{{}} block anymore
- added `stateGet` and `stateSet` functions
- added `storage` object, proxy to the document's sessionStorage object (allows storing data that persist after page refresh, but not closing)
- added `storage` object, proxy to the document's localStorage object (allows storing data that persist after refresh/close (cleared with the browser's cache)
- added `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval` function proxies with an extra `id` argument (they clear automatically when called multiple times and upon widget removal. `id` is scoped to the widget)

View file

@ -65,10 +65,17 @@ class Script extends Widget {
if (this.getProp('event') === 'value') {
this.script = scriptVm.compile(this.getProp('script'), {
id: '',
value: 0
})
try {
this.script = scriptVm.compile(this.getProp('script'), {
id: '',
value: 0
})
} catch(err) {
var stackline = err.stack ? (err.stack.match(/>:([0-9]+):[0-9]+/) || '') : '',
line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - 2) : ''
console.log((this.getProp('id') || this.props.id) + '.script error:\n' + err + line)
this.script = ()=>{}
}
} else if (this.getProp('event') === 'keyboard' && this.getProp('keyBinding')) {