Jacek Caban : jscript: Correctly handle NaN in to_integer.

Alexandre Julliard julliard at winehq.org
Fri Dec 4 09:11:27 CST 2009


Module: wine
Branch: master
Commit: ec769d2d95d69f87436f1a2ef73bbe4c4c2f0b50
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=ec769d2d95d69f87436f1a2ef73bbe4c4c2f0b50

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Dec  4 02:56:25 2009 +0100

jscript: Correctly handle NaN in to_integer.

---

 dlls/jscript/jsutils.c    |    8 ++++++--
 dlls/jscript/tests/api.js |    2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c
index 304980d..9e49cc7 100644
--- a/dlls/jscript/jsutils.c
+++ b/dlls/jscript/jsutils.c
@@ -449,10 +449,14 @@ HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret)
     if(FAILED(hres))
         return hres;
 
-    if(V_VT(&num) == VT_I4)
+    if(V_VT(&num) == VT_I4) {
         *ret = num;
-    else
+    }else if(isnan(V_R8(&num))) {
+        V_VT(ret) = VT_I4;
+        V_I4(ret) = 0;
+    }else {
         num_set_val(ret, V_R8(&num) >= 0.0 ? floor(V_R8(&num)) : -floor(-V_R8(&num)));
+    }
 
     return S_OK;
 }
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 42a79e8..80bdf88 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -231,6 +231,8 @@ tmp = "abc".charAt(-1);
 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
 tmp = "abc".charAt(0,2);
 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
+tmp = "abc".charAt(NaN);
+ok(tmp === "a", "'abc',charAt(NaN) = " + tmp);
 
 tmp = "abc".charCodeAt(0);
 ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);




More information about the wine-cvs mailing list