From 18857df3e5094b6518c12ddd632f59a82fca1be6 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sat, 4 Oct 2014 12:24:04 +0200 Subject: allow only numbers to be reported as number (fix #458) --- threads.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 2b2c1f6..55d3aed 100644 --- a/threads.js +++ b/threads.js @@ -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)) { -- cgit v1.3.1