From 531f8336a875f0cca2ccb557472c7d23670e011a Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 16 Oct 2008 14:31:40 -0500 Subject: [PATCH] jscript: Added infinity and nan handling to str_to_number. --- dlls/jscript/jsutils.c | 30 +++++++++++++++--------------- dlls/jscript/tests/lang.js | 7 +++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index 2adfcb7acd..defddd4b0c 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -246,26 +246,26 @@ static HRESULT str_to_number(BSTR str, VARIANT *ret) while(isspaceW(*ptr)) ptr++; + if(*ptr == '-') { + neg = TRUE; + ptr++; + }else if(*ptr == '+') { + ptr++; + } + if(!strncmpW(ptr, infinityW, sizeof(infinityW)/sizeof(WCHAR))) { ptr += sizeof(infinityW)/sizeof(WCHAR); while(*ptr && isspaceW(*ptr)) ptr++; - if(*ptr) { - FIXME("NaN\n"); - return E_NOTIMPL; - } - - FIXME("inf\n"); - return E_NOTIMPL; + if(*ptr) + num_set_nan(ret); + else + num_set_inf(ret, !neg); + return S_OK; } - if(*ptr == '-') { - neg = TRUE; - ptr++; - }else if(*ptr == '+') { - ptr++; - }else if(*ptr == '0' && ptr[1] == 'x') { + if(*ptr == '0' && ptr[1] == 'x') { DWORD l = 0; ptr += 2; @@ -313,8 +313,8 @@ static HRESULT str_to_number(BSTR str, VARIANT *ret) ptr++; if(*ptr) { - FIXME("NaN\n"); - return E_NOTIMPL; + num_set_nan(ret); + return S_OK; } if(neg) diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index 2b92d68167..d66e887d8d 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -813,4 +813,11 @@ ok((Infinity < 2) === false, "(Infinity < 2) !== false"); ok((Infinity > 2) === true, "(Infinity > 2) !== true"); ok((-Infinity < 2) === true, "(-Infinity < 2) !== true"); +ok(isNaN(+"test") === true, "isNaN(+'test') !== true"); +ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true"); +ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true"); +ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity"); +ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity"); +ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity"); + reportSuccess(); -- 2.32.0.93.g670b81a890