From 451169fb93a645bdf992ea9d727a561903f3854c Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 27 Mar 2012 11:28:51 +0200 Subject: [PATCH] jscript: Return double instead of VARIANT from to_number. --- dlls/jscript/array.c | 39 ++--- dlls/jscript/date.c | 322 ++++++++++++++++++----------------------- dlls/jscript/engine.c | 54 ++++--- dlls/jscript/error.c | 14 +- dlls/jscript/global.c | 18 +-- dlls/jscript/jscript.h | 9 +- dlls/jscript/jsutils.c | 83 ++++++----- dlls/jscript/math.c | 101 ++++++------- dlls/jscript/number.c | 17 ++- dlls/jscript/regexp.c | 12 +- 10 files changed, 314 insertions(+), 355 deletions(-) diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c index be98b8e975f..54dc3470433 100644 --- a/dlls/jscript/array.c +++ b/dlls/jscript/array.c @@ -127,20 +127,15 @@ static HRESULT Array_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP V_I4(retv) = This->length; break; case DISPATCH_PROPERTYPUT: { - VARIANT num; DOUBLE len = -1; DWORD i; HRESULT hres; - hres = to_number(ctx, get_arg(dp, 0), ei, &num); + hres = to_number(ctx, get_arg(dp, 0), ei, &len); if(FAILED(hres)) return hres; - if(V_VT(&num) == VT_I4) - len = V_I4(&num); - else - len = floor(V_R8(&num)); - + len = floor(len); if(len!=(DWORD)len) return throw_range_error(ctx, ei, JS_E_INVALID_LENGTH, NULL); @@ -573,7 +568,6 @@ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPA VARIANT *retv, jsexcept_t *ei) { jsdisp_t *arr, *jsthis; - VARIANT v; DOUBLE range; DWORD length, start, end, idx; HRESULT hres; @@ -585,15 +579,11 @@ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPA return hres; if(arg_cnt(dp)) { - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &range); if(FAILED(hres)) return hres; - if(V_VT(&v) == VT_I4) - range = V_I4(&v); - else - range = floor(V_R8(&v)); - + range = floor(range); if(-range>length || isnan(range)) start = 0; else if(range < 0) start = range+length; else if(range <= length) start = range; @@ -602,15 +592,11 @@ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPA else start = 0; if(arg_cnt(dp)>1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &range); if(FAILED(hres)) return hres; - if(V_VT(&v) == VT_I4) - range = V_I4(&v); - else - range = floor(V_R8(&v)); - + range = floor(range); if(-range>length) end = 0; else if(range < 0) end = range+length; else if(range <= length) end = range; @@ -623,6 +609,8 @@ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPA return hres; for(idx=start; idx 0.0 ? 1 : -1; + if(n == 0) + *cmp = 0; + *cmp = n > 0.0 ? 1 : -1; }else if(V_VT(v1) == VT_EMPTY) { *cmp = V_VT(v2) == VT_EMPTY ? 0 : 1; }else if(V_VT(v2) == VT_EMPTY) { diff --git a/dlls/jscript/date.c b/dlls/jscript/date.c index 6f9c800b723..4ca6e81df75 100644 --- a/dlls/jscript/date.c +++ b/dlls/jscript/date.c @@ -1366,7 +1366,7 @@ static HRESULT Date_getTimezoneOffset(script_ctx_t *ctx, vdisp_t *jsthis, WORD f static HRESULT Date_setTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double n; HRESULT hres; DateInstance *date; @@ -1378,11 +1378,11 @@ static HRESULT Date_setTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP if(!arg_cnt(dp)) return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &n); if(FAILED(hres)) return hres; - date->time = time_clip(num_val(&v)); + date->time = time_clip(n); if(retv) num_set_val(retv, date->time); @@ -1394,10 +1394,9 @@ static HRESULT Date_setTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP static HRESULT Date_setMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t; + double n, t; + HRESULT hres; TRACE("\n"); @@ -1407,13 +1406,13 @@ static HRESULT Date_setMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla if(!arg_cnt(dp)) return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &n); if(FAILED(hres)) return hres; t = local_time(date->time, date); t = make_date(day(t), make_time(hour_from_time(t), min_from_time(t), - sec_from_time(t), num_val(&v))); + sec_from_time(t), n)); date->time = time_clip(utc(t, date)); if(retv) @@ -1426,10 +1425,9 @@ static HRESULT Date_setMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla static HRESULT Date_setUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t; + double n, t; + HRESULT hres; TRACE("\n"); @@ -1439,13 +1437,13 @@ static HRESULT Date_setUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD if(!arg_cnt(dp)) return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &n); if(FAILED(hres)) return hres; t = date->time; t = make_date(day(t), make_time(hour_from_time(t), min_from_time(t), - sec_from_time(t), num_val(&v))); + sec_from_time(t), n)); date->time = time_clip(t); if(retv) @@ -1458,10 +1456,9 @@ static HRESULT Date_setUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD static HRESULT Date_setSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t, sec, ms; + double t, sec, ms; + HRESULT hres; TRACE("\n"); @@ -1473,18 +1470,17 @@ static HRESULT Date_setSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D t = local_time(date->time, date); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &sec); if(FAILED(hres)) return hres; - sec = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &ms); if(FAILED(hres)) return hres; - ms = num_val(&v); + }else { + ms = ms_from_time(t); } - else ms = ms_from_time(t); t = make_date(day(t), make_time(hour_from_time(t), min_from_time(t), sec, ms)); @@ -1500,10 +1496,9 @@ static HRESULT Date_setSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D static HRESULT Date_setUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t, sec, ms; + double t, sec, ms; + HRESULT hres; TRACE("\n"); @@ -1515,18 +1510,17 @@ static HRESULT Date_setUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags t = date->time; - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &sec); if(FAILED(hres)) return hres; - sec = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &ms); if(FAILED(hres)) return hres; - ms = num_val(&v); + }else { + ms = ms_from_time(t); } - else ms = ms_from_time(t); t = make_date(day(t), make_time(hour_from_time(t), min_from_time(t), sec, ms)); @@ -1542,10 +1536,9 @@ static HRESULT Date_setUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags static HRESULT Date_setMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t, min, sec, ms; + double t, min, sec, ms; + HRESULT hres; TRACE("\n"); @@ -1557,26 +1550,25 @@ static HRESULT Date_setMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D t = local_time(date->time, date); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &min); if(FAILED(hres)) return hres; - min = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &sec); if(FAILED(hres)) return hres; - sec = num_val(&v); + }else { + sec = sec_from_time(t); } - else sec = sec_from_time(t); if(arg_cnt(dp) > 2) { - hres = to_number(ctx, get_arg(dp, 2), ei, &v); + hres = to_number(ctx, get_arg(dp, 2), ei, &ms); if(FAILED(hres)) return hres; - ms = num_val(&v); + }else { + ms = ms_from_time(t); } - else ms = ms_from_time(t); t = make_date(day(t), make_time(hour_from_time(t), min, sec, ms)); @@ -1592,10 +1584,9 @@ static HRESULT Date_setMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D static HRESULT Date_setUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t, min, sec, ms; + double t, min, sec, ms; + HRESULT hres; TRACE("\n"); @@ -1607,26 +1598,25 @@ static HRESULT Date_setUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags t = date->time; - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &min); if(FAILED(hres)) return hres; - min = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &sec); if(FAILED(hres)) return hres; - sec = num_val(&v); + }else { + sec = sec_from_time(t); } - else sec = sec_from_time(t); if(arg_cnt(dp) > 2) { - hres = to_number(ctx, get_arg(dp, 2), ei, &v); + hres = to_number(ctx, get_arg(dp, 2), ei, &ms); if(FAILED(hres)) return hres; - ms = num_val(&v); + }else { + ms = ms_from_time(t); } - else ms = ms_from_time(t); t = make_date(day(t), make_time(hour_from_time(t), min, sec, ms)); @@ -1642,10 +1632,9 @@ static HRESULT Date_setUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags static HRESULT Date_setHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t, hour, min, sec, ms; + double t, hour, min, sec, ms; + HRESULT hres; TRACE("\n"); @@ -1657,34 +1646,33 @@ static HRESULT Date_setHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS t = local_time(date->time, date); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &hour); if(FAILED(hres)) return hres; - hour = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &min); if(FAILED(hres)) return hres; - min = num_val(&v); + }else { + min = min_from_time(t); } - else min = min_from_time(t); if(arg_cnt(dp) > 2) { - hres = to_number(ctx, get_arg(dp, 2), ei, &v); + hres = to_number(ctx, get_arg(dp, 2), ei, &sec); if(FAILED(hres)) return hres; - sec = num_val(&v); + }else { + sec = sec_from_time(t); } - else sec = sec_from_time(t); if(arg_cnt(dp) > 3) { - hres = to_number(ctx, get_arg(dp, 3), ei, &v); + hres = to_number(ctx, get_arg(dp, 3), ei, &ms); if(FAILED(hres)) return hres; - ms = num_val(&v); + }else { + ms = ms_from_time(t); } - else ms = ms_from_time(t); t = make_date(day(t), make_time(hour, min, sec, ms)); date->time = time_clip(utc(t, date)); @@ -1700,9 +1688,8 @@ static HRESULT Date_setUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, VARIANT *retv, jsexcept_t *ei) { DateInstance *date; - VARIANT v; + double t, hour, min, sec, ms; HRESULT hres; - DOUBLE t, hour, min, sec, ms; TRACE("\n"); @@ -1714,34 +1701,33 @@ static HRESULT Date_setUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, t = date->time; - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &hour); if(FAILED(hres)) return hres; - hour = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &min); if(FAILED(hres)) return hres; - min = num_val(&v); + }else { + min = min_from_time(t); } - else min = min_from_time(t); if(arg_cnt(dp) > 2) { - hres = to_number(ctx, get_arg(dp, 2), ei, &v); + hres = to_number(ctx, get_arg(dp, 2), ei, &sec); if(FAILED(hres)) return hres; - sec = num_val(&v); + }else { + sec = sec_from_time(t); } - else sec = sec_from_time(t); if(arg_cnt(dp) > 3) { - hres = to_number(ctx, get_arg(dp, 3), ei, &v); + hres = to_number(ctx, get_arg(dp, 3), ei, &ms); if(FAILED(hres)) return hres; - ms = num_val(&v); + }else { + ms = ms_from_time(t); } - else ms = ms_from_time(t); t = make_date(day(t), make_time(hour, min, sec, ms)); date->time = time_clip(t); @@ -1756,10 +1742,9 @@ static HRESULT Date_setUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, static HRESULT Date_setDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t; + double t, n; + HRESULT hres; TRACE("\n"); @@ -1769,13 +1754,12 @@ static HRESULT Date_setDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP if(!arg_cnt(dp)) return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &n); if(FAILED(hres)) return hres; t = local_time(date->time, date); - t = make_date(make_day(year_from_time(t), month_from_time(t), - num_val(&v)), time_within_day(t)); + t = make_date(make_day(year_from_time(t), month_from_time(t), n), time_within_day(t)); date->time = time_clip(utc(t, date)); if(retv) @@ -1788,10 +1772,9 @@ static HRESULT Date_setDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP static HRESULT Date_setUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t; + double t, n; + HRESULT hres; TRACE("\n"); @@ -1801,13 +1784,12 @@ static HRESULT Date_setUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D if(!arg_cnt(dp)) return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &n); if(FAILED(hres)) return hres; t = date->time; - t = make_date(make_day(year_from_time(t), month_from_time(t), - num_val(&v)), time_within_day(t)); + t = make_date(make_day(year_from_time(t), month_from_time(t), n), time_within_day(t)); date->time = time_clip(t); if(retv) @@ -1820,10 +1802,9 @@ static HRESULT Date_setUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D static HRESULT Date_setMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; DOUBLE t, month, ddate; + HRESULT hres; TRACE("\n"); @@ -1835,18 +1816,17 @@ static HRESULT Date_setMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS t = local_time(date->time, date); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &month); if(FAILED(hres)) return hres; - month = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &ddate); if(FAILED(hres)) return hres; - ddate = num_val(&v); + }else { + ddate = date_from_time(t); } - else ddate = date_from_time(t); t = make_date(make_day(year_from_time(t), month, ddate), time_within_day(t)); @@ -1862,10 +1842,9 @@ static HRESULT Date_setMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS static HRESULT Date_setUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t, month, ddate; + double t, month, ddate; + HRESULT hres; TRACE("\n"); @@ -1877,18 +1856,17 @@ static HRESULT Date_setUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, t = date->time; - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &month); if(FAILED(hres)) return hres; - month = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &ddate); if(FAILED(hres)) return hres; - ddate = num_val(&v); + }else { + ddate = date_from_time(t); } - else ddate = date_from_time(t); t = make_date(make_day(year_from_time(t), month, ddate), time_within_day(t)); @@ -1904,10 +1882,9 @@ static HRESULT Date_setUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, static HRESULT Date_setFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t, year, month, ddate; + double t, year, month, ddate; + HRESULT hres; TRACE("\n"); @@ -1919,26 +1896,25 @@ static HRESULT Date_setFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, t = local_time(date->time, date); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &year); if(FAILED(hres)) return hres; - year = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &month); if(FAILED(hres)) return hres; - month = num_val(&v); + }else { + month = month_from_time(t); } - else month = month_from_time(t); if(arg_cnt(dp) > 2) { - hres = to_number(ctx, get_arg(dp, 2), ei, &v); + hres = to_number(ctx, get_arg(dp, 2), ei, &ddate); if(FAILED(hres)) return hres; - ddate = num_val(&v); + }else { + ddate = date_from_time(t); } - else ddate = date_from_time(t); t = make_date(make_day(year, month, ddate), time_within_day(t)); date->time = time_clip(utc(t, date)); @@ -1953,10 +1929,9 @@ static HRESULT Date_setFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, static HRESULT Date_setUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - HRESULT hres; DateInstance *date; - DOUBLE t, year, month, ddate; + double t, year, month, ddate; + HRESULT hres; TRACE("\n"); @@ -1968,26 +1943,25 @@ static HRESULT Date_setUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag t = date->time; - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &year); if(FAILED(hres)) return hres; - year = num_val(&v); if(arg_cnt(dp) > 1) { - hres = to_number(ctx, get_arg(dp, 1), ei, &v); + hres = to_number(ctx, get_arg(dp, 1), ei, &month); if(FAILED(hres)) return hres; - month = num_val(&v); + }else { + month = month_from_time(t); } - else month = month_from_time(t); if(arg_cnt(dp) > 2) { - hres = to_number(ctx, get_arg(dp, 2), ei, &v); + hres = to_number(ctx, get_arg(dp, 2), ei, &ddate); if(FAILED(hres)) return hres; - ddate = num_val(&v); + }else { + ddate = date_from_time(t); } - else ddate = date_from_time(t); t = make_date(make_day(year, month, ddate), time_within_day(t)); date->time = time_clip(t); @@ -2030,7 +2004,6 @@ static HRESULT Date_setYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP { DateInstance *date; DOUBLE t, year; - VARIANT v; HRESULT hres; TRACE("\n"); @@ -2043,11 +2016,10 @@ static HRESULT Date_setYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP t = local_time(date->time, date); - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &year); if(FAILED(hres)) return hres; - year = num_val(&v); if(isnan(year)) { date->time = year; if(retv) @@ -2170,7 +2142,7 @@ static HRESULT create_date(script_ctx_t *ctx, jsdisp_t *object_prototype, DOUBLE return S_OK; } -static inline HRESULT date_parse(BSTR input, VARIANT *retv) { +static inline HRESULT date_parse(BSTR input, double *ret) { static const DWORD string_ids[] = { LOCALE_SMONTHNAME12, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME9, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME6, LOCALE_SMONTHNAME5, @@ -2191,15 +2163,15 @@ static inline HRESULT date_parse(BSTR input, VARIANT *retv) { DateInstance di; DWORD lcid_en; - if(retv) num_set_nan(retv); - input_len = SysStringLen(input); for(i=0; i1) { hres = to_number(ctx, get_arg(dp, 1), ei, &month); if(FAILED(hres)) return hres; - } - else { - V_VT(&month) = VT_R8; - V_R8(&month) = 0; + }else { + month = 0; } if(arg_no>2) { hres = to_number(ctx, get_arg(dp, 2), ei, &vdate); if(FAILED(hres)) return hres; - } - else { - V_VT(&vdate) = VT_R8; - V_R8(&vdate) = 1; + }else { + vdate = 1; } if(arg_no>3) { hres = to_number(ctx, get_arg(dp, 3), ei, &hours); if(FAILED(hres)) return hres; - } - else { - V_VT(&hours) = VT_R8; - V_R8(&hours) = 0; + }else { + hours = 0; } if(arg_no>4) { hres = to_number(ctx, get_arg(dp, 4), ei, &minutes); if(FAILED(hres)) return hres; - } - else { - V_VT(&minutes) = VT_R8; - V_R8(&minutes) = 0; + }else { + minutes = 0; } if(arg_no>5) { hres = to_number(ctx, get_arg(dp, 5), ei, &seconds); if(FAILED(hres)) return hres; - } - else { - V_VT(&seconds) = VT_R8; - V_R8(&seconds) = 0; + }else { + seconds = 0; } if(arg_no>6) { hres = to_number(ctx, get_arg(dp, 6), ei, &ms); if(FAILED(hres)) return hres; - } - else { - V_VT(&ms) = VT_R8; - V_R8(&ms) = 0; + } else { + ms = 0; } if(retv) { V_VT(retv) = VT_R8; V_R8(retv) = time_clip(make_date( - make_day(y, num_val(&month), num_val(&vdate)), - make_time(num_val(&hours), num_val(&minutes), - num_val(&seconds), num_val(&ms)))); + make_day(year, month, vdate), + make_time(hours, minutes,seconds, ms))); } return S_OK; @@ -2580,22 +2543,23 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, /* ECMA-262 3rd Edition 15.9.3.2 */ case 1: { - VARIANT prim, num; + VARIANT prim; + double n; hres = to_primitive(ctx, get_arg(dp,0), ei, &prim, NO_HINT); if(FAILED(hres)) return hres; if(V_VT(&prim) == VT_BSTR) - hres = date_parse(V_BSTR(&prim), &num); + hres = date_parse(V_BSTR(&prim), &n); else - hres = to_number(ctx, &prim, ei, &num); + hres = to_number(ctx, &prim, ei, &n); VariantClear(&prim); if(FAILED(hres)) return hres; - hres = create_date(ctx, NULL, time_clip(num_val(&num)), &date); + hres = create_date(ctx, NULL, time_clip(n), &date); if(FAILED(hres)) return hres; break; diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 892cb1e75b6..c4259b9349d 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -148,12 +148,17 @@ static void stack_popn(exec_ctx_t *ctx, unsigned n) static HRESULT stack_pop_number(exec_ctx_t *ctx, VARIANT *r) { VARIANT *v; + double n; HRESULT hres; v = stack_pop(ctx); - hres = to_number(ctx->script, v, ctx->ei, r); + hres = to_number(ctx->script, v, ctx->ei, &n); VariantClear(v); - return hres; + if(FAILED(hres)) + return hres; + + num_set_val(r, n); + return S_OK; } static HRESULT stack_pop_object(exec_ctx_t *ctx, IDispatch **r) @@ -1526,13 +1531,13 @@ static HRESULT add_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcep if(V_VT(&r) != VT_BSTR) SysFreeString(rstr); }else { - VARIANT nl, nr; + double nl, nr; hres = to_number(ctx, &l, ei, &nl); if(SUCCEEDED(hres)) { hres = to_number(ctx, &r, ei, &nr); if(SUCCEEDED(hres)) - num_set_val(retv, num_val(&nl) + num_val(&nr)); + num_set_val(retv, nl + nr); } } @@ -1872,18 +1877,19 @@ static HRESULT interp_minus(exec_ctx_t *ctx) /* ECMA-262 3rd Edition 11.4.6 */ static HRESULT interp_tonum(exec_ctx_t *ctx) { - VARIANT *v, num; + VARIANT *v; + double n; HRESULT hres; TRACE("\n"); v = stack_pop(ctx); - hres = to_number(ctx->script, v, ctx->ei, &num); + hres = to_number(ctx->script, v, ctx->ei, &n); VariantClear(v); if(FAILED(hres)) return hres; - return stack_push(ctx, &num); + return stack_push_number(ctx, n); } /* ECMA-262 3rd Edition 11.3.1 */ @@ -1903,11 +1909,12 @@ static HRESULT interp_postinc(exec_ctx_t *ctx) hres = disp_propget(ctx->script, obj, id, &v, ctx->ei); if(SUCCEEDED(hres)) { - VARIANT n, inc; + VARIANT inc; + double n; hres = to_number(ctx->script, &v, ctx->ei, &n); if(SUCCEEDED(hres)) { - num_set_val(&inc, num_val(&n)+(double)arg); + num_set_val(&inc, n+(double)arg); hres = disp_propput(ctx->script, obj, id, &inc, ctx->ei); } if(FAILED(hres)) @@ -1937,12 +1944,12 @@ static HRESULT interp_preinc(exec_ctx_t *ctx) hres = disp_propget(ctx->script, obj, id, &v, ctx->ei); if(SUCCEEDED(hres)) { - VARIANT n; + double n; hres = to_number(ctx->script, &v, ctx->ei, &n); VariantClear(&v); if(SUCCEEDED(hres)) { - num_set_val(&v, num_val(&n)+(double)arg); + num_set_val(&v, n+(double)arg); hres = disp_propput(ctx->script, obj, id, &v, ctx->ei); } } @@ -1980,23 +1987,31 @@ static HRESULT equal_values(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jse if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) { VARIANT v; + double n; HRESULT hres; - hres = to_number(ctx, lval, ei, &v); + hres = to_number(ctx, lval, ei, &n); if(FAILED(hres)) return hres; + /* FIXME: optimize */ + num_set_val(&v, n); + return equal_values(ctx, &v, rval, ei, ret); } if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) { VARIANT v; + double n; HRESULT hres; - hres = to_number(ctx, rval, ei, &v); + hres = to_number(ctx, rval, ei, &n); if(FAILED(hres)) return hres; + /* FIXME: optimize */ + num_set_val(&v, n); + return equal_values(ctx, lval, &v, ei, ret); } @@ -2138,7 +2153,8 @@ static HRESULT interp_neq2(exec_ctx_t *ctx) /* ECMA-262 3rd Edition 11.8.5 */ static HRESULT less_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret) { - VARIANT l, r, ln, rn; + double ln, rn; + VARIANT l, r; HRESULT hres; hres = to_primitive(ctx, lval, ei, &l, NO_HINT); @@ -2166,15 +2182,7 @@ static HRESULT less_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL g if(FAILED(hres)) return hres; - 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); - } - + *ret = !isnan(ln) && !isnan(rn) && ((ln < rn) ^ greater); return S_OK; } diff --git a/dlls/jscript/error.c b/dlls/jscript/error.c index 6adf60a3acd..d242ce3fc1a 100644 --- a/dlls/jscript/error.c +++ b/dlls/jscript/error.c @@ -234,18 +234,16 @@ static HRESULT error_constr(script_ctx_t *ctx, WORD flags, DISPPARAMS *dp, HRESULT hres; if(arg_cnt(dp)) { - VARIANT numv; + double n; - hres = to_number(ctx, get_arg(dp, 0), ei, &numv); - if(FAILED(hres) || (V_VT(&numv)==VT_R8 && isnan(V_R8(&numv)))) + hres = to_number(ctx, get_arg(dp, 0), ei, &n); + if(FAILED(hres)) /* FIXME: really? */ + n = ret_nan(); + if(isnan(n)) hres = to_string(ctx, get_arg(dp, 0), ei, &msg); - else if(V_VT(&numv) == VT_I4) - num = V_I4(&numv); - else - num = V_R8(&numv); - if(FAILED(hres)) return hres; + num = n; } if(arg_cnt(dp)>1 && !msg) { diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index 4ed39402147..d0b7a9bb10b 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -386,21 +386,19 @@ static HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS static HRESULT JSGlobal_isNaN(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT_BOOL ret = VARIANT_FALSE; - VARIANT num; + VARIANT_BOOL ret = VARIANT_TRUE; + double n; HRESULT hres; TRACE("\n"); if(arg_cnt(dp)) { - hres = to_number(ctx, get_arg(dp,0), ei, &num); + hres = to_number(ctx, get_arg(dp,0), ei, &n); if(FAILED(hres)) return hres; - if(V_VT(&num) == VT_R8 && isnan(V_R8(&num))) - ret = VARIANT_TRUE; - }else { - ret = VARIANT_TRUE; + if(!isnan(n)) + ret = VARIANT_FALSE; } if(retv) { @@ -419,13 +417,13 @@ static HRESULT JSGlobal_isFinite(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, TRACE("\n"); if(arg_cnt(dp)) { - VARIANT num; + double n; - hres = to_number(ctx, get_arg(dp,0), ei, &num); + hres = to_number(ctx, get_arg(dp,0), ei, &n); if(FAILED(hres)) return hres; - if(V_VT(&num) != VT_R8 || (!isinf(V_R8(&num)) && !isnan(V_R8(&num)))) + if(!isinf(n) && !isnan(n)) ret = VARIANT_TRUE; } diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index cd8ec4578c3..fbe3142ec63 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -253,7 +253,7 @@ typedef enum { HRESULT to_primitive(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*, hint_t) DECLSPEC_HIDDEN; HRESULT to_boolean(VARIANT*,VARIANT_BOOL*) DECLSPEC_HIDDEN; -HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*) DECLSPEC_HIDDEN; +HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,double*) DECLSPEC_HIDDEN; HRESULT to_integer(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*) DECLSPEC_HIDDEN; HRESULT to_int32(script_ctx_t*,VARIANT*,jsexcept_t*,INT*) DECLSPEC_HIDDEN; HRESULT to_uint32(script_ctx_t*,VARIANT*,jsexcept_t*,DWORD*) DECLSPEC_HIDDEN; @@ -451,6 +451,13 @@ static inline void num_set_inf(VARIANT *v, BOOL positive) #endif } +static inline DOUBLE ret_inf(void) +{ + VARIANT v; + num_set_inf(&v, TRUE); + return V_R8(&v); +} + static inline void var_set_jsdisp(VARIANT *v, jsdisp_t *jsdisp) { V_VT(v) = VT_DISPATCH; diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index b9a35dbcd2d..564dba69f8d 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -312,7 +312,7 @@ static int hex_to_int(WCHAR c) } /* ECMA-262 3rd Edition 9.3.1 */ -static HRESULT str_to_number(BSTR str, VARIANT *ret) +static HRESULT str_to_number(BSTR str, double *ret) { const WCHAR *ptr = str; BOOL neg = FALSE; @@ -336,9 +336,9 @@ static HRESULT str_to_number(BSTR str, VARIANT *ret) ptr++; if(*ptr) - num_set_nan(ret); + *ret = ret_nan(); else - num_set_inf(ret, !neg); + *ret = neg ? -ret_inf() : ret_inf(); return S_OK; } @@ -351,7 +351,7 @@ static HRESULT str_to_number(BSTR str, VARIANT *ret) ptr++; } - num_set_val(ret, d); + *ret = d; return S_OK; } @@ -390,31 +390,32 @@ static HRESULT str_to_number(BSTR str, VARIANT *ret) ptr++; if(*ptr) { - num_set_nan(ret); + *ret = ret_nan(); return S_OK; } if(neg) d = -d; - num_set_val(ret, d); + *ret = d; return S_OK; } /* ECMA-262 3rd Edition 9.3 */ -HRESULT to_number(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret) +HRESULT to_number(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, double *ret) { switch(V_VT(v)) { case VT_EMPTY: - num_set_nan(ret); + *ret = ret_nan(); break; case VT_NULL: - V_VT(ret) = VT_I4; - V_I4(ret) = 0; + *ret = 0; break; case VT_I4: + *ret = V_I4(v); + break; case VT_R8: - *ret = *v; + *ret = V_R8(v); break; case VT_BSTR: return str_to_number(V_BSTR(v), ret); @@ -431,8 +432,7 @@ HRESULT to_number(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret) return hres; } case VT_BOOL: - V_VT(ret) = VT_I4; - V_I4(ret) = V_BOOL(v) ? 1 : 0; + *ret = V_BOOL(v) ? 1 : 0; break; default: FIXME("unimplemented for vt %d\n", V_VT(v)); @@ -445,20 +445,23 @@ HRESULT to_number(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret) /* ECMA-262 3rd Edition 9.4 */ HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret) { - VARIANT num; + double n; HRESULT hres; - hres = to_number(ctx, v, ei, &num); + if(V_VT(v) == VT_I4) { + *ret = *v; + return S_OK; + } + + hres = to_number(ctx, v, ei, &n); if(FAILED(hres)) return hres; - if(V_VT(&num) == VT_I4) { - *ret = num; - }else if(isnan(V_R8(&num))) { + if(isnan(n)) { 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))); + num_set_val(ret, n >= 0.0 ? floor(n) : -floor(-n)); } return S_OK; @@ -467,34 +470,38 @@ HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret) /* ECMA-262 3rd Edition 9.5 */ HRESULT to_int32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, INT *ret) { - VARIANT num; + double n; HRESULT hres; - hres = to_number(ctx, v, ei, &num); + if(V_VT(v) == VT_I4) { + *ret = V_I4(v); + return S_OK; + } + + hres = to_number(ctx, v, ei, &n); if(FAILED(hres)) return hres; - 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); + *ret = isnan(n) || isinf(n) ? 0 : n; return S_OK; } /* ECMA-262 3rd Edition 9.6 */ HRESULT to_uint32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, DWORD *ret) { - VARIANT num; + double n; HRESULT hres; - hres = to_number(ctx, v, ei, &num); + if(V_VT(v) == VT_I4) { + *ret = V_I4(v); + return S_OK; + } + + hres = to_number(ctx, v, ei, &n); if(FAILED(hres)) return hres; - 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); + *ret = isnan(n) || isinf(n) ? 0 : n; return S_OK; } @@ -679,17 +686,19 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY } break; } - case VT_R8: - hres = to_number(ctx, src, &ei, dst); - if(SUCCEEDED(hres) && V_VT(dst) == VT_I4) - V_R8(dst) = V_I4(dst); + case VT_R8: { + double n; + hres = to_number(ctx, src, &ei, &n); + if(SUCCEEDED(hres)) + V_R8(dst) = n; break; + } case VT_R4: { - VARIANT n; + double n; hres = to_number(ctx, src, &ei, &n); if(SUCCEEDED(hres)) - V_R4(dst) = num_val(&n); + V_R4(dst) = n; break; } case VT_BOOL: { diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c index b28431eec0d..9c17967edd8 100644 --- a/dlls/jscript/math.c +++ b/dlls/jscript/math.c @@ -61,8 +61,7 @@ static const WCHAR tanW[] = {'t','a','n',0}; static HRESULT Math_abs(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; - DOUBLE d; + double d; HRESULT hres; TRACE("\n"); @@ -73,11 +72,10 @@ static HRESULT Math_abs(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &d); if(FAILED(hres)) return hres; - d = num_val(&v); if(retv) num_set_val(retv, d < 0.0 ? -d : d); return S_OK; @@ -86,7 +84,7 @@ static HRESULT Math_abs(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA static HRESULT Math_acos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -96,12 +94,11 @@ static HRESULT Math_acos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPAR return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; if(retv) { - DOUBLE x = num_val(&v); if(x < -1.0 || x > 1.0) num_set_nan(retv); else @@ -113,7 +110,7 @@ static HRESULT Math_acos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPAR static HRESULT Math_asin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -123,12 +120,11 @@ static HRESULT Math_asin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPAR return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; if(retv) { - DOUBLE x = num_val(&v); if(x < -1.0 || x > 1.0) num_set_nan(retv); else @@ -140,7 +136,7 @@ static HRESULT Math_asin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPAR static HRESULT Math_atan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -150,18 +146,18 @@ static HRESULT Math_atan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPAR return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; - if(retv) num_set_val(retv, atan(num_val(&v))); + if(retv) num_set_val(retv, atan(x)); return S_OK; } static HRESULT Math_atan2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v1, v2; + double x, y; HRESULT hres; TRACE("\n"); @@ -171,15 +167,15 @@ static HRESULT Math_atan2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v1); + hres = to_number(ctx, get_arg(dp, 0), ei, &y); if(FAILED(hres)) return hres; - hres = to_number(ctx, get_arg(dp, 1), ei, &v2); + hres = to_number(ctx, get_arg(dp, 1), ei, &x); if(FAILED(hres)) return hres; - if(retv) num_set_val(retv, atan2(num_val(&v1), num_val(&v2))); + if(retv) num_set_val(retv, atan2(y, x)); return S_OK; } @@ -187,7 +183,7 @@ static HRESULT Math_atan2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA static HRESULT Math_ceil(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -198,19 +194,19 @@ static HRESULT Math_ceil(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPAR return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; if(retv) - num_set_val(retv, ceil(num_val(&v))); + num_set_val(retv, ceil(x)); return S_OK; } static HRESULT Math_cos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -220,18 +216,18 @@ static HRESULT Math_cos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; - if(retv) num_set_val(retv, cos(num_val(&v))); + if(retv) num_set_val(retv, cos(x)); return S_OK; } static HRESULT Math_exp(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -241,18 +237,18 @@ static HRESULT Math_exp(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; - if(retv) num_set_val(retv, exp(num_val(&v))); + if(retv) num_set_val(retv, exp(x)); return S_OK; } static HRESULT Math_floor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -263,19 +259,19 @@ static HRESULT Math_floor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; if(retv) - num_set_val(retv, floor(num_val(&v))); + num_set_val(retv, floor(x)); return S_OK; } static HRESULT Math_log(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -286,12 +282,11 @@ static HRESULT Math_log(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; if(retv) { - DOUBLE x = num_val(&v); if(x < -0.0) num_set_nan(retv); else @@ -305,7 +300,6 @@ static HRESULT Math_max(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA VARIANT *retv, jsexcept_t *ei) { DOUBLE max, d; - VARIANT v; DWORD i; HRESULT hres; @@ -317,17 +311,15 @@ static HRESULT Math_max(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &max); if(FAILED(hres)) return hres; - max = num_val(&v); for(i=1; i < arg_cnt(dp); i++) { - hres = to_number(ctx, get_arg(dp, i), ei, &v); + hres = to_number(ctx, get_arg(dp, i), ei, &d); if(FAILED(hres)) return hres; - d = num_val(&v); if(d > max || isnan(d)) max = d; } @@ -342,7 +334,6 @@ static HRESULT Math_min(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA VARIANT *retv, jsexcept_t *ei) { DOUBLE min, d; - VARIANT v; DWORD i; HRESULT hres; @@ -354,17 +345,15 @@ static HRESULT Math_min(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &min); if(FAILED(hres)) return hres; - min = num_val(&v); for(i=1; i < arg_cnt(dp); i++) { - hres = to_number(ctx, get_arg(dp, i), ei, &v); + hres = to_number(ctx, get_arg(dp, i), ei, &d); if(FAILED(hres)) return hres; - d = num_val(&v); if(d < min || isnan(d)) min = d; } @@ -378,7 +367,7 @@ static HRESULT Math_min(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA static HRESULT Math_pow(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT x, y; + double x, y; HRESULT hres; TRACE("\n"); @@ -397,7 +386,7 @@ static HRESULT Math_pow(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA return hres; if(retv) - num_set_val(retv, pow(num_val(&x), num_val(&y))); + num_set_val(retv, pow(x, y)); return S_OK; } @@ -422,7 +411,7 @@ static HRESULT Math_random(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPP static HRESULT Math_round(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -432,19 +421,19 @@ static HRESULT Math_round(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; if(retv) - num_set_val(retv, floor(num_val(&v)+0.5)); + num_set_val(retv, floor(x+0.5)); return S_OK; } static HRESULT Math_sin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -454,18 +443,18 @@ static HRESULT Math_sin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; - if(retv) num_set_val(retv, sin(num_val(&v))); + if(retv) num_set_val(retv, sin(x)); return S_OK; } static HRESULT Math_sqrt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -475,18 +464,18 @@ static HRESULT Math_sqrt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPAR return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; - if(retv) num_set_val(retv, sqrt(num_val(&v))); + if(retv) num_set_val(retv, sqrt(x)); return S_OK; } static HRESULT Math_tan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT v; + double x; HRESULT hres; TRACE("\n"); @@ -496,11 +485,11 @@ static HRESULT Math_tan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARA return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &v); + hres = to_number(ctx, get_arg(dp, 0), ei, &x); if(FAILED(hres)) return hres; - if(retv) num_set_val(retv, tan(num_val(&v))); + if(retv) num_set_val(retv, tan(x)); return S_OK; } diff --git a/dlls/jscript/number.c b/dlls/jscript/number.c index e364f119a0f..7a3d8b0d4b6 100644 --- a/dlls/jscript/number.c +++ b/dlls/jscript/number.c @@ -263,7 +263,7 @@ static const builtin_info_t Number_info = { static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { - VARIANT num; + double n; HRESULT hres; TRACE("\n"); @@ -278,27 +278,30 @@ static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags return S_OK; } - hres = to_number(ctx, get_arg(dp, 0), ei, &num); + hres = to_number(ctx, get_arg(dp, 0), ei, &n); if(FAILED(hres)) return hres; if(retv) - *retv = num; + num_set_val(retv, n); break; case DISPATCH_CONSTRUCT: { jsdisp_t *obj; + VARIANT v; if(arg_cnt(dp)) { - hres = to_number(ctx, get_arg(dp, 0), ei, &num); + hres = to_number(ctx, get_arg(dp, 0), ei, &n); if(FAILED(hres)) return hres; + + num_set_val(&v, n); }else { - V_VT(&num) = VT_I4; - V_I4(&num) = 0; + V_VT(&v) = VT_I4; + V_I4(&v) = 0; } - hres = create_number(ctx, &num, &obj); + hres = create_number(ctx, &v, &obj); if(FAILED(hres)) return hres; diff --git a/dlls/jscript/regexp.c b/dlls/jscript/regexp.c index 5106604f9a1..8e80f9be522 100644 --- a/dlls/jscript/regexp.c +++ b/dlls/jscript/regexp.c @@ -3522,22 +3522,18 @@ static HRESULT RegExp_multiline(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, static INT index_from_var(script_ctx_t *ctx, VARIANT *v) { jsexcept_t ei; - VARIANT num; + double n; HRESULT hres; memset(&ei, 0, sizeof(ei)); - hres = to_number(ctx, v, &ei, &num); + hres = to_number(ctx, v, &ei, &n); if(FAILED(hres)) { /* FIXME: Move ignoring exceptions to to_primitive */ VariantClear(&ei.var); return 0; } - if(V_VT(&num) == VT_R8) { - DOUBLE d = floor(V_R8(&num)); - return (DOUBLE)(INT)d == d ? d : 0; - } - - return V_I4(&num); + n = floor(n); + return (double)(INT)n == n ? n : 0; } static HRESULT RegExp_lastIndex(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,