Commit 4f6f8ef2 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added NaN handling to relational operators.

parent 9a7265be
......@@ -16,6 +16,9 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <math.h>
#include "jscript.h"
......@@ -2599,7 +2602,7 @@ HRESULT not_equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD f
}
/* ECMA-262 3rd Edition 11.8.5 */
static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
{
VARIANT l, r, ln, rn;
HRESULT hres;
......@@ -2615,7 +2618,7 @@ static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept
}
if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
*ret = strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0;
*ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
SysFreeString(V_BSTR(&l));
SysFreeString(V_BSTR(&r));
return S_OK;
......@@ -2629,10 +2632,14 @@ static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept
if(FAILED(hres))
return hres;
if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4)
*ret = V_I4(&ln) < V_I4(&rn);
else
*ret = num_val(&ln) < num_val(&rn);
if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
*ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
}else {
DOUBLE ld = num_val(&ln);
DOUBLE rd = num_val(&rn);
*ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
}
return S_OK;
}
......@@ -2651,7 +2658,7 @@ HRESULT less_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags,
if(FAILED(hres))
return hres;
hres = less_eval(ctx, &lval, &rval, ei, &b);
hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
VariantClear(&lval);
VariantClear(&rval);
if(FAILED(hres))
......@@ -2674,13 +2681,13 @@ HRESULT lesseq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags
if(FAILED(hres))
return hres;
hres = less_eval(ctx, &rval, &lval, ei, &b);
hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
VariantClear(&lval);
VariantClear(&rval);
if(FAILED(hres))
return hres;
return return_bool(ret, !b);
return return_bool(ret, b);
}
/* ECMA-262 3rd Edition 11.8.2 */
......@@ -2697,7 +2704,7 @@ HRESULT greater_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flag
if(FAILED(hres))
return hres;
hres = less_eval(ctx, &rval, &lval, ei, &b);
hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
VariantClear(&lval);
VariantClear(&rval);
if(FAILED(hres))
......@@ -2720,13 +2727,13 @@ HRESULT greatereq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD fl
if(FAILED(hres))
return hres;
hres = less_eval(ctx, &lval, &rval, ei, &b);
hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
VariantClear(&lval);
VariantClear(&rval);
if(FAILED(hres))
return hres;
return return_bool(ret, !b);
return return_bool(ret, b);
}
/* ECMA-262 3rd Edition 11.4.8 */
......
......@@ -801,4 +801,16 @@ ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
ok(isFinite() === false, "isFinite() !== false");
ok((1 < NaN) === false, "(1 < NaN) !== false");
ok((1 > NaN) === false, "(1 > NaN) !== false");
ok((1 <= NaN) === false, "(1 <= NaN) !== false");
ok((1 >= NaN) === false, "(1 >= NaN) !== false");
ok((NaN < 1) === false, "(NaN < 1) !== false");
ok((NaN > 1) === false, "(NaN > 1) !== false");
ok((NaN <= 1) === false, "(NaN <= 1) !== false");
ok((NaN >= 1) === false, "(NaN >= 1) !== false");
ok((Infinity < 2) === false, "(Infinity < 2) !== false");
ok((Infinity > 2) === true, "(Infinity > 2) !== true");
ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
reportSuccess();
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