Commit efda5561 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Correctly handle NaN and Infinity in to_int32 and to_uint32.

parent 8ea4102a
...@@ -467,7 +467,10 @@ HRESULT to_int32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, INT *ret) ...@@ -467,7 +467,10 @@ HRESULT to_int32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, INT *ret)
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
*ret = V_VT(&num) == VT_I4 ? V_I4(&num) : (INT)V_R8(&num); if(V_VT(&num) == VT_I4)
*ret = V_I4(&num);
else
*ret = isnan(V_R8(&num)) || isinf(V_R8(&num)) ? 0 : (INT)V_R8(&num);
return S_OK; return S_OK;
} }
...@@ -481,7 +484,10 @@ HRESULT to_uint32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, DWORD *ret) ...@@ -481,7 +484,10 @@ HRESULT to_uint32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, DWORD *ret)
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
*ret = V_VT(&num) == VT_I4 ? V_I4(&num) : (DWORD)V_R8(&num); if(V_VT(&num) == VT_I4)
*ret = V_I4(&num);
else
*ret = isnan(V_R8(&num)) || isinf(V_R8(&num)) ? 0 : (DWORD)V_R8(&num);
return S_OK; return S_OK;
} }
......
...@@ -346,6 +346,15 @@ tmp = -3.5 | 0; ...@@ -346,6 +346,15 @@ tmp = -3.5 | 0;
ok(tmp === -3, "-3.5 | 0 !== -3"); ok(tmp === -3, "-3.5 | 0 !== -3");
ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp)); ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
tmp = 0 | NaN;
ok(tmp === 0, "0 | NaN = " + tmp);
tmp = 0 | Infinity;
ok(tmp === 0, "0 | NaN = " + tmp);
tmp = 0 | (-Infinity);
ok(tmp === 0, "0 | NaN = " + tmp);
tmp = 10; tmp = 10;
ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26"); ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp)); ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
...@@ -380,6 +389,9 @@ ok(tmp === 2, "8 >> 2 = " + tmp); ...@@ -380,6 +389,9 @@ ok(tmp === 2, "8 >> 2 = " + tmp);
tmp = -64 >>> 4; tmp = -64 >>> 4;
ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp); ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
tmp = 4 >>> NaN;
ok(tmp === 4, "4 >>> NaN = " + tmp);
tmp = 10; tmp = 10;
ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8"); ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp)); ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment