jscript: Always use jsval-based to_number implementation.

This commit is contained in:
Jacek Caban 2012-09-17 15:18:20 +02:00 committed by Alexandre Julliard
parent 26576b83da
commit 0bab034fac
10 changed files with 124 additions and 164 deletions

View File

@ -129,7 +129,7 @@ static HRESULT Array_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
DWORD i;
HRESULT hres;
hres = to_number_jsval(ctx, argv[0], ei, &len);
hres = to_number(ctx, argv[0], ei, &len);
if(FAILED(hres))
return hres;
@ -567,7 +567,7 @@ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsign
return hres;
if(argc) {
hres = to_number_jsval(ctx, argv[0], ei, &range);
hres = to_number(ctx, argv[0], ei, &range);
if(FAILED(hres))
return hres;
@ -580,7 +580,7 @@ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsign
else start = 0;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &range);
hres = to_number(ctx, argv[1], ei, &range);
if(FAILED(hres))
return hres;
@ -635,7 +635,7 @@ static HRESULT sort_cmp(script_ctx_t *ctx, jsdisp_t *cmp_func, jsval_t v1, jsval
if(FAILED(hres))
return hres;
hres = to_number_jsval(ctx, res, ei, &n);
hres = to_number(ctx, res, ei, &n);
jsval_release(res);
if(FAILED(hres))
return hres;

View File

@ -1348,7 +1348,7 @@ static HRESULT Date_setTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(!argc)
return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL);
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres))
return hres;
@ -1375,7 +1375,7 @@ static HRESULT Date_setMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla
if(!argc)
return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL);
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres))
return hres;
@ -1405,7 +1405,7 @@ static HRESULT Date_setUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD
if(!argc)
return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL);
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres))
return hres;
@ -1437,12 +1437,12 @@ static HRESULT Date_setSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
t = local_time(date->time, date);
hres = to_number_jsval(ctx, argv[0], ei, &sec);
hres = to_number(ctx, argv[0], ei, &sec);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &ms);
hres = to_number(ctx, argv[1], ei, &ms);
if(FAILED(hres))
return hres;
}else {
@ -1476,12 +1476,12 @@ static HRESULT Date_setUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
t = date->time;
hres = to_number_jsval(ctx, argv[0], ei, &sec);
hres = to_number(ctx, argv[0], ei, &sec);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &ms);
hres = to_number(ctx, argv[1], ei, &ms);
if(FAILED(hres))
return hres;
}else {
@ -1515,12 +1515,12 @@ static HRESULT Date_setMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
t = local_time(date->time, date);
hres = to_number_jsval(ctx, argv[0], ei, &min);
hres = to_number(ctx, argv[0], ei, &min);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &sec);
hres = to_number(ctx, argv[1], ei, &sec);
if(FAILED(hres))
return hres;
}else {
@ -1528,7 +1528,7 @@ static HRESULT Date_setMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
}
if(argc > 2) {
hres = to_number_jsval(ctx, argv[2], ei, &ms);
hres = to_number(ctx, argv[2], ei, &ms);
if(FAILED(hres))
return hres;
}else {
@ -1562,12 +1562,12 @@ static HRESULT Date_setUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
t = date->time;
hres = to_number_jsval(ctx, argv[0], ei, &min);
hres = to_number(ctx, argv[0], ei, &min);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &sec);
hres = to_number(ctx, argv[1], ei, &sec);
if(FAILED(hres))
return hres;
}else {
@ -1575,7 +1575,7 @@ static HRESULT Date_setUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
}
if(argc > 2) {
hres = to_number_jsval(ctx, argv[2], ei, &ms);
hres = to_number(ctx, argv[2], ei, &ms);
if(FAILED(hres))
return hres;
}else {
@ -1609,12 +1609,12 @@ static HRESULT Date_setHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
t = local_time(date->time, date);
hres = to_number_jsval(ctx, argv[0], ei, &hour);
hres = to_number(ctx, argv[0], ei, &hour);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &min);
hres = to_number(ctx, argv[1], ei, &min);
if(FAILED(hres))
return hres;
}else {
@ -1622,7 +1622,7 @@ static HRESULT Date_setHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
}
if(argc > 2) {
hres = to_number_jsval(ctx, argv[2], ei, &sec);
hres = to_number(ctx, argv[2], ei, &sec);
if(FAILED(hres))
return hres;
}else {
@ -1630,7 +1630,7 @@ static HRESULT Date_setHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
}
if(argc > 3) {
hres = to_number_jsval(ctx, argv[3], ei, &ms);
hres = to_number(ctx, argv[3], ei, &ms);
if(FAILED(hres))
return hres;
}else {
@ -1663,12 +1663,12 @@ static HRESULT Date_setUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
t = date->time;
hres = to_number_jsval(ctx, argv[0], ei, &hour);
hres = to_number(ctx, argv[0], ei, &hour);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &min);
hres = to_number(ctx, argv[1], ei, &min);
if(FAILED(hres))
return hres;
}else {
@ -1676,7 +1676,7 @@ static HRESULT Date_setUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
}
if(argc > 2) {
hres = to_number_jsval(ctx, argv[2], ei, &sec);
hres = to_number(ctx, argv[2], ei, &sec);
if(FAILED(hres))
return hres;
}else {
@ -1684,7 +1684,7 @@ static HRESULT Date_setUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
}
if(argc > 3) {
hres = to_number_jsval(ctx, argv[3], ei, &ms);
hres = to_number(ctx, argv[3], ei, &ms);
if(FAILED(hres))
return hres;
}else {
@ -1715,7 +1715,7 @@ static HRESULT Date_setDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(!argc)
return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL);
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres))
return hres;
@ -1744,7 +1744,7 @@ static HRESULT Date_setUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
if(!argc)
return throw_type_error(ctx, ei, JS_E_MISSING_ARG, NULL);
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres))
return hres;
@ -1775,12 +1775,12 @@ static HRESULT Date_setMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
t = local_time(date->time, date);
hres = to_number_jsval(ctx, argv[0], ei, &month);
hres = to_number(ctx, argv[0], ei, &month);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &ddate);
hres = to_number(ctx, argv[1], ei, &ddate);
if(FAILED(hres))
return hres;
}else {
@ -1814,12 +1814,12 @@ static HRESULT Date_setUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
t = date->time;
hres = to_number_jsval(ctx, argv[0], ei, &month);
hres = to_number(ctx, argv[0], ei, &month);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &ddate);
hres = to_number(ctx, argv[1], ei, &ddate);
if(FAILED(hres))
return hres;
}else {
@ -1853,12 +1853,12 @@ static HRESULT Date_setFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
t = local_time(date->time, date);
hres = to_number_jsval(ctx, argv[0], ei, &year);
hres = to_number(ctx, argv[0], ei, &year);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &month);
hres = to_number(ctx, argv[1], ei, &month);
if(FAILED(hres))
return hres;
}else {
@ -1866,7 +1866,7 @@ static HRESULT Date_setFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
}
if(argc > 2) {
hres = to_number_jsval(ctx, argv[2], ei, &ddate);
hres = to_number(ctx, argv[2], ei, &ddate);
if(FAILED(hres))
return hres;
}else {
@ -1899,12 +1899,12 @@ static HRESULT Date_setUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
t = date->time;
hres = to_number_jsval(ctx, argv[0], ei, &year);
hres = to_number(ctx, argv[0], ei, &year);
if(FAILED(hres))
return hres;
if(argc > 1) {
hres = to_number_jsval(ctx, argv[1], ei, &month);
hres = to_number(ctx, argv[1], ei, &month);
if(FAILED(hres))
return hres;
}else {
@ -1912,7 +1912,7 @@ static HRESULT Date_setUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
}
if(argc > 2) {
hres = to_number_jsval(ctx, argv[2], ei, &ddate);
hres = to_number(ctx, argv[2], ei, &ddate);
if(FAILED(hres))
return hres;
}else {
@ -1970,7 +1970,7 @@ static HRESULT Date_setYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
t = local_time(date->time, date);
hres = to_number_jsval(ctx, argv[0], ei, &year);
hres = to_number(ctx, argv[0], ei, &year);
if(FAILED(hres))
return hres;
@ -2401,7 +2401,7 @@ static HRESULT date_utc(script_ctx_t *ctx, unsigned argc, jsval_t *argv, double
TRACE("\n");
if(argc) {
hres = to_number_jsval(ctx, argv[0], ei, &year);
hres = to_number(ctx, argv[0], ei, &year);
if(FAILED(hres))
return hres;
if(0 <= year && year <= 99)
@ -2411,7 +2411,7 @@ static HRESULT date_utc(script_ctx_t *ctx, unsigned argc, jsval_t *argv, double
}
if(argc>1) {
hres = to_number_jsval(ctx, argv[1], ei, &month);
hres = to_number(ctx, argv[1], ei, &month);
if(FAILED(hres))
return hres;
}else {
@ -2419,7 +2419,7 @@ static HRESULT date_utc(script_ctx_t *ctx, unsigned argc, jsval_t *argv, double
}
if(argc>2) {
hres = to_number_jsval(ctx, argv[2], ei, &vdate);
hres = to_number(ctx, argv[2], ei, &vdate);
if(FAILED(hres))
return hres;
}else {
@ -2427,7 +2427,7 @@ static HRESULT date_utc(script_ctx_t *ctx, unsigned argc, jsval_t *argv, double
}
if(argc>3) {
hres = to_number_jsval(ctx, argv[3], ei, &hours);
hres = to_number(ctx, argv[3], ei, &hours);
if(FAILED(hres))
return hres;
}else {
@ -2435,7 +2435,7 @@ static HRESULT date_utc(script_ctx_t *ctx, unsigned argc, jsval_t *argv, double
}
if(argc>4) {
hres = to_number_jsval(ctx, argv[4], ei, &minutes);
hres = to_number(ctx, argv[4], ei, &minutes);
if(FAILED(hres))
return hres;
}else {
@ -2443,7 +2443,7 @@ static HRESULT date_utc(script_ctx_t *ctx, unsigned argc, jsval_t *argv, double
}
if(argc>5) {
hres = to_number_jsval(ctx, argv[5], ei, &seconds);
hres = to_number(ctx, argv[5], ei, &seconds);
if(FAILED(hres))
return hres;
}else {
@ -2451,7 +2451,7 @@ static HRESULT date_utc(script_ctx_t *ctx, unsigned argc, jsval_t *argv, double
}
if(argc>6) {
hres = to_number_jsval(ctx, argv[6], ei, &ms);
hres = to_number(ctx, argv[6], ei, &ms);
if(FAILED(hres))
return hres;
} else {
@ -2515,7 +2515,7 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(is_string(prim))
hres = date_parse(get_string(prim), &n);
else
hres = to_number_jsval(ctx, prim, ei, &n);
hres = to_number(ctx, prim, ei, &n);
jsval_release(prim);
if(FAILED(hres))

View File

@ -130,7 +130,7 @@ static HRESULT stack_pop_number(exec_ctx_t *ctx, double *r)
HRESULT hres;
v = stack_pop(ctx);
hres = to_number_jsval(ctx->script, v, ctx->ei, r);
hres = to_number(ctx->script, v, ctx->ei, r);
jsval_release(v);
return hres;
}
@ -1454,9 +1454,9 @@ static HRESULT add_eval(script_ctx_t *ctx, jsval_t lval, jsval_t rval, jsexcept_
}else {
double nl, nr;
hres = to_number_jsval(ctx, l, ei, &nl);
hres = to_number(ctx, l, ei, &nl);
if(SUCCEEDED(hres)) {
hres = to_number_jsval(ctx, r, ei, &nr);
hres = to_number(ctx, r, ei, &nr);
if(SUCCEEDED(hres))
*ret = jsval_number(nl+nr);
}
@ -1799,7 +1799,7 @@ static HRESULT interp_tonum(exec_ctx_t *ctx)
TRACE("\n");
v = stack_pop(ctx);
hres = to_number_jsval(ctx->script, v, ctx->ei, &n);
hres = to_number(ctx->script, v, ctx->ei, &n);
jsval_release(v);
if(FAILED(hres))
return hres;
@ -1826,7 +1826,7 @@ static HRESULT interp_postinc(exec_ctx_t *ctx)
if(SUCCEEDED(hres)) {
double n;
hres = to_number_jsval(ctx->script, v, ctx->ei, &n);
hres = to_number(ctx->script, v, ctx->ei, &n);
if(SUCCEEDED(hres))
hres = disp_propput(ctx->script, obj, id, jsval_number(n+(double)arg), ctx->ei);
if(FAILED(hres))
@ -1859,7 +1859,7 @@ static HRESULT interp_preinc(exec_ctx_t *ctx)
if(SUCCEEDED(hres)) {
double n;
hres = to_number_jsval(ctx->script, v, ctx->ei, &n);
hres = to_number(ctx->script, v, ctx->ei, &n);
jsval_release(v);
if(SUCCEEDED(hres)) {
ret = n+(double)arg;
@ -1894,7 +1894,7 @@ static HRESULT equal_values(script_ctx_t *ctx, jsval_t lval, jsval_t rval, jsexc
double n;
HRESULT hres;
hres = to_number_jsval(ctx, lval, ei, &n);
hres = to_number(ctx, lval, ei, &n);
if(FAILED(hres))
return hres;
@ -1906,7 +1906,7 @@ static HRESULT equal_values(script_ctx_t *ctx, jsval_t lval, jsval_t rval, jsexc
double n;
HRESULT hres;
hres = to_number_jsval(ctx, rval, ei, &n);
hres = to_number(ctx, rval, ei, &n);
if(FAILED(hres))
return hres;
@ -2061,10 +2061,10 @@ static HRESULT less_eval(script_ctx_t *ctx, jsval_t lval, jsval_t rval, BOOL gre
return S_OK;
}
hres = to_number_jsval(ctx, l, ei, &ln);
hres = to_number(ctx, l, ei, &ln);
jsval_release(l);
if(SUCCEEDED(hres))
hres = to_number_jsval(ctx, r, ei, &rn);
hres = to_number(ctx, r, ei, &rn);
jsval_release(r);
if(FAILED(hres))
return hres;

View File

@ -231,7 +231,7 @@ static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, jsval_
if(argc) {
double n;
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres)) /* FIXME: really? */
n = NAN;
if(isnan(n))

View File

@ -392,7 +392,7 @@ static HRESULT JSGlobal_isNaN(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
TRACE("\n");
if(argc) {
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres))
return hres;
@ -416,7 +416,7 @@ static HRESULT JSGlobal_isFinite(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(argc) {
double n;
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres))
return hres;

View File

@ -256,10 +256,8 @@ typedef enum {
HRESULT to_primitive(script_ctx_t*,jsval_t,jsexcept_t*,jsval_t*, hint_t) DECLSPEC_HIDDEN;
HRESULT to_boolean(jsval_t,BOOL*) DECLSPEC_HIDDEN;
HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,double*) DECLSPEC_HIDDEN;
HRESULT to_number_jsval(script_ctx_t*,jsval_t,jsexcept_t*,double*) DECLSPEC_HIDDEN;
HRESULT to_number(script_ctx_t*,jsval_t,jsexcept_t*,double*) DECLSPEC_HIDDEN;
HRESULT to_integer(script_ctx_t*,jsval_t,jsexcept_t*,double*) DECLSPEC_HIDDEN;
HRESULT to_int32_var(script_ctx_t*,VARIANT*,jsexcept_t*,INT*) DECLSPEC_HIDDEN;
HRESULT to_int32(script_ctx_t*,jsval_t,jsexcept_t*,INT*) DECLSPEC_HIDDEN;
HRESULT to_uint32(script_ctx_t*,VARIANT*,jsexcept_t*,DWORD*) DECLSPEC_HIDDEN;
HRESULT to_uint32_jsval(script_ctx_t*,jsval_t,jsexcept_t*,DWORD*) DECLSPEC_HIDDEN;

View File

@ -575,67 +575,42 @@ static HRESULT str_to_number(BSTR str, double *ret)
}
/* ECMA-262 3rd Edition 9.3 */
HRESULT to_number(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, double *ret)
HRESULT to_number(script_ctx_t *ctx, jsval_t val, jsexcept_t *ei, double *ret)
{
switch(V_VT(v)) {
case VT_EMPTY:
switch(val.type) {
case JSV_UNDEFINED:
*ret = NAN;
break;
case VT_NULL:
return S_OK;
case JSV_NULL:
*ret = 0;
break;
case VT_I4:
*ret = V_I4(v);
break;
case VT_R8:
*ret = V_R8(v);
break;
case VT_BSTR:
return str_to_number(V_BSTR(v), ret);
case VT_DISPATCH: {
return S_OK;
case JSV_NUMBER:
*ret = get_number(val);
return S_OK;
case JSV_STRING:
return str_to_number(get_string(val), ret);
case JSV_OBJECT: {
jsval_t prim;
HRESULT hres;
hres = to_primitive(ctx, jsval_disp(V_DISPATCH(v)), ei, &prim, HINT_NUMBER);
hres = to_primitive(ctx, val, ei, &prim, HINT_NUMBER);
if(FAILED(hres))
return hres;
hres = to_number_jsval(ctx, prim, ei, ret);
hres = to_number(ctx, prim, ei, ret);
jsval_release(prim);
return hres;
}
case VT_BOOL:
*ret = V_BOOL(v) ? 1 : 0;
break;
case VT_I2:
case VT_INT:
assert(0);
default:
FIXME("unimplemented for vt %d\n", V_VT(v));
case JSV_BOOL:
*ret = get_bool(val) ? 1 : 0;
return S_OK;
case JSV_VARIANT:
FIXME("unimplemented for variant %s\n", debugstr_variant(get_variant(val)));
return E_NOTIMPL;
}
};
return S_OK;
}
/* ECMA-262 3rd Edition 9.3 */
HRESULT to_number_jsval(script_ctx_t *ctx, jsval_t v, jsexcept_t *ei, double *ret)
{
VARIANT var;
HRESULT hres;
if(v.type == JSV_NUMBER) {
*ret = v.u.n;
return S_OK;
}
hres = jsval_to_variant(v, &var);
if(FAILED(hres))
return hres;
hres = to_number(ctx, &var, ei, ret);
VariantClear(&var);
return hres;
assert(0);
return E_FAIL;
}
/* ECMA-262 3rd Edition 9.4 */
@ -644,7 +619,7 @@ HRESULT to_integer(script_ctx_t *ctx, jsval_t v, jsexcept_t *ei, double *ret)
double n;
HRESULT hres;
hres = to_number_jsval(ctx, v, ei, &n);
hres = to_number(ctx, v, ei, &n);
if(FAILED(hres))
return hres;
@ -655,32 +630,13 @@ HRESULT to_integer(script_ctx_t *ctx, jsval_t v, jsexcept_t *ei, double *ret)
return S_OK;
}
/* ECMA-262 3rd Edition 9.5 */
HRESULT to_int32_var(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, INT *ret)
{
double n;
HRESULT hres;
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;
*ret = isnan(n) || isinf(n) ? 0 : n;
return S_OK;
}
/* ECMA-262 3rd Edition 9.5 */
HRESULT to_int32(script_ctx_t *ctx, jsval_t v, jsexcept_t *ei, INT *ret)
{
double n;
HRESULT hres;
hres = to_number_jsval(ctx, v, ei, &n);
hres = to_number(ctx, v, ei, &n);
if(FAILED(hres))
return hres;
@ -691,6 +647,7 @@ HRESULT to_int32(script_ctx_t *ctx, jsval_t v, jsexcept_t *ei, INT *ret)
/* ECMA-262 3rd Edition 9.6 */
HRESULT to_uint32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, DWORD *ret)
{
jsval_t val;
double n;
HRESULT hres;
@ -699,7 +656,12 @@ HRESULT to_uint32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, DWORD *ret)
return S_OK;
}
hres = to_number(ctx, v, ei, &n);
hres = variant_to_jsval(v, &val);
if(FAILED(hres))
return hres;
hres = to_number(ctx, val, ei, &n);
jsval_release(val);
if(FAILED(hres))
return hres;
@ -924,8 +886,13 @@ HRESULT to_object_jsval(script_ctx_t *ctx, jsval_t v, IDispatch **disp)
HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTYPE vt)
{
jsexcept_t ei;
jsval_t val;
HRESULT hres;
hres = variant_to_jsval(src, &val);
if(FAILED(hres))
return hres;
memset(&ei, 0, sizeof(ei));
switch(vt) {
@ -933,7 +900,7 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY
case VT_I4: {
INT i;
hres = to_int32_var(ctx, src, &ei, &i);
hres = to_int32(ctx, val, &ei, &i);
if(SUCCEEDED(hres)) {
if(vt == VT_I4)
V_I4(dst) = i;
@ -944,7 +911,7 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY
}
case VT_R8: {
double n;
hres = to_number(ctx, src, &ei, &n);
hres = to_number(ctx, val, &ei, &n);
if(SUCCEEDED(hres))
V_R8(dst) = n;
break;
@ -952,21 +919,15 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY
case VT_R4: {
double n;
hres = to_number(ctx, src, &ei, &n);
hres = to_number(ctx, val, &ei, &n);
if(SUCCEEDED(hres))
V_R4(dst) = n;
break;
}
case VT_BOOL: {
jsval_t val;
BOOL b;
hres = variant_to_jsval(src, &val);
if(FAILED(hres))
return hres;
hres = to_boolean(val, &b);
jsval_release(val);
if(SUCCEEDED(hres))
V_BOOL(dst) = b ? VARIANT_TRUE : VARIANT_FALSE;
break;
@ -990,6 +951,7 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY
hres = E_NOTIMPL;
}
jsval_release(val);
if(FAILED(hres)) {
jsval_release(ei.val);
return hres;

View File

@ -72,7 +72,7 @@ static HRESULT Math_abs(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &d);
hres = to_number(ctx, argv[0], ei, &d);
if(FAILED(hres))
return hres;
@ -95,7 +95,7 @@ static HRESULT Math_acos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -118,7 +118,7 @@ static HRESULT Math_asin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -141,7 +141,7 @@ static HRESULT Math_atan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -164,11 +164,11 @@ static HRESULT Math_atan2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &y);
hres = to_number(ctx, argv[0], ei, &y);
if(FAILED(hres))
return hres;
hres = to_number_jsval(ctx, argv[1], ei, &x);
hres = to_number(ctx, argv[1], ei, &x);
if(FAILED(hres))
return hres;
@ -192,7 +192,7 @@ static HRESULT Math_ceil(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -215,7 +215,7 @@ static HRESULT Math_cos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -238,7 +238,7 @@ static HRESULT Math_exp(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -261,7 +261,7 @@ static HRESULT Math_floor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -284,7 +284,7 @@ static HRESULT Math_log(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -309,12 +309,12 @@ static HRESULT Math_max(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &max);
hres = to_number(ctx, argv[0], ei, &max);
if(FAILED(hres))
return hres;
for(i=1; i < argc; i++) {
hres = to_number_jsval(ctx, argv[i], ei, &d);
hres = to_number(ctx, argv[i], ei, &d);
if(FAILED(hres))
return hres;
@ -343,12 +343,12 @@ static HRESULT Math_min(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &min);
hres = to_number(ctx, argv[0], ei, &min);
if(FAILED(hres))
return hres;
for(i=1; i < argc; i++) {
hres = to_number_jsval(ctx, argv[i], ei, &d);
hres = to_number(ctx, argv[i], ei, &d);
if(FAILED(hres))
return hres;
@ -376,11 +376,11 @@ static HRESULT Math_pow(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
hres = to_number_jsval(ctx, argv[1], ei, &y);
hres = to_number(ctx, argv[1], ei, &y);
if(FAILED(hres))
return hres;
@ -420,7 +420,7 @@ static HRESULT Math_round(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -443,7 +443,7 @@ static HRESULT Math_sin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -466,7 +466,7 @@ static HRESULT Math_sqrt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;
@ -489,7 +489,7 @@ static HRESULT Math_tan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &x);
hres = to_number(ctx, argv[0], ei, &x);
if(FAILED(hres))
return hres;

View File

@ -559,7 +559,7 @@ static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return S_OK;
}
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres))
return hres;
@ -571,7 +571,7 @@ static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
jsdisp_t *obj;
if(argc) {
hres = to_number_jsval(ctx, argv[0], ei, &n);
hres = to_number(ctx, argv[0], ei, &n);
if(FAILED(hres))
return hres;
}else {

View File

@ -3523,7 +3523,7 @@ static INT index_from_val(script_ctx_t *ctx, jsval_t v)
HRESULT hres;
memset(&ei, 0, sizeof(ei));
hres = to_number_jsval(ctx, v, &ei, &n);
hres = to_number(ctx, v, &ei, &n);
if(FAILED(hres)) { /* FIXME: Move ignoring exceptions to to_primitive */
jsval_release(ei.val);
return 0;