jsparser: some more guards

This commit is contained in:
jean-emmanuel 2019-04-07 10:51:36 +02:00
parent 7b6bff30b8
commit d4e3c8fa2d
2 changed files with 5 additions and 4 deletions

View file

@ -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)
}

View file

@ -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
}