Fix parseInt of NaN/Infinity (fix #309)

This commit is contained in:
Gordon Williams 2014-04-08 09:53:06 +01:00
parent 288a9a3ec1
commit 0abfb35bbe
3 changed files with 10 additions and 2 deletions

View File

@ -12,6 +12,7 @@
function.call can now have more than 4 arguments
Rewrite native function caller (fix #277)
Fix conversion of floats to booleans (fix #307)
Fix parseInt of NaN/Infinity (fix #309)
1v60 : Fix unary plug on variable not working (fix #268)
Added DNS with eth.setIP() for W5500

View File

@ -82,9 +82,13 @@ JsVar *jswrap_parseInt(JsVar *v, JsVar *radixVar) {
if (jsvIsNumeric(radixVar))
radix = (int)jsvGetInteger(radixVar);
if (jsvIsFloat(v) && !isfinite(jsvGetFloat(v)))
return jsvNewFromFloat(NAN);
// shortcut for values that are already numbers
if ((radix==0 || radix==10) && jsvIsNumeric(v))
if ((radix==0 || radix==10) && jsvIsNumeric(v)) {
return jsvNewFromInteger(jsvGetInteger(v));
}
// otherwise convert to string
char buffer[JS_NUMBER_BUFFER_SIZE];
jsvGetString(v, buffer, JS_NUMBER_BUFFER_SIZE);

View File

@ -10,6 +10,9 @@ var a = [
parseInt("0x100",16), 256,
parseInt("a",16), 10,
parseInt("A",16), 10,
parseInt(NaN), NaN,
parseInt(NaN,16), NaN,
parseInt(Infinity), NaN,
parseFloat("1.11"), 1.11,
parseFloat(".01"), 0.01,
parseFloat("100."), 100.0,
@ -21,4 +24,4 @@ var a = [
var result = 1;
for (var i=0;i<a.length;i+=2)
if (a[i]!=a[i+1]) result = 0;
if (a[i]!=a[i+1] && !(isNaN(a[i]) && isNaN(a[i+1]))) result = 0;