diff options
| author | Gubolin <gubolin@fantasymail.de> | 2014-10-04 12:24:04 +0200 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2014-10-04 12:24:04 +0200 |
| commit | 18857df3e5094b6518c12ddd632f59a82fca1be6 (patch) | |
| tree | a29c5b7f8a5563de324289f9a011c2c9364d75ca | |
| parent | ebbd0be87ac9d8b2ac80857089350cfdd11f27b4 (diff) | |
| download | snap-18857df3e5094b6518c12ddd632f59a82fca1be6.tar.gz snap-18857df3e5094b6518c12ddd632f59a82fca1be6.zip | |
allow only numbers to be reported as number (fix #458)issue_458
| -rw-r--r-- | threads.js | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -118,6 +118,15 @@ function snapEquals(a, b) { return x === y; } +// stricter alternative to parseFloat +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat/ +function filterFloat(value) { + if(/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/ + .test(value)) + return Number(value); + return NaN; +} + // ThreadManager /////////////////////////////////////////////////////// function ThreadManager() { @@ -1847,13 +1856,14 @@ Process.prototype.reportIsA = function (thing, typeString) { Process.prototype.reportTypeOf = function (thing) { // answer a string denoting the argument's type var exp; + if (thing === null || (thing === undefined)) { return 'nothing'; } if (thing === true || (thing === false)) { return 'Boolean'; } - if (!isNaN(parseFloat(thing))) { + if (!isNaN(filterFloat(thing))) { return 'number'; } if (isString(thing)) { |
