Commit acfd2b98 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Always use jsval-based to_string implementation.

parent 2fc71ab6
......@@ -164,7 +164,7 @@ static HRESULT ActiveXObject_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
return E_NOTIMPL;
}
hres = to_string_jsval(ctx, argv[0], ei, &progid);
hres = to_string(ctx, argv[0], ei, &progid);
if(FAILED(hres))
return hres;
......
......@@ -262,7 +262,7 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
break;
if(!is_undefined(val) && !is_null(val)) {
hres = to_string_jsval(ctx, val, ei, str_tab+i);
hres = to_string(ctx, val, ei, str_tab+i);
jsval_release(val);
if(FAILED(hres))
break;
......@@ -348,7 +348,7 @@ static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigne
if(argc) {
BSTR sep;
hres = to_string_jsval(ctx, argv[0], ei, &sep);
hres = to_string(ctx, argv[0], ei, &sep);
if(FAILED(hres))
return hres;
......@@ -656,11 +656,11 @@ static HRESULT sort_cmp(script_ctx_t *ctx, jsdisp_t *cmp_func, jsval_t v1, jsval
}else {
BSTR x, y;
hres = to_string_jsval(ctx, v1, ei, &x);
hres = to_string(ctx, v1, ei, &x);
if(FAILED(hres))
return hres;
hres = to_string_jsval(ctx, v2, ei, &y);
hres = to_string(ctx, v2, ei, &y);
if(SUCCEEDED(hres)) {
*cmp = strcmpW(x, y);
SysFreeString(y);
......
......@@ -2380,7 +2380,7 @@ static HRESULT DateConstr_parse(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &parse_str);
hres = to_string(ctx, argv[0], ei, &parse_str);
if(FAILED(hres))
return hres;
......
......@@ -812,7 +812,7 @@ static HRESULT interp_array(exec_ctx_t *ctx)
return hres;
}
hres = to_string_jsval(ctx->script, namev, ctx->ei, &name);
hres = to_string(ctx->script, namev, ctx->ei, &name);
jsval_release(namev);
if(FAILED(hres)) {
IDispatch_Release(obj);
......@@ -881,7 +881,7 @@ static HRESULT interp_memberid(exec_ctx_t *ctx)
hres = to_object_jsval(ctx->script, objv, &obj);
jsval_release(objv);
if(SUCCEEDED(hres)) {
hres = to_string_jsval(ctx->script, namev, ctx->ei, &name);
hres = to_string(ctx->script, namev, ctx->ei, &name);
if(FAILED(hres))
IDispatch_Release(obj);
}
......@@ -1380,7 +1380,7 @@ static HRESULT interp_in(exec_ctx_t *ctx)
}
v = stack_pop(ctx);
hres = to_string_jsval(ctx->script, v, ctx->ei, &str);
hres = to_string(ctx->script, v, ctx->ei, &str);
jsval_release(v);
if(FAILED(hres)) {
IDispatch_Release(get_object(obj));
......@@ -1422,13 +1422,13 @@ static HRESULT add_eval(script_ctx_t *ctx, jsval_t lval, jsval_t rval, jsexcept_
if(is_string(l))
lstr = get_string(l);
else
hres = to_string_jsval(ctx, l, ei, &lstr);
hres = to_string(ctx, l, ei, &lstr);
if(SUCCEEDED(hres)) {
if(is_string(r))
rstr = get_string(r);
else
hres = to_string_jsval(ctx, r, ei, &rstr);
hres = to_string(ctx, r, ei, &rstr);
}
if(SUCCEEDED(hres)) {
......@@ -1585,7 +1585,7 @@ static HRESULT interp_delete(exec_ctx_t *ctx)
return hres;
}
hres = to_string_jsval(ctx->script, namev, ctx->ei, &name);
hres = to_string(ctx->script, namev, ctx->ei, &name);
jsval_release(namev);
if(FAILED(hres)) {
IDispatch_Release(obj);
......
......@@ -62,7 +62,7 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
return hres;
if(!is_undefined(v)) {
hres = to_string_jsval(ctx, v, ei, &name);
hres = to_string(ctx, v, ei, &name);
jsval_release(v);
if(FAILED(hres))
return hres;
......@@ -75,7 +75,7 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
hres = jsdisp_propget_name(jsthis, messageW, &v, ei);
if(SUCCEEDED(hres)) {
if(!is_undefined(v)) {
hres = to_string_jsval(ctx, v, ei, &msg);
hres = to_string(ctx, v, ei, &msg);
jsval_release(v);
if(SUCCEEDED(hres) && !*msg) {
SysFreeString(msg);
......@@ -235,14 +235,14 @@ static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, jsval_
if(FAILED(hres)) /* FIXME: really? */
n = NAN;
if(isnan(n))
hres = to_string_jsval(ctx, argv[0], ei, &msg);
hres = to_string(ctx, argv[0], ei, &msg);
if(FAILED(hres))
return hres;
num = n;
}
if(argc>1 && !msg) {
hres = to_string_jsval(ctx, argv[1], ei, &msg);
hres = to_string(ctx, argv[1], ei, &msg);
if(FAILED(hres))
return hres;
}
......
......@@ -711,7 +711,7 @@ static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *arg
if(argc > 2)
len = (argc-2)*2; /* separating commas */
for(i=0; i < argc; i++) {
hres = to_string_jsval(ctx, argv[i], ei, params+i);
hres = to_string(ctx, argv[i], ei, params+i);
if(FAILED(hres))
break;
len += SysStringLen(params[i]);
......
......@@ -297,7 +297,7 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &str);
hres = to_string(ctx, argv[0], ei, &str);
if(FAILED(hres))
return hres;
......@@ -469,7 +469,7 @@ static HRESULT JSGlobal_parseInt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
}
}
hres = to_string_jsval(ctx, argv[0], ei, &str);
hres = to_string(ctx, argv[0], ei, &str);
if(FAILED(hres))
return hres;
......@@ -536,7 +536,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &val_str);
hres = to_string(ctx, argv[0], ei, &val_str);
if(FAILED(hres))
return hres;
......@@ -648,7 +648,7 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &str);
hres = to_string(ctx, argv[0], ei, &str);
if(FAILED(hres))
return hres;
......@@ -789,7 +789,7 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &str);
hres = to_string(ctx, argv[0], ei, &str);
if(FAILED(hres))
return hres;
......@@ -860,7 +860,7 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &str);
hres = to_string(ctx, argv[0], ei, &str);
if(FAILED(hres))
return hres;
......@@ -951,7 +951,7 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &str);
hres = to_string(ctx, argv[0], ei, &str);
if(FAILED(hres))
return hres;
......@@ -1021,7 +1021,7 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &str);
hres = to_string(ctx, argv[0], ei, &str);
if(FAILED(hres))
return hres;
......
......@@ -260,8 +260,7 @@ 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(script_ctx_t*,jsval_t,jsexcept_t*,INT*) DECLSPEC_HIDDEN;
HRESULT to_uint32(script_ctx_t*,jsval_t,jsexcept_t*,DWORD*) DECLSPEC_HIDDEN;
HRESULT to_string(script_ctx_t*,VARIANT*,jsexcept_t*,BSTR*) DECLSPEC_HIDDEN;
HRESULT to_string_jsval(script_ctx_t*,jsval_t,jsexcept_t*,BSTR*) DECLSPEC_HIDDEN;
HRESULT to_string(script_ctx_t*,jsval_t,jsexcept_t*,BSTR*) DECLSPEC_HIDDEN;
HRESULT to_object(script_ctx_t*,VARIANT*,IDispatch**) DECLSPEC_HIDDEN;
HRESULT to_object_jsval(script_ctx_t*,jsval_t,IDispatch**) DECLSPEC_HIDDEN;
......
......@@ -697,6 +697,8 @@ HRESULT double_to_bstr(double n, BSTR *str)
*str = SysAllocString(NaNW);
}else if(isinf(n)) {
*str = SysAllocString(n<0 ? InfinityW : InfinityW+1);
}else if(is_int32(n)) {
*str = int_to_bstr(n);
}else {
VARIANT strv, v;
HRESULT hres;
......@@ -715,71 +717,48 @@ HRESULT double_to_bstr(double n, BSTR *str)
}
/* ECMA-262 3rd Edition 9.8 */
HRESULT to_string(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, BSTR *str)
HRESULT to_string(script_ctx_t *ctx, jsval_t val, jsexcept_t *ei, BSTR *str)
{
const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
const WCHAR nullW[] = {'n','u','l','l',0};
const WCHAR trueW[] = {'t','r','u','e',0};
const WCHAR falseW[] = {'f','a','l','s','e',0};
switch(V_VT(v)) {
case VT_EMPTY:
switch(val.type) {
case JSV_UNDEFINED:
*str = SysAllocString(undefinedW);
break;
case VT_NULL:
case JSV_NULL:
*str = SysAllocString(nullW);
break;
case VT_I4:
*str = int_to_bstr(V_I4(v));
break;
case VT_R8:
return double_to_bstr(V_R8(v), str);
case VT_BSTR:
*str = SysAllocString(V_BSTR(v));
case JSV_NUMBER:
return double_to_bstr(get_number(val), str);
case JSV_STRING:
*str = clone_bstr(get_string(val));
break;
case VT_DISPATCH: {
case JSV_OBJECT: {
jsval_t prim;
HRESULT hres;
hres = to_primitive(ctx, jsval_disp(V_DISPATCH(v)), ei, &prim, HINT_STRING);
hres = to_primitive(ctx, val, ei, &prim, HINT_STRING);
if(FAILED(hres))
return hres;
hres = to_string_jsval(ctx, prim, ei, str);
hres = to_string(ctx, prim, ei, str);
jsval_release(prim);
return hres;
}
case VT_BOOL:
*str = SysAllocString(V_BOOL(v) ? trueW : falseW);
case JSV_BOOL:
*str = SysAllocString(get_bool(val) ? trueW : falseW);
break;
default:
FIXME("unsupported vt %d\n", V_VT(v));
FIXME("unsupported %s\n", debugstr_jsval(val));
return E_NOTIMPL;
}
return *str ? S_OK : E_OUTOFMEMORY;
}
/* ECMA-262 3rd Edition 9.8 */
HRESULT to_string_jsval(script_ctx_t *ctx, jsval_t v, jsexcept_t *ei, BSTR *str)
{
VARIANT var;
HRESULT hres;
if(v.type == JSV_STRING) {
*str = clone_bstr(v.u.str);
return *str ? S_OK : E_OUTOFMEMORY;
}
hres = jsval_to_variant(v, &var);
if(FAILED(hres))
return hres;
hres = to_string(ctx, &var, ei, str);
VariantClear(&var);
return hres;
}
/* ECMA-262 3rd Edition 9.9 */
HRESULT to_object(script_ctx_t *ctx, VARIANT *v, IDispatch **disp)
{
......@@ -909,7 +888,7 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY
case VT_BSTR: {
BSTR str;
hres = to_string(ctx, src, &ei, &str);
hres = to_string(ctx, val, &ei, &str);
if(SUCCEEDED(hres))
V_BSTR(dst) = str;
break;
......
......@@ -244,10 +244,7 @@ static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
val = number->value;
if(radix==10 || isnan(val) || isinf(val)) {
VARIANT v;
num_set_val(&v, val);
hres = to_string(ctx, &v, ei, &str);
hres = to_string(ctx, jsval_number(val), ei, &str);
if(FAILED(hres))
return hres;
}else {
......@@ -373,10 +370,7 @@ static HRESULT Number_toFixed(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
val = number->value;
if(isinf(val) || isnan(val)) {
VARIANT v;
num_set_val(&v, val);
hres = to_string(ctx, &v, ei, &str);
hres = to_string(ctx, jsval_number(val), ei, &str);
if(FAILED(hres))
return hres;
}else {
......@@ -415,10 +409,7 @@ static HRESULT Number_toExponential(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla
val = number->value;
if(isinf(val) || isnan(val)) {
VARIANT v;
num_set_val(&v, val);
hres = to_string(ctx, &v, ei, &str);
hres = to_string(ctx, jsval_number(val), ei, &str);
if(FAILED(hres))
return hres;
}else {
......@@ -457,10 +448,7 @@ static HRESULT Number_toPrecision(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
val = number->value;
if(isinf(val) || isnan(val) || !prec) {
VARIANT v;
num_set_val(&v, val);
hres = to_string(ctx, &v, ei, &str);
hres = to_string(ctx, jsval_number(val), ei, &str);
if(FAILED(hres))
return hres;
}else {
......
......@@ -118,7 +118,7 @@ static HRESULT Object_hasOwnProperty(script_ctx_t *ctx, vdisp_t *jsthis, WORD fl
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &name);
hres = to_string(ctx, argv[0], ei, &name);
if(FAILED(hres))
return hres;
......
......@@ -3648,7 +3648,7 @@ static HRESULT run_exec(script_ctx_t *ctx, vdisp_t *jsthis, jsval_t arg, jsexcep
regexp = regexp_from_vdisp(jsthis);
hres = to_string_jsval(ctx, arg, ei, &string);
hres = to_string(ctx, arg, ei, &string);
if(FAILED(hres))
return hres;
length = SysStringLen(string);
......
......@@ -81,7 +81,6 @@ static HRESULT get_string_val(script_ctx_t *ctx, vdisp_t *jsthis, jsexcept_t *ei
const WCHAR **str, DWORD *len, BSTR *val_str)
{
StringInstance *string;
VARIANT this_var;
HRESULT hres;
if((string = string_this(jsthis))) {
......@@ -91,9 +90,7 @@ static HRESULT get_string_val(script_ctx_t *ctx, vdisp_t *jsthis, jsexcept_t *ei
return S_OK;
}
V_VT(&this_var) = VT_DISPATCH;
V_DISPATCH(&this_var) = jsthis->u.disp;
hres = to_string(ctx, &this_var, ei, val_str);
hres = to_string(ctx, jsval_disp(jsthis->u.disp), ei, val_str);
if(FAILED(hres))
return hres;
......@@ -202,12 +199,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
HRESULT hres;
if(!(string = string_this(jsthis))) {
VARIANT this;
V_VT(&this) = VT_DISPATCH;
V_DISPATCH(&this) = jsthis->u.disp;
hres = to_string(ctx, &this, ei, &val_str);
hres = to_string(ctx, jsval_disp(jsthis->u.disp), ei, &val_str);
if(FAILED(hres))
return hres;
......@@ -220,7 +212,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
}
if(argc) {
hres = to_string_jsval(ctx, argv[0], ei, &attr_value);
hres = to_string(ctx, argv[0], ei, &attr_value);
if(FAILED(hres)) {
SysFreeString(val_str);
return hres;
......@@ -374,7 +366,6 @@ static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
{
BSTR *strs = NULL, ret = NULL;
DWORD len = 0, i, l, str_cnt;
VARIANT var;
WCHAR *ptr;
HRESULT hres;
......@@ -385,13 +376,10 @@ static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
if(!strs)
return E_OUTOFMEMORY;
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = jsthis->u.disp;
hres = to_string(ctx, &var, ei, strs);
hres = to_string(ctx, jsval_disp(jsthis->u.disp), ei, strs);
if(SUCCEEDED(hres)) {
for(i=0; i < argc; i++) {
hres = to_string_jsval(ctx, argv[i], ei, strs+i+1);
hres = to_string(ctx, argv[i], ei, strs+i+1);
if(FAILED(hres))
break;
}
......@@ -471,7 +459,7 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &search_str);
hres = to_string(ctx, argv[0], ei, &search_str);
if(FAILED(hres)) {
SysFreeString(val_str);
return hres;
......@@ -535,7 +523,7 @@ static HRESULT String_lastIndexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return S_OK;
}
hres = to_string_jsval(ctx, argv[0], ei, &search_str);
hres = to_string(ctx, argv[0], ei, &search_str);
if(FAILED(hres)) {
SysFreeString(val_str);
return hres;
......@@ -612,7 +600,7 @@ static HRESULT String_match(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(!regexp) {
BSTR match_str;
hres = to_string_jsval(ctx, argv[0], ei, &match_str);
hres = to_string(ctx, argv[0], ei, &match_str);
if(FAILED(hres))
return hres;
......@@ -723,7 +711,7 @@ static HRESULT rep_call(script_ctx_t *ctx, jsdisp_t *func, const WCHAR *str, mat
if(FAILED(hres))
return hres;
hres = to_string_jsval(ctx, val, ei, ret);
hres = to_string(ctx, val, ei, ret);
jsval_release(val);
return hres;
}
......@@ -769,7 +757,7 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
}
if(!regexp) {
hres = to_string_jsval(ctx, argv[0], ei, &match_str);
hres = to_string(ctx, argv[0], ei, &match_str);
if(FAILED(hres)) {
SysFreeString(val_str);
return hres;
......@@ -786,7 +774,7 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
}
if(!rep_func) {
hres = to_string_jsval(ctx, argv[1], ei, &rep_str);
hres = to_string(ctx, argv[1], ei, &rep_str);
if(SUCCEEDED(hres)) {
rep_len = SysStringLen(rep_str);
if(!strchrW(rep_str, '$'))
......@@ -1130,7 +1118,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
}
if(!use_regexp) {
hres = to_string_jsval(ctx, argv[0], ei, &match_str);
hres = to_string(ctx, argv[0], ei, &match_str);
if(FAILED(hres)) {
SysFreeString(val_str);
return hres;
......@@ -1559,7 +1547,7 @@ static HRESULT StringConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
BSTR str;
if(argc) {
hres = to_string_jsval(ctx, argv[0], ei, &str);
hres = to_string(ctx, argv[0], ei, &str);
if(FAILED(hres))
return hres;
}else {
......@@ -1577,7 +1565,7 @@ static HRESULT StringConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(argc) {
BSTR str;
hres = to_string_jsval(ctx, argv[0], ei, &str);
hres = to_string(ctx, argv[0], ei, &str);
if(FAILED(hres))
return hres;
......
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