Jacek Caban : jscript: Properly support overloaded values in to_int32.

Alexandre Julliard julliard at winehq.org
Wed Apr 11 16:12:55 CDT 2018


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Apr 11 19:36:00 2018 +0200

jscript: Properly support overloaded values in to_int32.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/jscript/jsutils.c     | 9 ++++++++-
 dlls/jscript/tests/lang.js | 6 ++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c
index 4556ec4..9020611 100644
--- a/dlls/jscript/jsutils.c
+++ b/dlls/jscript/jsutils.c
@@ -659,11 +659,18 @@ HRESULT to_int32(script_ctx_t *ctx, jsval_t v, INT *ret)
     double n;
     HRESULT hres;
 
+    const double p32 = (double)0xffffffff + 1;
+
     hres = to_number(ctx, v, &n);
     if(FAILED(hres))
         return hres;
 
-    *ret = is_finite(n) ? n : 0;
+    if(is_finite(n))
+        n = n > 0 ? fmod(n, p32) : -fmod(-n, p32);
+    else
+        n = 0;
+
+    *ret = (UINT32)n;
     return S_OK;
 }
 
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index ef4c316..9350200 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -632,6 +632,12 @@ tmp = 10;
 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
 
+tmp = (123 * Math.pow(2,32) + 2) | 0;
+ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
+
+tmp = (-123 * Math.pow(2,32) + 2) | 0;
+ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
+
 tmp = 3 & 5;
 ok(tmp === 1, "3 & 5 !== 1");
 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));




More information about the wine-cvs mailing list