jscript: Return double from to_integer.

This commit is contained in:
Jacek Caban 2012-05-03 10:42:42 +02:00 committed by Alexandre Julliard
parent e26a3018e7
commit 56bf46fda0
4 changed files with 26 additions and 55 deletions

View File

@ -853,9 +853,9 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPP
{ {
DWORD length, start=0, delete_cnt=0, argc, i, add_args = 0; DWORD length, start=0, delete_cnt=0, argc, i, add_args = 0;
jsdisp_t *ret_array = NULL, *jsthis; jsdisp_t *ret_array = NULL, *jsthis;
VARIANT v;
double d; double d;
int n; int n;
VARIANT v;
HRESULT hres = S_OK; HRESULT hres = S_OK;
TRACE("\n"); TRACE("\n");
@ -866,10 +866,9 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPP
argc = arg_cnt(dp); argc = arg_cnt(dp);
if(argc >= 1) { if(argc >= 1) {
hres = to_integer(ctx, get_arg(dp,0), ei, &v); hres = to_integer(ctx, get_arg(dp,0), ei, &d);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
d = num_val(&v);
if(is_int32(d)) { if(is_int32(d)) {
if((n = d) >= 0) if((n = d) >= 0)
@ -882,10 +881,9 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPP
} }
if(argc >= 2) { if(argc >= 2) {
hres = to_integer(ctx, get_arg(dp,1), ei, &v); hres = to_integer(ctx, get_arg(dp,1), ei, &d);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
d = num_val(&v);
if(is_int32(d)) { if(is_int32(d)) {
if((n = d) > 0) if((n = d) > 0)

View File

@ -254,7 +254,7 @@ typedef enum {
HRESULT to_primitive(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*, hint_t) DECLSPEC_HIDDEN; HRESULT to_primitive(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*, hint_t) DECLSPEC_HIDDEN;
HRESULT to_boolean(VARIANT*,VARIANT_BOOL*) DECLSPEC_HIDDEN; HRESULT to_boolean(VARIANT*,VARIANT_BOOL*) DECLSPEC_HIDDEN;
HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,double*) 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_integer(script_ctx_t*,VARIANT*,jsexcept_t*,double*) DECLSPEC_HIDDEN;
HRESULT to_int32(script_ctx_t*,VARIANT*,jsexcept_t*,INT*) 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; HRESULT to_uint32(script_ctx_t*,VARIANT*,jsexcept_t*,DWORD*) DECLSPEC_HIDDEN;
HRESULT to_string(script_ctx_t*,VARIANT*,jsexcept_t*,BSTR*) DECLSPEC_HIDDEN; HRESULT to_string(script_ctx_t*,VARIANT*,jsexcept_t*,BSTR*) DECLSPEC_HIDDEN;

View File

@ -457,13 +457,13 @@ HRESULT to_number(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, double *ret)
} }
/* ECMA-262 3rd Edition 9.4 */ /* ECMA-262 3rd Edition 9.4 */
HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret) HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, double *ret)
{ {
double n; double n;
HRESULT hres; HRESULT hres;
if(V_VT(v) == VT_I4) { if(V_VT(v) == VT_I4) {
*ret = *v; *ret = V_I4(v);
return S_OK; return S_OK;
} }
@ -471,13 +471,10 @@ HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret)
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(isnan(n)) { if(isnan(n))
V_VT(ret) = VT_I4; *ret = 0;
V_I4(ret) = 0; else
}else { *ret = n >= 0.0 ? floor(n) : -floor(-n);
num_set_val(ret, n >= 0.0 ? floor(n) : -floor(-n));
}
return S_OK; return S_OK;
} }

View File

@ -302,15 +302,13 @@ static HRESULT String_charAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
return hres; return hres;
if(arg_cnt(dp)) { if(arg_cnt(dp)) {
VARIANT num;
double d; double d;
hres = to_integer(ctx, get_arg(dp, 0), ei, &num); hres = to_integer(ctx, get_arg(dp, 0), ei, &d);
if(FAILED(hres)) { if(FAILED(hres)) {
SysFreeString(val_str); SysFreeString(val_str);
return hres; return hres;
} }
d = num_val(&num);
pos = is_int32(d) ? d : -1; pos = is_int32(d) ? d : -1;
} }
@ -349,17 +347,14 @@ static HRESULT String_charCodeAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
return hres; return hres;
if(arg_cnt(dp) > 0) { if(arg_cnt(dp) > 0) {
VARIANT v;
double d; double d;
hres = to_integer(ctx, get_arg(dp, 0), ei, &v); hres = to_integer(ctx, get_arg(dp, 0), ei, &d);
if(FAILED(hres)) { if(FAILED(hres)) {
SysFreeString(val_str); SysFreeString(val_str);
return hres; return hres;
} }
d = num_val(&v);
if(!is_int32(d) || d < 0 || d >= length) { if(!is_int32(d) || d < 0 || d >= length) {
SysFreeString(val_str); SysFreeString(val_str);
if(retv) if(retv)
@ -493,15 +488,11 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI
} }
if(arg_cnt(dp) >= 2) { if(arg_cnt(dp) >= 2) {
VARIANT ival;
double d; double d;
hres = to_integer(ctx, get_arg(dp,1), ei, &ival); hres = to_integer(ctx, get_arg(dp,1), ei, &d);
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres) && d > 0.0)
d = num_val(&ival); pos = is_int32(d) ? min(length, d) : length;
if(d > 0.0)
pos = is_int32(d) ? min((int)d, length) : length;
}
} }
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
@ -567,15 +558,11 @@ static HRESULT String_lastIndexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
search_len = SysStringLen(search_str); search_len = SysStringLen(search_str);
if(arg_cnt(dp) >= 2) { if(arg_cnt(dp) >= 2) {
VARIANT ival;
double d; double d;
hres = to_integer(ctx, get_arg(dp,1), ei, &ival); hres = to_integer(ctx, get_arg(dp,1), ei, &d);
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres) && d > 0)
d = num_val(&ival); pos = is_int32(d) ? min(length, d) : length;
if(d > 0)
pos = is_int32(d) ? min((int)d, length) : length;
}
}else { }else {
pos = length; pos = length;
} }
@ -1072,7 +1059,6 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
DWORD length; DWORD length;
INT start=0, end; INT start=0, end;
double d; double d;
VARIANT v;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
@ -1082,14 +1068,12 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
return hres; return hres;
if(arg_cnt(dp)) { if(arg_cnt(dp)) {
hres = to_integer(ctx, get_arg(dp,0), ei, &v); hres = to_integer(ctx, get_arg(dp,0), ei, &d);
if(FAILED(hres)) { if(FAILED(hres)) {
SysFreeString(val_str); SysFreeString(val_str);
return hres; return hres;
} }
d = num_val(&v);
if(is_int32(d)) { if(is_int32(d)) {
start = d; start = d;
if(start < 0) { if(start < 0) {
@ -1105,14 +1089,12 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
} }
if(arg_cnt(dp) >= 2) { if(arg_cnt(dp) >= 2) {
hres = to_integer(ctx, get_arg(dp,1), ei, &v); hres = to_integer(ctx, get_arg(dp,1), ei, &d);
if(FAILED(hres)) { if(FAILED(hres)) {
SysFreeString(val_str); SysFreeString(val_str);
return hres; return hres;
} }
d = num_val(&v);
if(is_int32(d)) { if(is_int32(d)) {
end = d; end = d;
if(end < 0) { if(end < 0) {
@ -1301,7 +1283,6 @@ static HRESULT String_substring(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
BSTR val_str; BSTR val_str;
INT start=0, end; INT start=0, end;
DWORD length; DWORD length;
VARIANT v;
double d; double d;
HRESULT hres; HRESULT hres;
@ -1312,27 +1293,25 @@ static HRESULT String_substring(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
return hres; return hres;
if(arg_cnt(dp) >= 1) { if(arg_cnt(dp) >= 1) {
hres = to_integer(ctx, get_arg(dp,0), ei, &v); hres = to_integer(ctx, get_arg(dp,0), ei, &d);
if(FAILED(hres)) { if(FAILED(hres)) {
SysFreeString(val_str); SysFreeString(val_str);
return hres; return hres;
} }
d = num_val(&v);
if(d >= 0) if(d >= 0)
start = is_int32(d) ? min((int)d, length) : length; start = is_int32(d) ? min(length, d) : length;
} }
if(arg_cnt(dp) >= 2) { if(arg_cnt(dp) >= 2) {
hres = to_integer(ctx, get_arg(dp,1), ei, &v); hres = to_integer(ctx, get_arg(dp,1), ei, &d);
if(FAILED(hres)) { if(FAILED(hres)) {
SysFreeString(val_str); SysFreeString(val_str);
return hres; return hres;
} }
d = num_val(&v);
if(d >= 0) if(d >= 0)
end = is_int32(d) ? min((int)d, length) : length; end = is_int32(d) ? min(length, d) : length;
else else
end = 0; end = 0;
}else { }else {
@ -1365,7 +1344,6 @@ static HRESULT String_substr(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
const WCHAR *str; const WCHAR *str;
INT start=0, len; INT start=0, len;
DWORD length; DWORD length;
VARIANT v;
double d; double d;
HRESULT hres; HRESULT hres;
@ -1376,25 +1354,23 @@ static HRESULT String_substr(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
return hres; return hres;
if(arg_cnt(dp) >= 1) { if(arg_cnt(dp) >= 1) {
hres = to_integer(ctx, get_arg(dp,0), ei, &v); hres = to_integer(ctx, get_arg(dp,0), ei, &d);
if(FAILED(hres)) { if(FAILED(hres)) {
SysFreeString(val_str); SysFreeString(val_str);
return hres; return hres;
} }
d = num_val(&v);
if(d >= 0) if(d >= 0)
start = is_int32(d) ? min(length, d) : length; start = is_int32(d) ? min(length, d) : length;
} }
if(arg_cnt(dp) >= 2) { if(arg_cnt(dp) >= 2) {
hres = to_integer(ctx, get_arg(dp,1), ei, &v); hres = to_integer(ctx, get_arg(dp,1), ei, &d);
if(FAILED(hres)) { if(FAILED(hres)) {
SysFreeString(val_str); SysFreeString(val_str);
return hres; return hres;
} }
d = num_val(&v);
if(d >= 0.0) if(d >= 0.0)
len = is_int32(d) ? min(length-start, d) : length-start; len = is_int32(d) ? min(length-start, d) : length-start;
else else