From 62af51dcc7f0fe2819c7aebe583078132286aac5 Mon Sep 17 00:00:00 2001 From: bordun Date: Tue, 24 Mar 2020 12:17:11 +0100 Subject: [PATCH] script: safe compile --- CHANGELOG.md | 2 +- src/client/widgets/scripts/script.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 971809bc..23e4b032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/client/widgets/scripts/script.js b/src/client/widgets/scripts/script.js index b04b08ed..b5c543bd 100644 --- a/src/client/widgets/scripts/script.js +++ b/src/client/widgets/scripts/script.js @@ -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')) {