Fixing several function calls with no argument errors.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
+ Functions max and min now throw an error if no arguments are provided. + Objects called now throw an error if no argument is provided. + Fixing tokenizer's seek error reporting system (leads to very rare types of errors). + Removing expression simplifications that could make the app freeze when no arguments are provided to a function.
This commit is contained in:
parent
35ce1c4824
commit
9239eac78a
3 changed files with 22 additions and 15 deletions
|
@ -241,7 +241,10 @@ function evaluate(tokens, expr, values) {
|
||||||
nstack.push(f.apply(undefined, args));
|
nstack.push(f.apply(undefined, args));
|
||||||
} else if(f.execute) {
|
} else if(f.execute) {
|
||||||
// Objects & expressions execution
|
// Objects & expressions execution
|
||||||
nstack.push(f.execute.apply(f, args));
|
if(args.length >= 1)
|
||||||
|
nstack.push(f.execute.apply(f, args));
|
||||||
|
else
|
||||||
|
throw new Error(qsTranslate('error', 'In order to be executed, object %1 must have at least one argument.').arg(f))
|
||||||
} else {
|
} else {
|
||||||
throw new Error(qsTranslate('error', '%1 cannot be executed.').arg(f));
|
throw new Error(qsTranslate('error', '%1 cannot be executed.').arg(f));
|
||||||
}
|
}
|
||||||
|
@ -1614,16 +1617,20 @@ function arrayIndex(array, index) {
|
||||||
function max(array) {
|
function max(array) {
|
||||||
if (arguments.length === 1 && Array.isArray(array)) {
|
if (arguments.length === 1 && Array.isArray(array)) {
|
||||||
return Math.max.apply(Math, array);
|
return Math.max.apply(Math, array);
|
||||||
} else {
|
} else if(arguments.length >= 1) {
|
||||||
return Math.max.apply(Math, arguments);
|
return Math.max.apply(Math, arguments);
|
||||||
|
} else {
|
||||||
|
throw new EvalError(qsTranslate('error', 'Function %1 must have at least one argument.').arg('max'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function min(array) {
|
function min(array) {
|
||||||
if (arguments.length === 1 && Array.isArray(array)) {
|
if (arguments.length === 1 && Array.isArray(array)) {
|
||||||
return Math.min.apply(Math, array);
|
return Math.min.apply(Math, array);
|
||||||
} else {
|
} else if(arguments.length >= 1) {
|
||||||
return Math.min.apply(Math, arguments);
|
return Math.min.apply(Math, arguments);
|
||||||
|
} else {
|
||||||
|
throw new EvalError(qsTranslate('error', 'Function %1 must have at least one argument.').arg('min'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class InputExpression {
|
||||||
if(!this.atEnd() && this.peek() == char) {
|
if(!this.atEnd() && this.peek() == char) {
|
||||||
this.position++;
|
this.position++;
|
||||||
} else {
|
} else {
|
||||||
this.raise("Unexpected character " + peek() + ". Expected character " + char);
|
this.raise("Unexpected character " + this.peek() + ". Expected character " + char);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,16 +216,16 @@ function simplifyExpression(str) {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
// Simple simplifications
|
// Simple simplifications
|
||||||
[/(\s|^|\()0(\.0+)? \* (\([^)(]+\))/g, '$10'],
|
// [/(\s|^|\()0(\.0+)? \* (\([^)(]+\))/g, '$10'],
|
||||||
[/(\s|^|\()0(\.0+)? \* ([^)(+-]+)/g, '$10'],
|
// [/(\s|^|\()0(\.0+)? \* ([^)(+-]+)/g, '$10'],
|
||||||
[/(\([^)(]\)) \* 0(\.0+)?(\s|$|\))/g, '0$3'],
|
// [/(\([^)(]\)) \* 0(\.0+)?(\s|$|\))/g, '0$3'],
|
||||||
[/([^)(+-]) \* 0(\.0+)?(\s|$|\))/g, '0$3'],
|
// [/([^)(+-]) \* 0(\.0+)?(\s|$|\))/g, '0$3'],
|
||||||
[/(\s|^|\()1(\.0+)? (\*|\/) /g, '$1'],
|
// [/(\s|^|\()1(\.0+)? (\*|\/) /g, '$1'],
|
||||||
[/(\s|^|\()0(\.0+)? (\+|\-) /g, '$1'],
|
// [/(\s|^|\()0(\.0+)? (\+|\-) /g, '$1'],
|
||||||
[/ (\*|\/) 1(\.0+)?(\s|$|\))/g, '$3'],
|
// [/ (\*|\/) 1(\.0+)?(\s|$|\))/g, '$3'],
|
||||||
[/ (\+|\-) 0(\.0+)?(\s|$|\))/g, '$3'],
|
// [/ (\+|\-) 0(\.0+)?(\s|$|\))/g, '$3'],
|
||||||
[/(^| |\() /g, '$1'],
|
// [/(^| |\() /g, '$1'],
|
||||||
[/ ($|\))/g, '$1'],
|
// [/ ($|\))/g, '$1'],
|
||||||
]
|
]
|
||||||
|
|
||||||
// Replacements
|
// Replacements
|
||||||
|
@ -271,7 +271,7 @@ function makeExpressionReadable(str) {
|
||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
|
|
||||||
str = simplifyExpression(str)
|
// str = simplifyExpression(str)
|
||||||
// Replacements
|
// Replacements
|
||||||
for(var replacement of replacements)
|
for(var replacement of replacements)
|
||||||
while(replacement[0].test(str))
|
while(replacement[0].test(str))
|
||||||
|
|
Loading…
Reference in a new issue