From d4e3c8fa2de1121425e69559df8b4d9cba8075e6 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sun, 7 Apr 2019 10:51:36 +0200 Subject: [PATCH] jsparser: some more guards --- src/client/app/widgets/common/widget.js | 2 +- src/client/app/widgets/utils.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/client/app/widgets/common/widget.js b/src/client/app/widgets/common/widget.js index c9d599de..8ec2ea19 100644 --- a/src/client/app/widgets/common/widget.js +++ b/src/client/app/widgets/common/widget.js @@ -610,7 +610,7 @@ class Widget extends EventEmitter { }) } catch (err) { - var stackline = err.stack ? err.stack.match(/>:([0-9]+):[0-9]+/) : '', + 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') + '.' + propName + ': JS{{}} error:\n' + err + line) } diff --git a/src/client/app/widgets/utils.js b/src/client/app/widgets/utils.js index 1ac0a2d0..6e2f6293 100644 --- a/src/client/app/widgets/utils.js +++ b/src/client/app/widgets/utils.js @@ -120,12 +120,13 @@ module.exports = { loopProtect.hit = function(line){ throw 'Potential infinite loop found on line ' + line } - sandbox.contentWindow.parsers = {} + + sandbox.contentWindow.__parsers = {} sandbox.contentWindow.__protect = loopProtect function evaljs(code, defaultContext) { - sandbox.contentWindow.parsers[code] = sandbox.contentWindow.Function( + sandbox.contentWindow.__parsers[code] = sandbox.contentWindow.Function( loopProtect('"use strict";' + code) .replace(/;\n(if \(__protect.*break;)\n/g, ';$1') // prevent loop protect from breaking stack linenumber ) @@ -141,7 +142,7 @@ module.exports = { // evaluate try { - ret = sandbox.contentWindow.parsers[code]() + ret = sandbox.contentWindow.__parsers[code]() } catch(e) { err = e }