jscript: Return double from to_integer.
This commit is contained in:
parent
e26a3018e7
commit
56bf46fda0
|
@ -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;
|
||||
jsdisp_t *ret_array = NULL, *jsthis;
|
||||
VARIANT v;
|
||||
double d;
|
||||
int n;
|
||||
VARIANT v;
|
||||
HRESULT hres = S_OK;
|
||||
|
||||
TRACE("\n");
|
||||
|
@ -866,10 +866,9 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPP
|
|||
|
||||
argc = arg_cnt(dp);
|
||||
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))
|
||||
return hres;
|
||||
d = num_val(&v);
|
||||
|
||||
if(is_int32(d)) {
|
||||
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) {
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &v);
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &d);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
d = num_val(&v);
|
||||
|
||||
if(is_int32(d)) {
|
||||
if((n = d) > 0)
|
||||
|
|
|
@ -254,7 +254,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*,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_uint32(script_ctx_t*,VARIANT*,jsexcept_t*,DWORD*) DECLSPEC_HIDDEN;
|
||||
HRESULT to_string(script_ctx_t*,VARIANT*,jsexcept_t*,BSTR*) DECLSPEC_HIDDEN;
|
||||
|
|
|
@ -457,13 +457,13 @@ HRESULT to_number(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, double *ret)
|
|||
}
|
||||
|
||||
/* 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;
|
||||
HRESULT hres;
|
||||
|
||||
if(V_VT(v) == VT_I4) {
|
||||
*ret = *v;
|
||||
*ret = V_I4(v);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -471,13 +471,10 @@ HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
if(isnan(n)) {
|
||||
V_VT(ret) = VT_I4;
|
||||
V_I4(ret) = 0;
|
||||
}else {
|
||||
num_set_val(ret, n >= 0.0 ? floor(n) : -floor(-n));
|
||||
}
|
||||
|
||||
if(isnan(n))
|
||||
*ret = 0;
|
||||
else
|
||||
*ret = n >= 0.0 ? floor(n) : -floor(-n);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -302,15 +302,13 @@ static HRESULT String_charAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
|
|||
return hres;
|
||||
|
||||
if(arg_cnt(dp)) {
|
||||
VARIANT num;
|
||||
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)) {
|
||||
SysFreeString(val_str);
|
||||
return hres;
|
||||
}
|
||||
d = num_val(&num);
|
||||
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;
|
||||
|
||||
if(arg_cnt(dp) > 0) {
|
||||
VARIANT v;
|
||||
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)) {
|
||||
SysFreeString(val_str);
|
||||
return hres;
|
||||
}
|
||||
|
||||
d = num_val(&v);
|
||||
|
||||
if(!is_int32(d) || d < 0 || d >= length) {
|
||||
SysFreeString(val_str);
|
||||
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) {
|
||||
VARIANT ival;
|
||||
double d;
|
||||
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &ival);
|
||||
if(SUCCEEDED(hres)) {
|
||||
d = num_val(&ival);
|
||||
if(d > 0.0)
|
||||
pos = is_int32(d) ? min((int)d, length) : length;
|
||||
}
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &d);
|
||||
if(SUCCEEDED(hres) && d > 0.0)
|
||||
pos = is_int32(d) ? min(length, d) : length;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if(arg_cnt(dp) >= 2) {
|
||||
VARIANT ival;
|
||||
double d;
|
||||
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &ival);
|
||||
if(SUCCEEDED(hres)) {
|
||||
d = num_val(&ival);
|
||||
if(d > 0)
|
||||
pos = is_int32(d) ? min((int)d, length) : length;
|
||||
}
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &d);
|
||||
if(SUCCEEDED(hres) && d > 0)
|
||||
pos = is_int32(d) ? min(length, d) : length;
|
||||
}else {
|
||||
pos = length;
|
||||
}
|
||||
|
@ -1072,7 +1059,6 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
|
|||
DWORD length;
|
||||
INT start=0, end;
|
||||
double d;
|
||||
VARIANT v;
|
||||
HRESULT hres;
|
||||
|
||||
TRACE("\n");
|
||||
|
@ -1082,14 +1068,12 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
|
|||
return hres;
|
||||
|
||||
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)) {
|
||||
SysFreeString(val_str);
|
||||
return hres;
|
||||
}
|
||||
|
||||
d = num_val(&v);
|
||||
|
||||
if(is_int32(d)) {
|
||||
start = d;
|
||||
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) {
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &v);
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &d);
|
||||
if(FAILED(hres)) {
|
||||
SysFreeString(val_str);
|
||||
return hres;
|
||||
}
|
||||
|
||||
d = num_val(&v);
|
||||
|
||||
if(is_int32(d)) {
|
||||
end = d;
|
||||
if(end < 0) {
|
||||
|
@ -1301,7 +1283,6 @@ static HRESULT String_substring(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
|||
BSTR val_str;
|
||||
INT start=0, end;
|
||||
DWORD length;
|
||||
VARIANT v;
|
||||
double d;
|
||||
HRESULT hres;
|
||||
|
||||
|
@ -1312,27 +1293,25 @@ static HRESULT String_substring(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
|||
return hres;
|
||||
|
||||
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)) {
|
||||
SysFreeString(val_str);
|
||||
return hres;
|
||||
}
|
||||
|
||||
d = num_val(&v);
|
||||
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) {
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &v);
|
||||
hres = to_integer(ctx, get_arg(dp,1), ei, &d);
|
||||
if(FAILED(hres)) {
|
||||
SysFreeString(val_str);
|
||||
return hres;
|
||||
}
|
||||
|
||||
d = num_val(&v);
|
||||
if(d >= 0)
|
||||
end = is_int32(d) ? min((int)d, length) : length;
|
||||
end = is_int32(d) ? min(length, d) : length;
|
||||
else
|
||||
end = 0;
|
||||
}else {
|
||||
|
@ -1365,7 +1344,6 @@ static HRESULT String_substr(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
|
|||
const WCHAR *str;
|
||||
INT start=0, len;
|
||||
DWORD length;
|
||||
VARIANT v;
|
||||
double d;
|
||||
HRESULT hres;
|
||||
|
||||
|
@ -1376,25 +1354,23 @@ static HRESULT String_substr(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
|
|||
return hres;
|
||||
|
||||
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)) {
|
||||
SysFreeString(val_str);
|
||||
return hres;
|
||||
}
|
||||
|
||||
d = num_val(&v);
|
||||
if(d >= 0)
|
||||
start = is_int32(d) ? min(length, d) : length;
|
||||
}
|
||||
|
||||
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)) {
|
||||
SysFreeString(val_str);
|
||||
return hres;
|
||||
}
|
||||
|
||||
d = num_val(&v);
|
||||
if(d >= 0.0)
|
||||
len = is_int32(d) ? min(length-start, d) : length-start;
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue