jscript: Correctly handle NaN and Infinity in to_int32 and to_uint32.
This commit is contained in:
parent
8ea4102a6c
commit
efda5561d0
|
@ -467,7 +467,10 @@ HRESULT to_int32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, INT *ret)
|
|||
if(FAILED(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;
|
||||
}
|
||||
|
||||
|
@ -481,7 +484,10 @@ HRESULT to_uint32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, DWORD *ret)
|
|||
if(FAILED(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -346,6 +346,15 @@ tmp = -3.5 | 0;
|
|||
ok(tmp === -3, "-3.5 | 0 !== -3");
|
||||
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;
|
||||
ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
|
||||
ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
|
||||
|
@ -380,6 +389,9 @@ ok(tmp === 2, "8 >> 2 = " + tmp);
|
|||
tmp = -64 >>> 4;
|
||||
ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
|
||||
|
||||
tmp = 4 >>> NaN;
|
||||
ok(tmp === 4, "4 >>> NaN = " + tmp);
|
||||
|
||||
tmp = 10;
|
||||
ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
|
||||
ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
|
||||
|
|
Loading…
Reference in New Issue