summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGubolin <gubolin@fantasymail.de>2014-10-04 12:24:04 +0200
committerGubolin <gubolin@fantasymail.de>2014-10-04 12:24:04 +0200
commit18857df3e5094b6518c12ddd632f59a82fca1be6 (patch)
treea29c5b7f8a5563de324289f9a011c2c9364d75ca
parentebbd0be87ac9d8b2ac80857089350cfdd11f27b4 (diff)
downloadsnap-18857df3e5094b6518c12ddd632f59a82fca1be6.tar.gz
snap-18857df3e5094b6518c12ddd632f59a82fca1be6.zip
allow only numbers to be reported as number (fix #458)issue_458
-rw-r--r--threads.js12
1 files changed, 11 insertions, 1 deletions
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)) {