Commit 932b3dd0 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added new variable representation and use it for internal function return values.

parent b57323a6
......@@ -139,7 +139,7 @@ static IUnknown *create_activex_object(script_ctx_t *ctx, const WCHAR *progid)
}
static HRESULT ActiveXObject_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
IDispatch *disp;
IUnknown *obj;
......@@ -180,8 +180,7 @@ static HRESULT ActiveXObject_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
return E_NOTIMPL;
}
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = disp;
*r = jsval_disp(disp);
return S_OK;
}
......
......@@ -117,7 +117,7 @@ static WCHAR *idx_to_str(DWORD idx, WCHAR *ptr)
}
static HRESULT Array_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
ArrayInstance *This = array_from_vdisp(jsthis);
......@@ -125,7 +125,7 @@ static HRESULT Array_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
switch(flags) {
case DISPATCH_PROPERTYGET:
num_set_int(retv, This->length);
*r = jsval_number(This->length);
break;
case DISPATCH_PROPERTYPUT: {
DOUBLE len = -1;
......@@ -202,7 +202,7 @@ static HRESULT concat_obj(jsdisp_t *array, IDispatch *obj, DWORD *len, jsexcept_
}
static HRESULT Array_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *ret;
DWORD len = 0;
......@@ -233,14 +233,14 @@ static HRESULT Array_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(FAILED(hres))
return hres;
if(retv)
var_set_jsdisp(retv, ret);
if(r)
*r = jsval_obj(ret);
else
jsdisp_release(ret);
return S_OK;
}
static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, VARIANT *retv, jsexcept_t *ei)
static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, jsval_t *r, jsexcept_t *ei)
{
BSTR *str_tab, ret = NULL;
VARIANT var;
......@@ -248,11 +248,11 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
HRESULT hres = E_FAIL;
if(!length) {
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocStringLen(NULL, 0);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocStringLen(NULL, 0);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK;
}
......@@ -323,15 +323,14 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
TRACE("= %s\n", debugstr_w(ret));
if(retv) {
if(r) {
if(!ret) {
ret = SysAllocStringLen(NULL, 0);
if(!ret)
return E_OUTOFMEMORY;
}
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}else {
SysFreeString(ret);
}
......@@ -341,7 +340,7 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
/* ECMA-262 3rd Edition 15.4.4.5 */
static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsthis;
DWORD length;
......@@ -360,18 +359,18 @@ static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
hres = array_join(ctx, jsthis, length, sep, retv, ei);
hres = array_join(ctx, jsthis, length, sep, r, ei);
SysFreeString(sep);
}else {
hres = array_join(ctx, jsthis, length, default_separatorW, retv, ei);
hres = array_join(ctx, jsthis, length, default_separatorW, r, ei);
}
return hres;
}
static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsthis;
VARIANT val;
......@@ -389,8 +388,8 @@ static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned
if(FAILED(hres))
return hres;
if(retv)
V_VT(retv) = VT_EMPTY;
if(r)
*r = jsval_undefined();
return S_OK;
}
......@@ -412,17 +411,15 @@ static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned
return hres;
}
if(retv)
*retv = val;
else
VariantClear(&val);
return S_OK;
if(r)
hres = variant_to_jsval(&val, r);
VariantClear(&val);
return hres;
}
/* ECMA-262 3rd Edition 15.4.4.7 */
static HRESULT Array_push(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsthis;
DWORD length = 0;
......@@ -445,13 +442,13 @@ static HRESULT Array_push(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
if(retv)
num_set_int(retv, length+argc);
if(r)
*r = jsval_number(length+argc);
return S_OK;
}
static HRESULT Array_reverse(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsthis;
DWORD length, k, l;
......@@ -499,17 +496,14 @@ static HRESULT Array_reverse(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsi
}
}
if(retv) {
jsdisp_addref(jsthis);
var_set_jsdisp(retv, jsthis);
}
if(r)
*r = jsval_obj(jsdisp_addref(jsthis));
return S_OK;
}
/* ECMA-262 3rd Edition 15.4.4.9 */
static HRESULT Array_shift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsthis;
DWORD length = 0, i;
......@@ -529,8 +523,8 @@ static HRESULT Array_shift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsign
}
if(!length) {
if(retv)
V_VT(retv) = VT_EMPTY;
if(r)
*r = jsval_undefined();
return S_OK;
}
......@@ -554,16 +548,15 @@ static HRESULT Array_shift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsign
hres = set_length(jsthis, ei, length-1);
}
if(SUCCEEDED(hres) && retv)
*retv = ret;
else
VariantClear(&ret);
if(SUCCEEDED(hres) && r)
hres = variant_to_jsval(&ret, r);
VariantClear(&ret);
return hres;
}
/* ECMA-262 3rd Edition 15.4.4.10 */
static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *arr, *jsthis;
DOUBLE range;
......@@ -624,8 +617,8 @@ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsign
}
}
if(retv)
var_set_jsdisp(retv, arr);
if(r)
*r = jsval_obj(arr);
else
jsdisp_release(arr);
......@@ -639,7 +632,7 @@ static HRESULT sort_cmp(script_ctx_t *ctx, jsdisp_t *cmp_func, VARIANT *v1, VARI
if(cmp_func) {
VARIANTARG args[2];
double n;
VARIANT res;
jsval_t res;
args[0] = *v1;
args[1] = *v2;
......@@ -648,8 +641,8 @@ static HRESULT sort_cmp(script_ctx_t *ctx, jsdisp_t *cmp_func, VARIANT *v1, VARI
if(FAILED(hres))
return hres;
hres = to_number(ctx, &res, ei, &n);
VariantClear(&res);
hres = to_number_jsval(ctx, res, ei, &n);
jsval_release(res);
if(FAILED(hres))
return hres;
......@@ -688,7 +681,7 @@ static HRESULT sort_cmp(script_ctx_t *ctx, jsdisp_t *cmp_func, VARIANT *v1, VARI
/* ECMA-262 3rd Edition 15.4.4.11 */
static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsthis, *cmp_func = NULL;
VARIANT *vtab, **sorttab = NULL;
......@@ -726,10 +719,8 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigne
if(!length) {
if(cmp_func)
jsdisp_release(cmp_func);
if(retv) {
jsdisp_addref(jsthis);
var_set_jsdisp(retv, jsthis);
}
if(r)
*r = jsval_obj(jsdisp_addref(jsthis));
return S_OK;
}
......@@ -831,17 +822,14 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
if(retv) {
jsdisp_addref(jsthis);
var_set_jsdisp(retv, jsthis);
}
if(r)
*r = jsval_obj(jsdisp_addref(jsthis));
return S_OK;
}
/* ECMA-262 3rd Edition 15.4.4.12 */
static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DWORD length, start=0, delete_cnt=0, i, add_args = 0;
jsdisp_t *ret_array = NULL, *jsthis;
......@@ -886,7 +874,7 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsig
add_args = argc-2;
}
if(retv) {
if(r) {
hres = create_array(ctx, 0, &ret_array);
if(FAILED(hres))
return hres;
......@@ -940,14 +928,14 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsig
return hres;
}
if(retv)
var_set_jsdisp(retv, ret_array);
if(r)
*r = jsval_obj(ret_array);
return S_OK;
}
/* ECMA-262 3rd Edition 15.4.4.2 */
static HRESULT Array_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
ArrayInstance *array;
......@@ -957,11 +945,11 @@ static HRESULT Array_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
if(!array)
return throw_type_error(ctx, ei, JS_E_ARRAY_EXPECTED, NULL);
return array_join(ctx, &array->dispex, array->length, default_separatorW, retv, ei);
return array_join(ctx, &array->dispex, array->length, default_separatorW, r, ei);
}
static HRESULT Array_toLocaleString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
......@@ -969,7 +957,7 @@ static HRESULT Array_toLocaleString(script_ctx_t *ctx, vdisp_t *vthis, WORD flag
/* ECMA-262 3rd Edition 15.4.4.13 */
static HRESULT Array_unshift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsthis;
WCHAR buf[14], *buf_end, *str;
......@@ -1022,17 +1010,13 @@ static HRESULT Array_unshift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsi
return hres;
}
if(retv) {
if(ctx->version < 2)
V_VT(retv) = VT_EMPTY;
else
num_set_int(retv, length);
}
if(r)
*r = ctx->version < 2 ? jsval_undefined() : jsval_number(length);
return S_OK;
}
static HRESULT Array_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -1040,7 +1024,7 @@ static HRESULT Array_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsig
case INVOKE_FUNC:
return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
case INVOKE_PROPERTYGET:
return array_join(ctx, jsthis->u.jsdisp, array_from_vdisp(jsthis)->length, default_separatorW, retv, ei);
return array_join(ctx, jsthis->u.jsdisp, array_from_vdisp(jsthis)->length, default_separatorW, r, ei);
default:
FIXME("unimplemented flags %x\n", flags);
return E_NOTIMPL;
......@@ -1114,7 +1098,7 @@ static const builtin_info_t ArrayInst_info = {
};
static HRESULT ArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *obj;
DWORD i;
......@@ -1133,7 +1117,7 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
if(FAILED(hres))
return hres;
var_set_jsdisp(retv, obj);
*r = jsval_obj(obj);
return S_OK;
}
......@@ -1151,7 +1135,7 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
return hres;
}
var_set_jsdisp(retv, obj);
*r = jsval_obj(obj);
break;
}
default:
......
......@@ -39,7 +39,7 @@ static inline BoolInstance *bool_this(vdisp_t *jsthis)
/* ECMA-262 3rd Edition 15.6.4.2 */
static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BoolInstance *bool;
......@@ -51,7 +51,7 @@ static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
if(!(bool = bool_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_BOOLEAN_EXPECTED, NULL);
if(retv) {
if(r) {
BSTR val;
if(bool->val) val = SysAllocString(trueW);
......@@ -60,8 +60,7 @@ static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
if(!val)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = val;
*r = jsval_string(val);
}
return S_OK;
......@@ -69,7 +68,7 @@ static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
/* ECMA-262 3rd Edition 15.6.4.3 */
static HRESULT Bool_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BoolInstance *bool;
......@@ -78,16 +77,13 @@ static HRESULT Bool_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(!(bool = bool_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_BOOLEAN_EXPECTED, NULL);
if(retv) {
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = bool->val;
}
if(r)
*r = jsval_bool(bool->val);
return S_OK;
}
static HRESULT Bool_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -126,7 +122,7 @@ static const builtin_info_t BoolInst_info = {
};
static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
HRESULT hres;
VARIANT_BOOL value = VARIANT_FALSE;
......@@ -145,15 +141,13 @@ static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(FAILED(hres))
return hres;
var_set_jsdisp(retv, bool);
*r = jsval_obj(bool);
return S_OK;
}
case INVOKE_FUNC:
if(retv) {
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = value;
}
if(r)
*r = jsval_bool(value);
return S_OK;
default:
......
......@@ -465,7 +465,7 @@ static SYSTEMTIME create_systemtime(DOUBLE time)
return st;
}
static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset, VARIANT *retv)
static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset, jsval_t *r)
{
static const WCHAR NaNW[] = { 'N','a','N',0 };
static const WCHAR formatW[] = { '%','s',' ','%','s',' ','%','d',' ',
......@@ -498,16 +498,16 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
WCHAR sign = '-';
if(isnan(time)) {
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(NaNW);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocString(NaNW);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK;
}
if(retv) {
if(r) {
len = 21;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
......@@ -583,14 +583,13 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
SysFreeString(week);
SysFreeString(month);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = date_str;
*r = jsval_string(date_str);
}
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.1.2 */
static HRESULT dateobj_to_string(DateInstance *date, VARIANT *retv)
static HRESULT dateobj_to_string(DateInstance *date, jsval_t *r)
{
DOUBLE time;
int offset;
......@@ -599,11 +598,11 @@ static HRESULT dateobj_to_string(DateInstance *date, VARIANT *retv)
offset = date->bias +
daylight_saving_ta(time, date);
return date_to_string(time, TRUE, offset, retv);
return date_to_string(time, TRUE, offset, r);
}
static HRESULT Date_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -612,12 +611,12 @@ static HRESULT Date_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
return dateobj_to_string(date, retv);
return dateobj_to_string(date, r);
}
/* ECMA-262 3rd Edition 15.9.1.5 */
static HRESULT Date_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR NaNW[] = { 'N','a','N',0 };
SYSTEMTIME st;
......@@ -631,11 +630,11 @@ static HRESULT Date_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(isnan(date->time)) {
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(NaNW);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocString(NaNW);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK;
}
......@@ -643,9 +642,9 @@ static HRESULT Date_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
st = create_systemtime(local_time(date->time, date));
if(st.wYear<1601 || st.wYear>9999)
return dateobj_to_string(date, retv);
return dateobj_to_string(date, r);
if(retv) {
if(r) {
date_len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
time_len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
date_str = SysAllocStringLen(NULL, date_len+time_len-1);
......@@ -655,14 +654,13 @@ static HRESULT Date_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
GetTimeFormatW(ctx->lcid, 0, &st, NULL, &date_str[date_len], time_len);
date_str[date_len-1] = ' ';
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = date_str;
*r = jsval_string(date_str);
}
return S_OK;
}
static HRESULT Date_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -671,13 +669,13 @@ static HRESULT Date_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR NaNW[] = { 'N','a','N',0 };
static const WCHAR formatADW[] = { '%','s',',',' ','%','d',' ','%','s',' ','%','d',' ',
......@@ -706,16 +704,16 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis,
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(isnan(date->time)) {
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(NaNW);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocString(NaNW);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK;
}
if(retv) {
if(r) {
len = 17;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
......@@ -773,29 +771,28 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis,
SysFreeString(week);
SysFreeString(month);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = date_str;
*r = jsval_string(date_str);
}
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.42 */
static HRESULT Date_toUTCString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return create_utc_string(ctx, jsthis, retv, ei);
return create_utc_string(ctx, jsthis, r, ei);
}
static HRESULT Date_toGMTString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return create_utc_string(ctx, jsthis, retv, ei);
return create_utc_string(ctx, jsthis, r, ei);
}
/* ECMA-262 3rd Edition 15.9.5.3 */
static HRESULT dateobj_to_date_string(DateInstance *date, VARIANT *retv)
static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
{
static const WCHAR NaNW[] = { 'N','a','N',0 };
static const WCHAR formatADW[] = { '%','s',' ','%','s',' ','%','d',' ','%','d',0 };
......@@ -819,18 +816,18 @@ static HRESULT dateobj_to_date_string(DateInstance *date, VARIANT *retv)
DWORD lcid_en, week_id, month_id;
if(isnan(date->time)) {
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(NaNW);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocString(NaNW);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK;
}
time = local_time(date->time, date);
if(retv) {
if(r) {
len = 5;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
......@@ -886,26 +883,25 @@ static HRESULT dateobj_to_date_string(DateInstance *date, VARIANT *retv)
SysFreeString(week);
SysFreeString(month);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = date_str;
*r = jsval_string(date_str);
}
return S_OK;
}
static HRESULT Date_toDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
return dateobj_to_date_string(date, retv);
return dateobj_to_date_string(date, r);
}
/* ECMA-262 3rd Edition 15.9.5.4 */
static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR NaNW[] = { 'N','a','N',0 };
static const WCHAR formatW[] = { '%','0','2','d',':','%','0','2','d',':','%','0','2','d',
......@@ -924,18 +920,17 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(isnan(date->time)) {
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(NaNW);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocString(NaNW);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK;
}
time = local_time(date->time, date);
if(retv) {
if(r) {
date_str = SysAllocStringLen(NULL, 17);
if(!date_str)
return E_OUTOFMEMORY;
......@@ -957,15 +952,14 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
sprintfW(date_str, formatUTCW, (int)hour_from_time(time),
(int)min_from_time(time), (int)sec_from_time(time));
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = date_str;
*r = jsval_string(date_str);
}
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.6 */
static HRESULT Date_toLocaleDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR NaNW[] = { 'N','a','N',0 };
SYSTEMTIME st;
......@@ -979,11 +973,11 @@ static HRESULT Date_toLocaleDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(isnan(date->time)) {
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(NaNW);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocString(NaNW);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK;
}
......@@ -991,24 +985,23 @@ static HRESULT Date_toLocaleDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
st = create_systemtime(local_time(date->time, date));
if(st.wYear<1601 || st.wYear>9999)
return dateobj_to_date_string(date, retv);
return dateobj_to_date_string(date, r);
if(retv) {
if(r) {
len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
date_str = SysAllocStringLen(NULL, len);
if(!date_str)
return E_OUTOFMEMORY;
GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, date_str, len);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = date_str;
*r = jsval_string(date_str);
}
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.7 */
static HRESULT Date_toLocaleTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR NaNW[] = { 'N','a','N',0 };
SYSTEMTIME st;
......@@ -1022,11 +1015,11 @@ static HRESULT Date_toLocaleTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(isnan(date->time)) {
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(NaNW);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocString(NaNW);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK;
}
......@@ -1034,24 +1027,23 @@ static HRESULT Date_toLocaleTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
st = create_systemtime(local_time(date->time, date));
if(st.wYear<1601 || st.wYear>9999)
return Date_toTimeString(ctx, jsthis, flags, argc, argv, retv, ei);
return Date_toTimeString(ctx, jsthis, flags, argc, argv, r, ei);
if(retv) {
if(r) {
len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
date_str = SysAllocStringLen(NULL, len);
if(!date_str)
return E_OUTOFMEMORY;
GetTimeFormatW(ctx->lcid, 0, &st, NULL, date_str, len);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = date_str;
*r = jsval_string(date_str);
}
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.9 */
static HRESULT Date_getTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1060,14 +1052,14 @@ static HRESULT Date_getTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.10 */
static HRESULT Date_getFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1076,17 +1068,17 @@ static HRESULT Date_getFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv) {
if(r) {
DOUBLE time = local_time(date->time, date);
num_set_val(retv, year_from_time(time));
*r = jsval_number(year_from_time(time));
}
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.11 */
static HRESULT Date_getUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1095,14 +1087,14 @@ static HRESULT Date_getUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, year_from_time(date->time));
if(r)
*r = jsval_number(year_from_time(date->time));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.12 */
static HRESULT Date_getMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1111,17 +1103,14 @@ static HRESULT Date_getMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv) {
DOUBLE time = local_time(date->time, date);
num_set_val(retv, month_from_time(time));
}
if(r)
*r = jsval_number(month_from_time(local_time(date->time, date)));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.13 */
static HRESULT Date_getUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1130,14 +1119,14 @@ static HRESULT Date_getUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, month_from_time(date->time));
if(r)
*r = jsval_number(month_from_time(date->time));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.14 */
static HRESULT Date_getDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1146,17 +1135,14 @@ static HRESULT Date_getDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv) {
DOUBLE time = local_time(date->time, date);
num_set_val(retv, date_from_time(time));
}
if(r)
*r = jsval_number(date_from_time(local_time(date->time, date)));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.15 */
static HRESULT Date_getUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1165,14 +1151,14 @@ static HRESULT Date_getUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, date_from_time(date->time));
if(r)
*r = jsval_number(date_from_time(date->time));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.16 */
static HRESULT Date_getDay(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1181,17 +1167,14 @@ static HRESULT Date_getDay(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsig
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv) {
DOUBLE time = local_time(date->time, date);
num_set_val(retv, week_day(time));
}
if(r)
*r = jsval_number(week_day(local_time(date->time, date)));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.17 */
static HRESULT Date_getUTCDay(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1200,14 +1183,14 @@ static HRESULT Date_getUTCDay(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, week_day(date->time));
if(r)
*r = jsval_number(week_day(date->time));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.18 */
static HRESULT Date_getHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1216,17 +1199,14 @@ static HRESULT Date_getHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv) {
DOUBLE time = local_time(date->time, date);
num_set_val(retv, hour_from_time(time));
}
if(r)
*r = jsval_number(hour_from_time(local_time(date->time, date)));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.19 */
static HRESULT Date_getUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1235,14 +1215,14 @@ static HRESULT Date_getUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, hour_from_time(date->time));
if(r)
*r = jsval_number(hour_from_time(date->time));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.20 */
static HRESULT Date_getMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1251,17 +1231,14 @@ static HRESULT Date_getMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv) {
DOUBLE time = local_time(date->time, date);
num_set_val(retv, min_from_time(time));
}
if(r)
*r = jsval_number(min_from_time(local_time(date->time, date)));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.21 */
static HRESULT Date_getUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1270,14 +1247,14 @@ static HRESULT Date_getUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, min_from_time(date->time));
if(r)
*r = jsval_number(min_from_time(date->time));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.22 */
static HRESULT Date_getSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1286,17 +1263,14 @@ static HRESULT Date_getSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv) {
DOUBLE time = local_time(date->time, date);
num_set_val(retv, sec_from_time(time));
}
if(r)
*r = jsval_number(sec_from_time(local_time(date->time, date)));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.23 */
static HRESULT Date_getUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1305,14 +1279,14 @@ static HRESULT Date_getUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, sec_from_time(date->time));
if(r)
*r = jsval_number(sec_from_time(date->time));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.24 */
static HRESULT Date_getMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1321,17 +1295,14 @@ static HRESULT Date_getMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv) {
DOUBLE time = local_time(date->time, date);
num_set_val(retv, ms_from_time(time));
}
if(r)
*r = jsval_number(ms_from_time(local_time(date->time, date)));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.25 */
static HRESULT Date_getUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1340,14 +1311,14 @@ static HRESULT Date_getUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, ms_from_time(date->time));
if(r)
*r = jsval_number(ms_from_time(date->time));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.26 */
static HRESULT Date_getTimezoneOffset(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
......@@ -1356,15 +1327,14 @@ static HRESULT Date_getTimezoneOffset(script_ctx_t *ctx, vdisp_t *jsthis, WORD f
if(!(date = date_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_DATE_EXPECTED, NULL);
if(retv)
num_set_val(retv, floor(
(date->time-local_time(date->time, date))/MS_PER_MINUTE));
if(r)
*r = jsval_number(floor((date->time-local_time(date->time, date))/MS_PER_MINUTE));
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.27 */
static HRESULT Date_setTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double n;
HRESULT hres;
......@@ -1384,15 +1354,14 @@ static HRESULT Date_setTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
date->time = time_clip(n);
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.28 */
static HRESULT Date_setMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double n, t;
......@@ -1415,15 +1384,14 @@ static HRESULT Date_setMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla
sec_from_time(t), n));
date->time = time_clip(utc(t, date));
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.29 */
static HRESULT Date_setUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double n, t;
......@@ -1446,15 +1414,14 @@ static HRESULT Date_setUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD
sec_from_time(t), n));
date->time = time_clip(t);
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.30 */
static HRESULT Date_setSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, sec, ms;
......@@ -1486,15 +1453,14 @@ static HRESULT Date_setSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
min_from_time(t), sec, ms));
date->time = time_clip(utc(t, date));
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.31 */
static HRESULT Date_setUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, sec, ms;
......@@ -1526,15 +1492,14 @@ static HRESULT Date_setUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
min_from_time(t), sec, ms));
date->time = time_clip(t);
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.33 */
static HRESULT Date_setMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, min, sec, ms;
......@@ -1574,15 +1539,14 @@ static HRESULT Date_setMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
min, sec, ms));
date->time = time_clip(utc(t, date));
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.34 */
static HRESULT Date_setUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, min, sec, ms;
......@@ -1622,15 +1586,14 @@ static HRESULT Date_setUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
min, sec, ms));
date->time = time_clip(t);
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.35 */
static HRESULT Date_setHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, hour, min, sec, ms;
......@@ -1677,15 +1640,14 @@ static HRESULT Date_setHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
t = make_date(day(t), make_time(hour, min, sec, ms));
date->time = time_clip(utc(t, date));
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.36 */
static HRESULT Date_setUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, hour, min, sec, ms;
......@@ -1732,15 +1694,14 @@ static HRESULT Date_setUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
t = make_date(day(t), make_time(hour, min, sec, ms));
date->time = time_clip(t);
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.36 */
static HRESULT Date_setDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, n;
......@@ -1762,15 +1723,14 @@ static HRESULT Date_setDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
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)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.37 */
static HRESULT Date_setUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, n;
......@@ -1792,15 +1752,14 @@ static HRESULT Date_setUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
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)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.38 */
static HRESULT Date_setMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
DOUBLE t, month, ddate;
......@@ -1832,15 +1791,14 @@ static HRESULT Date_setMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
time_within_day(t));
date->time = time_clip(utc(t, date));
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.39 */
static HRESULT Date_setUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, month, ddate;
......@@ -1872,15 +1830,14 @@ static HRESULT Date_setUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
time_within_day(t));
date->time = time_clip(t);
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.40 */
static HRESULT Date_setFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, year, month, ddate;
......@@ -1919,15 +1876,14 @@ static HRESULT Date_setFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
t = make_date(make_day(year, month, ddate), time_within_day(t));
date->time = time_clip(utc(t, date));
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition 15.9.5.41 */
static HRESULT Date_setUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
double t, year, month, ddate;
......@@ -1966,15 +1922,14 @@ static HRESULT Date_setUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
t = make_date(make_day(year, month, ddate), time_within_day(t));
date->time = time_clip(t);
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
/* ECMA-262 3rd Edition B2.4 */
static HRESULT Date_getYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
DOUBLE t, year;
......@@ -1986,21 +1941,20 @@ static HRESULT Date_getYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
t = local_time(date->time, date);
if(isnan(t)) {
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
year = year_from_time(t);
if(retv)
num_set_val(retv, (1900<=year && year<2000)?year-1900:year);
if(r)
*r = jsval_number((1900<=year && year<2000)?year-1900:year);
return S_OK;
}
/* ECMA-262 3rd Edition B2.5 */
static HRESULT Date_setYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DateInstance *date;
DOUBLE t, year;
......@@ -2022,8 +1976,8 @@ static HRESULT Date_setYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(isnan(year)) {
date->time = year;
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -2033,13 +1987,13 @@ static HRESULT Date_setYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
date->time = time_clip(utc(make_date(make_day(year, month_from_time(t), date_from_time(t)), time_within_day(t)), date));
if(retv)
num_set_val(retv, date->time);
if(r)
*r = jsval_number(date->time);
return S_OK;
}
static HRESULT Date_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -2412,7 +2366,7 @@ static inline HRESULT date_parse(BSTR input, double *ret) {
}
static HRESULT DateConstr_parse(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR parse_str;
double n;
......@@ -2421,8 +2375,8 @@ static HRESULT DateConstr_parse(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
TRACE("\n");
if(!argc) {
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -2435,7 +2389,7 @@ static HRESULT DateConstr_parse(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(FAILED(hres))
return hres;
num_set_val(retv, n);
*r = jsval_number(n);
return S_OK;
}
......@@ -2510,7 +2464,7 @@ static HRESULT date_utc(script_ctx_t *ctx, unsigned argc, VARIANT *argv, double
}
static HRESULT DateConstr_UTC(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double n;
HRESULT hres;
......@@ -2518,13 +2472,13 @@ static HRESULT DateConstr_UTC(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
TRACE("\n");
hres = date_utc(ctx, argc, argv, &n, ei);
if(SUCCEEDED(hres) && retv)
num_set_val(retv, n);
if(SUCCEEDED(hres) && r)
*r = jsval_number(n);
return hres;
}
static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *date;
HRESULT hres;
......@@ -2591,7 +2545,7 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
}
}
var_set_jsdisp(retv, date);
*r = jsval_obj(date);
return S_OK;
case INVOKE_FUNC: {
......@@ -2603,7 +2557,7 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
lltime = ((LONGLONG)local_time.dwHighDateTime<<32)
+ local_time.dwLowDateTime;
return date_to_string(lltime/10000-TIME_EPOCH, FALSE, 0, retv);
return date_to_string(lltime/10000-TIME_EPOCH, FALSE, 0, r);
}
default:
......
......@@ -348,7 +348,7 @@ static HRESULT convert_params(const DISPPARAMS *dp, VARIANT *buf, unsigned *argc
}
static HRESULT invoke_prop_func(jsdisp_t *This, IDispatch *jsthis, dispex_prop_t *prop, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei, IServiceProvider *caller)
{
HRESULT hres;
......@@ -366,17 +366,17 @@ static HRESULT invoke_prop_func(jsdisp_t *This, IDispatch *jsthis, dispex_prop_t
set_disp(&vthis, jsthis);
else
set_jsdisp(&vthis, This);
hres = prop->u.p->invoke(This->ctx, &vthis, flags, argc, argv, retv, ei);
hres = prop->u.p->invoke(This->ctx, &vthis, flags, argc, argv, r, ei);
vdisp_release(&vthis);
}else {
/* Function object calls are special case */
hres = Function_invoke(This, jsthis, flags, argc, argv, retv, ei);
hres = Function_invoke(This, jsthis, flags, argc, argv, r, ei);
}
return hres;
}
case PROP_PROTREF:
return invoke_prop_func(This->prototype, jsthis, This->prototype->props+prop->u.ref,
flags, argc, argv, retv, ei, caller);
flags, argc, argv, r, ei, caller);
case PROP_VARIANT: {
if(V_VT(&prop->u.var) != VT_DISPATCH) {
FIXME("invoke vt %d\n", V_VT(&prop->u.var));
......@@ -385,7 +385,7 @@ static HRESULT invoke_prop_func(jsdisp_t *This, IDispatch *jsthis, dispex_prop_t
TRACE("call %s %p\n", debugstr_w(prop->name), V_DISPATCH(&prop->u.var));
return disp_call_value(This->ctx, V_DISPATCH(&prop->u.var), jsthis, flags, argc, argv, retv, ei);
return disp_call_value(This->ctx, V_DISPATCH(&prop->u.var), jsthis, flags, argc, argv, r, ei);
}
default:
ERR("type %d\n", prop->type);
......@@ -413,10 +413,15 @@ static HRESULT prop_get(jsdisp_t *This, dispex_prop_t *prop, DISPPARAMS *dp,
hres = VariantCopy(retv, &prop->u.var);
}else {
vdisp_t vthis;
jsval_t r;
set_jsdisp(&vthis, This);
hres = prop->u.p->invoke(This->ctx, &vthis, DISPATCH_PROPERTYGET, 0, NULL, retv, ei);
hres = prop->u.p->invoke(This->ctx, &vthis, DISPATCH_PROPERTYGET, 0, NULL, &r, ei);
vdisp_release(&vthis);
if(SUCCEEDED(hres)) {
hres = jsval_to_variant(r, retv);
jsval_release(r);
}
}
break;
case PROP_PROTREF:
......@@ -679,15 +684,20 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc
case DISPATCH_CONSTRUCT: {
VARIANT *argv;
unsigned argc;
jsval_t r;
VARIANT buf[6];
hres = convert_params(pdp, buf, &argc, &argv);
if(FAILED(hres))
return hres;
hres = invoke_prop_func(This, get_this(pdp), prop, wFlags, argc, argv, pvarRes, &jsexcept, pspCaller);
hres = invoke_prop_func(This, get_this(pdp), prop, wFlags, argc, argv, pvarRes ? &r : NULL, &jsexcept, pspCaller);
if(argv != buf)
heap_free(argv);
if(SUCCEEDED(hres) && pvarRes) {
hres = jsval_to_variant(r, pvarRes);
jsval_release(r);
}
break;
}
case DISPATCH_PROPERTYGET:
......@@ -995,18 +1005,18 @@ HRESULT jsdisp_get_id(jsdisp_t *jsdisp, const WCHAR *name, DWORD flags, DISPID *
return DISP_E_UNKNOWNNAME;
}
HRESULT jsdisp_call_value(jsdisp_t *jsfunc, IDispatch *jsthis, WORD flags, unsigned argc, VARIANT *argv, VARIANT *retv,
HRESULT jsdisp_call_value(jsdisp_t *jsfunc, IDispatch *jsthis, WORD flags, unsigned argc, VARIANT *argv, jsval_t *r,
jsexcept_t *ei)
{
HRESULT hres;
if(is_class(jsfunc, JSCLASS_FUNCTION)) {
hres = Function_invoke(jsfunc, jsthis, flags, argc, argv, retv, ei);
hres = Function_invoke(jsfunc, jsthis, flags, argc, argv, r, ei);
}else {
vdisp_t vdisp;
set_disp(&vdisp, jsthis);
hres = jsfunc->builtin_info->value_prop.invoke(jsfunc->ctx, &vdisp, flags, argc, argv, retv, ei);
hres = jsfunc->builtin_info->value_prop.invoke(jsfunc->ctx, &vdisp, flags, argc, argv, r, ei);
vdisp_release(&vdisp);
}
return hres;
......@@ -1015,6 +1025,8 @@ HRESULT jsdisp_call_value(jsdisp_t *jsfunc, IDispatch *jsthis, WORD flags, unsig
HRESULT jsdisp_call(jsdisp_t *disp, DISPID id, WORD flags, unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
{
dispex_prop_t *prop;
jsval_t r;
HRESULT hres;
memset(ei, 0, sizeof(*ei));
if(retv)
......@@ -1024,10 +1036,18 @@ HRESULT jsdisp_call(jsdisp_t *disp, DISPID id, WORD flags, unsigned argc, VARIAN
if(!prop)
return DISP_E_MEMBERNOTFOUND;
return invoke_prop_func(disp, to_disp(disp), prop, flags, argc, argv, retv, ei, NULL);
hres = invoke_prop_func(disp, to_disp(disp), prop, flags, argc, argv, retv ? &r : NULL, ei, NULL);
if(FAILED(hres))
return hres;
if(retv) {
hres = jsval_to_variant(r, retv);
jsval_release(r);
}
return hres;
}
HRESULT jsdisp_call_name(jsdisp_t *disp, const WCHAR *name, WORD flags, unsigned argc, VARIANT *argv, VARIANT *retv,
HRESULT jsdisp_call_name(jsdisp_t *disp, const WCHAR *name, WORD flags, unsigned argc, VARIANT *argv, jsval_t *r,
jsexcept_t *ei)
{
dispex_prop_t *prop;
......@@ -1038,10 +1058,7 @@ HRESULT jsdisp_call_name(jsdisp_t *disp, const WCHAR *name, WORD flags, unsigned
return hres;
memset(ei, 0, sizeof(*ei));
if(retv)
V_VT(retv) = VT_EMPTY;
return invoke_prop_func(disp, to_disp(disp), prop, flags, argc, argv, retv, ei, NULL);
return invoke_prop_func(disp, to_disp(disp), prop, flags, argc, argv, r, ei, NULL);
}
HRESULT disp_call(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD flags, unsigned argc, VARIANT *argv,
......@@ -1123,11 +1140,11 @@ HRESULT disp_call(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD flags, uns
}
HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, IDispatch *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsdisp;
IDispatchEx *dispex;
VARIANT buf[6];
VARIANT buf[6], retv;
DISPPARAMS dp;
unsigned i;
HRESULT hres;
......@@ -1139,13 +1156,13 @@ HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, IDispatch *jsthis, W
return E_FAIL;
}
hres = jsdisp_call_value(jsdisp, jsthis, flags, argc, argv, retv, ei);
hres = jsdisp_call_value(jsdisp, jsthis, flags, argc, argv, r, ei);
jsdisp_release(jsdisp);
return hres;
}
memset(ei, 0, sizeof(*ei));
if(retv && argc)
if(r && argc)
flags |= DISPATCH_PROPERTYGET;
......@@ -1176,11 +1193,10 @@ HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, IDispatch *jsthis, W
V_DISPATCH(dp.rgvarg) = jsthis;
}
if(retv)
V_VT(retv) = VT_EMPTY;
V_VT(&retv) = VT_EMPTY;
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
if(SUCCEEDED(hres)) {
hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, ctx->lcid, flags, &dp, retv, &ei->ei,
hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, ctx->lcid, flags, &dp, r ? &retv : NULL, &ei->ei,
&ctx->jscaller->IServiceProvider_iface);
IDispatchEx_Release(dispex);
}else {
......@@ -1192,7 +1208,7 @@ HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, IDispatch *jsthis, W
}
TRACE("using IDispatch\n");
hres = IDispatch_Invoke(disp, DISPID_VALUE, &IID_NULL, ctx->lcid, flags, &dp, retv, &ei->ei, &err);
hres = IDispatch_Invoke(disp, DISPID_VALUE, &IID_NULL, ctx->lcid, flags, &dp, r ? &retv : NULL, &ei->ei, &err);
}
if(dp.rgvarg != buf)
......@@ -1200,9 +1216,12 @@ HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, IDispatch *jsthis, W
if(FAILED(hres))
return hres;
if(retv)
ensure_retval_type(retv);
return S_OK;
if(!r)
return S_OK;
hres = variant_to_jsval(&retv, r);
VariantClear(&retv);
return hres;
}
HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, VARIANT *val, jsexcept_t *ei)
......
......@@ -385,7 +385,7 @@ static HRESULT disp_get_id(script_ctx_t *ctx, IDispatch *disp, BSTR name, DWORD
return hres;
}
static inline BOOL is_null(const VARIANT *v)
static inline BOOL is_null_var(const VARIANT *v)
{
return V_VT(v) == VT_NULL || (V_VT(v) == VT_DISPATCH && !V_DISPATCH(v));
}
......@@ -442,8 +442,8 @@ static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
if(V_VT(lval) != V_VT(rval)) {
if(is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval)))
*ret = num_val(lval) == num_val(rval);
else if(is_null(lval))
*ret = is_null(rval);
else if(is_null_var(lval))
*ret = is_null_var(rval);
else
*ret = FALSE;
return S_OK;
......@@ -981,6 +981,7 @@ static HRESULT interp_new(exec_ctx_t *ctx)
{
const unsigned arg = get_op_uint(ctx, 0);
VARIANT *constr, v;
jsval_t r;
HRESULT hres;
TRACE("%d\n", arg);
......@@ -996,7 +997,12 @@ static HRESULT interp_new(exec_ctx_t *ctx)
else if(!V_DISPATCH(constr))
return throw_type_error(ctx->script, ctx->ei, JS_E_INVALID_PROPERTY, NULL);
hres = disp_call_value(ctx->script, V_DISPATCH(constr), NULL, DISPATCH_CONSTRUCT, arg, stack_args(ctx, arg), &v, ctx->ei);
hres = disp_call_value(ctx->script, V_DISPATCH(constr), NULL, DISPATCH_CONSTRUCT, arg, stack_args(ctx, arg), &r, ctx->ei);
if(FAILED(hres))
return hres;
hres = jsval_to_variant(r, &v);
jsval_release(r);
if(FAILED(hres))
return hres;
......@@ -1010,6 +1016,7 @@ static HRESULT interp_call(exec_ctx_t *ctx)
const unsigned argn = get_op_uint(ctx, 0);
const int do_ret = get_op_int(ctx, 1);
VARIANT v, *objv;
jsval_t r;
HRESULT hres;
TRACE("%d %d\n", argn, do_ret);
......@@ -1019,12 +1026,21 @@ static HRESULT interp_call(exec_ctx_t *ctx)
return throw_type_error(ctx->script, ctx->ei, JS_E_INVALID_PROPERTY, NULL);
hres = disp_call_value(ctx->script, V_DISPATCH(objv), NULL, DISPATCH_METHOD, argn, stack_args(ctx, argn),
do_ret ? &v : NULL, ctx->ei);
do_ret ? &r : NULL, ctx->ei);
if(FAILED(hres))
return hres;
stack_popn(ctx, argn+1);
return do_ret ? stack_push(ctx, &v) : S_OK;
if(!do_ret)
return S_OK;
hres = jsval_to_variant(r, &v);
jsval_release(r);
if(FAILED(hres))
return hres;
return stack_push(ctx, &v);
}
......
......@@ -35,7 +35,7 @@ static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
/* ECMA-262 3rd Edition 15.11.4.4 */
static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsthis;
BSTR name = NULL, msg = NULL, ret = NULL;
......@@ -48,11 +48,11 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
jsthis = get_jsdisp(vthis);
if(!jsthis || ctx->version < 2) {
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(object_errorW);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocString(object_errorW);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK;
}
......@@ -116,18 +116,15 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
if(!ret)
return E_OUTOFMEMORY;
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}else {
if(r)
*r = jsval_string(ret);
else
SysFreeString(ret);
}
return S_OK;
}
static HRESULT Error_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -227,7 +224,7 @@ static HRESULT create_error(script_ctx_t *ctx, jsdisp_t *constr,
}
static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei, jsdisp_t *constr) {
jsval_t *r, jsexcept_t *ei, jsdisp_t *constr) {
jsdisp_t *err;
UINT num = 0;
BSTR msg = NULL;
......@@ -261,11 +258,10 @@ static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, VARIAN
if(FAILED(hres))
return hres;
if(retv)
var_set_jsdisp(retv, err);
if(r)
*r = jsval_obj(err);
else
jsdisp_release(err);
return S_OK;
default:
......@@ -275,59 +271,59 @@ static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, VARIAN
}
static HRESULT ErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->error_constr);
return error_constr(ctx, flags, argc, argv, r, ei, ctx->error_constr);
}
static HRESULT EvalErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->eval_error_constr);
return error_constr(ctx, flags, argc, argv, r, ei, ctx->eval_error_constr);
}
static HRESULT RangeErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->range_error_constr);
return error_constr(ctx, flags, argc, argv, r, ei, ctx->range_error_constr);
}
static HRESULT ReferenceErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->reference_error_constr);
return error_constr(ctx, flags, argc, argv, r, ei, ctx->reference_error_constr);
}
static HRESULT RegExpErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->regexp_error_constr);
return error_constr(ctx, flags, argc, argv, r, ei, ctx->regexp_error_constr);
}
static HRESULT SyntaxErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->syntax_error_constr);
return error_constr(ctx, flags, argc, argv, r, ei, ctx->syntax_error_constr);
}
static HRESULT TypeErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->type_error_constr);
return error_constr(ctx, flags, argc, argv, r, ei, ctx->type_error_constr);
}
static HRESULT URIErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->uri_error_constr);
return error_constr(ctx, flags, argc, argv, r, ei, ctx->uri_error_constr);
}
HRESULT init_error_constr(script_ctx_t *ctx, jsdisp_t *object_prototype)
......
......@@ -75,7 +75,7 @@ static HRESULT init_parameters(jsdisp_t *var_disp, FunctionInstance *function, u
}
static HRESULT Arguments_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
......@@ -160,7 +160,7 @@ static HRESULT create_var_disp(script_ctx_t *ctx, FunctionInstance *function, js
}
static HRESULT invoke_source(script_ctx_t *ctx, FunctionInstance *function, IDispatch *this_obj, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *var_disp, *arg_disp;
exec_ctx_t *exec_ctx;
......@@ -190,24 +190,28 @@ static HRESULT invoke_source(script_ctx_t *ctx, FunctionInstance *function, IDis
jsdisp_release(var_disp);
if(SUCCEEDED(hres)) {
jsdisp_t *prev_args;
VARIANT retv;
prev_args = function->arguments;
function->arguments = arg_disp;
hres = exec_source(exec_ctx, function->code, function->func_code, FALSE, ei, retv);
hres = exec_source(exec_ctx, function->code, function->func_code, FALSE, ei, r ? &retv : NULL);
function->arguments = prev_args;
jsdisp_release(arg_disp);
exec_release(exec_ctx);
if(SUCCEEDED(hres) && r) {
hres = variant_to_jsval(&retv, r);
VariantClear(&retv);
}
}
jsdisp_release(arg_disp);
exec_release(exec_ctx);
return hres;
}
static HRESULT invoke_constructor(script_ctx_t *ctx, FunctionInstance *function, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *this_obj;
VARIANT var;
jsval_t var;
HRESULT hres;
hres = create_object(ctx, &function->dispex, &this_obj);
......@@ -220,19 +224,18 @@ static HRESULT invoke_constructor(script_ctx_t *ctx, FunctionInstance *function,
return hres;
}
if(V_VT(&var) == VT_DISPATCH) {
if(is_object_instance(var)) {
jsdisp_release(this_obj);
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = V_DISPATCH(&var);
*r = var;
}else {
VariantClear(&var);
var_set_jsdisp(retv, this_obj);
jsval_release(var);
*r = jsval_obj(this_obj);
}
return S_OK;
}
static HRESULT invoke_value_proc(script_ctx_t *ctx, FunctionInstance *function, IDispatch *this_disp, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
vdisp_t vthis;
HRESULT hres;
......@@ -244,19 +247,19 @@ static HRESULT invoke_value_proc(script_ctx_t *ctx, FunctionInstance *function,
else
set_jsdisp(&vthis, ctx->global);
hres = function->value_proc(ctx, &vthis, flags, argc, argv, retv, ei);
hres = function->value_proc(ctx, &vthis, flags, argc, argv, r, ei);
vdisp_release(&vthis);
return hres;
}
static HRESULT call_function(script_ctx_t *ctx, FunctionInstance *function, IDispatch *this_obj,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
if(function->value_proc)
return invoke_value_proc(ctx, function, this_obj, DISPATCH_METHOD, argc, argv, retv, ei);
return invoke_value_proc(ctx, function, this_obj, DISPATCH_METHOD, argc, argv, r, ei);
return invoke_source(ctx, function, this_obj, argc, argv, retv, ei);
return invoke_source(ctx, function, this_obj, argc, argv, r, ei);
}
static HRESULT function_to_string(FunctionInstance *function, BSTR *ret)
......@@ -288,7 +291,7 @@ static HRESULT function_to_string(FunctionInstance *function, BSTR *ret)
return S_OK;
}
HRESULT Function_invoke(jsdisp_t *func_this, IDispatch *jsthis, WORD flags, unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
HRESULT Function_invoke(jsdisp_t *func_this, IDispatch *jsthis, WORD flags, unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
FunctionInstance *function;
......@@ -298,17 +301,17 @@ HRESULT Function_invoke(jsdisp_t *func_this, IDispatch *jsthis, WORD flags, unsi
function = (FunctionInstance*)func_this;
if(function->value_proc)
return invoke_value_proc(function->dispex.ctx, function, jsthis, flags, argc, argv, retv, ei);
return invoke_value_proc(function->dispex.ctx, function, jsthis, flags, argc, argv, r, ei);
if(flags == DISPATCH_CONSTRUCT)
return invoke_constructor(function->dispex.ctx, function, argc, argv, retv, ei);
return invoke_constructor(function->dispex.ctx, function, argc, argv, r, ei);
assert(flags == DISPATCH_METHOD);
return invoke_source(function->dispex.ctx, function, jsthis, argc, argv, retv, ei);
return invoke_source(function->dispex.ctx, function, jsthis, argc, argv, r, ei);
}
static HRESULT Function_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FunctionInstance *This = function_from_vdisp(jsthis);
......@@ -316,7 +319,7 @@ static HRESULT Function_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
switch(flags) {
case DISPATCH_PROPERTYGET:
num_set_int(retv, This->length);
*r = jsval_number(This->length);
break;
default:
FIXME("unimplemented flags %x\n", flags);
......@@ -327,7 +330,7 @@ static HRESULT Function_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
}
static HRESULT Function_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FunctionInstance *function;
BSTR str;
......@@ -342,12 +345,10 @@ static HRESULT Function_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(FAILED(hres))
return hres;
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = str;
}else {
if(r)
*r = jsval_string(str);
else
SysFreeString(str);
}
return S_OK;
}
......@@ -388,7 +389,7 @@ static HRESULT array_to_args(script_ctx_t *ctx, jsdisp_t *arg_array, jsexcept_t
}
static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FunctionInstance *function;
VARIANT *args = NULL;
......@@ -431,7 +432,7 @@ static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
}
if(SUCCEEDED(hres))
hres = call_function(ctx, function, this_obj, cnt, args, retv, ei);
hres = call_function(ctx, function, this_obj, cnt, args, r, ei);
if(this_obj)
IDispatch_Release(this_obj);
......@@ -442,7 +443,7 @@ static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
}
static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FunctionInstance *function;
IDispatch *this_obj = NULL;
......@@ -464,7 +465,7 @@ static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
cnt = argc-1;
}
hres = call_function(ctx, function, this_obj, cnt, argv+1, retv, ei);
hres = call_function(ctx, function, this_obj, cnt, argv+1, r, ei);
if(this_obj)
IDispatch_Release(this_obj);
......@@ -472,7 +473,7 @@ static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
}
HRESULT Function_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FunctionInstance *function;
......@@ -488,7 +489,7 @@ HRESULT Function_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
switch(flags) {
case DISPATCH_METHOD:
assert(function->value_proc != NULL);
return invoke_value_proc(ctx, function, NULL, flags, argc, argv, retv, ei);
return invoke_value_proc(ctx, function, NULL, flags, argc, argv, r, ei);
case DISPATCH_PROPERTYGET: {
HRESULT hres;
......@@ -498,14 +499,13 @@ HRESULT Function_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
if(FAILED(hres))
return hres;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = str;
*r = jsval_string(str);
break;
}
case DISPATCH_CONSTRUCT:
assert(function->value_proc != NULL);
return invoke_value_proc(ctx, function, NULL, flags, argc, argv, retv, ei);
return invoke_value_proc(ctx, function, NULL, flags, argc, argv, r, ei);
default:
FIXME("not implemented flags %x\n", flags);
......@@ -516,7 +516,7 @@ HRESULT Function_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
}
static HRESULT Function_arguments(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
FunctionInstance *function = (FunctionInstance*)jsthis->u.jsdisp;
HRESULT hres = S_OK;
......@@ -525,12 +525,7 @@ static HRESULT Function_arguments(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
switch(flags) {
case DISPATCH_PROPERTYGET: {
if(function->arguments) {
jsdisp_addref(function->arguments);
var_set_jsdisp(retv, function->arguments);
}else {
V_VT(retv) = VT_NULL;
}
*r = function->arguments ? jsval_obj(jsdisp_addref(function->arguments)) : jsval_null();
break;
}
case DISPATCH_PROPERTYPUT:
......@@ -809,7 +804,7 @@ static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, VARIANT *arg
}
static HRESULT FunctionConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
HRESULT hres;
......@@ -823,8 +818,7 @@ static HRESULT FunctionConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla
if(FAILED(hres))
return hres;
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = ret;
*r = jsval_disp(ret);
break;
}
default:
......@@ -836,7 +830,7 @@ static HRESULT FunctionConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla
}
static HRESULT FunctionProt_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
......
......@@ -115,169 +115,168 @@ static WCHAR int_to_char(int i)
}
static HRESULT constructor_call(jsdisp_t *constr, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
if(flags != DISPATCH_PROPERTYGET)
return jsdisp_call_value(constr, NULL, flags, argc, argv, retv, ei);
return jsdisp_call_value(constr, NULL, flags, argc, argv, r, ei);
jsdisp_addref(constr);
var_set_jsdisp(retv, constr);
*r = jsval_obj(jsdisp_addref(constr));
return S_OK;
}
static HRESULT JSGlobal_Array(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->array_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->array_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_Boolean(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->bool_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->bool_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_Date(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->date_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->date_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_Error(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->error_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->error_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_EvalError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->eval_error_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->eval_error_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_RangeError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->range_error_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->range_error_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_RegExpError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->regexp_error_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->regexp_error_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_ReferenceError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->reference_error_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->reference_error_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_SyntaxError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->syntax_error_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->syntax_error_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_TypeError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->type_error_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->type_error_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_URIError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->uri_error_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->uri_error_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_Function(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->function_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->function_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_Number(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->number_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->number_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_Object(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->object_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->object_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_String(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->string_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->string_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_RegExp(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->regexp_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->regexp_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_ActiveXObject(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->activex_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->activex_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_VBArray(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return constructor_call(ctx->vbarray_constr, flags, argc, argv, retv, ei);
return constructor_call(ctx->vbarray_constr, flags, argc, argv, r, ei);
}
static HRESULT JSGlobal_Enumerator(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR ret, str;
const WCHAR *ptr;
......@@ -287,13 +286,12 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
TRACE("\n");
if(!argc) {
if(retv) {
if(r) {
ret = SysAllocString(undefinedW);
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}
return S_OK;
......@@ -339,36 +337,32 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
SysFreeString(str);
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}
if(r)
*r = jsval_string(ret);
else
SysFreeString(ret);
return S_OK;
}
/* ECMA-262 3rd Edition 15.1.2.1 */
static HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
bytecode_t *code;
VARIANT retv;
HRESULT hres;
TRACE("\n");
if(!argc) {
if(retv)
V_VT(retv) = VT_EMPTY;
if(r)
*r = jsval_undefined();
return S_OK;
}
if(V_VT(argv) != VT_BSTR) {
if(retv) {
V_VT(retv) = VT_EMPTY;
return VariantCopy(retv, argv);
}
if(r)
return variant_to_jsval(argv, r);
return S_OK;
}
......@@ -384,16 +378,22 @@ static HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
return throw_syntax_error(ctx, ei, hres, NULL);
}
hres = exec_source(ctx->exec_ctx, code, &code->global_code, TRUE, ei, retv);
hres = exec_source(ctx->exec_ctx, code, &code->global_code, TRUE, ei, r ? &retv : NULL);
release_bytecode(code);
if(FAILED(hres))
return hres;
if(r) {
hres = variant_to_jsval(&retv, r);
VariantClear(&retv);
}
return hres;
}
static HRESULT JSGlobal_isNaN(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
VARIANT_BOOL ret = VARIANT_TRUE;
BOOL ret = TRUE;
double n;
HRESULT hres;
......@@ -405,20 +405,18 @@ static HRESULT JSGlobal_isNaN(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
return hres;
if(!isnan(n))
ret = VARIANT_FALSE;
ret = FALSE;
}
if(retv) {
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = ret;
}
if(r)
*r = jsval_bool(ret);
return S_OK;
}
static HRESULT JSGlobal_isFinite(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
VARIANT_BOOL ret = VARIANT_FALSE;
BOOL ret = FALSE;
HRESULT hres;
TRACE("\n");
......@@ -431,13 +429,11 @@ static HRESULT JSGlobal_isFinite(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
return hres;
if(!isinf(n) && !isnan(n))
ret = VARIANT_TRUE;
ret = TRUE;
}
if(retv) {
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = ret;
}
if(r)
*r = jsval_bool(ret);
return S_OK;
}
......@@ -453,7 +449,7 @@ static INT char_to_int(WCHAR c)
}
static HRESULT JSGlobal_parseInt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BOOL neg = FALSE, empty = TRUE;
DOUBLE ret = 0.0;
......@@ -463,7 +459,8 @@ static HRESULT JSGlobal_parseInt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
HRESULT hres;
if(!argc) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -474,8 +471,8 @@ static HRESULT JSGlobal_parseInt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(radix && (radix < 2 || radix > 36)) {
WARN("radix %d out of range\n", radix);
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
}
......@@ -526,13 +523,13 @@ static HRESULT JSGlobal_parseInt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(neg)
ret = -ret;
if(retv)
num_set_val(retv, ret);
if(r)
*r = jsval_number(ret);
return S_OK;
}
static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
LONGLONG d = 0, hlp;
int exp = 0;
......@@ -542,8 +539,8 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
HRESULT hres;
if(!argc) {
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -620,15 +617,15 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
SysFreeString(val_str);
if(ret_nan) {
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
V_VT(retv) = VT_R8;
if(!positive)
d = -d;
V_R8(retv) = (exp>0 ? d*pow(10, exp) : d/pow(10, -exp));
if(r)
*r = jsval_number(exp>0 ? d*pow(10, exp) : d/pow(10, -exp));
return S_OK;
}
......@@ -639,7 +636,7 @@ static inline int hex_to_int(const WCHAR wch) {
}
static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR ret, str;
const WCHAR *ptr;
......@@ -649,13 +646,11 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
TRACE("\n");
if(!argc) {
if(retv) {
if(r) {
ret = SysAllocString(undefinedW);
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}
return S_OK;
......@@ -707,83 +702,79 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
SysFreeString(str);
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}
if(r)
*r = jsval_string(ret);
else
SysFreeString(ret);
return S_OK;
}
static HRESULT JSGlobal_GetObject(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT JSGlobal_ScriptEngine(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR JScriptW[] = {'J','S','c','r','i','p','t',0};
TRACE("\n");
if(retv) {
if(r) {
BSTR ret;
ret = SysAllocString(JScriptW);
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}
return S_OK;
}
static HRESULT JSGlobal_ScriptEngineMajorVersion(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
if(retv)
num_set_int(retv, JSCRIPT_MAJOR_VERSION);
if(r)
*r = jsval_number(JSCRIPT_MAJOR_VERSION);
return S_OK;
}
static HRESULT JSGlobal_ScriptEngineMinorVersion(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
if(retv)
num_set_int(retv, JSCRIPT_MINOR_VERSION);
if(r)
*r = jsval_number(JSCRIPT_MINOR_VERSION);
return S_OK;
}
static HRESULT JSGlobal_ScriptEngineBuildVersion(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
if(retv)
num_set_int(retv, JSCRIPT_BUILD_VERSION);
if(r)
*r = jsval_number(JSCRIPT_BUILD_VERSION);
return S_OK;
}
static HRESULT JSGlobal_CollectGarbage(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
const WCHAR *ptr;
DWORD len = 0, i;
......@@ -795,13 +786,12 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
TRACE("\n");
if(!argc) {
if(retv) {
if(r) {
ret = SysAllocString(undefinedW);
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}
return S_OK;
......@@ -847,17 +837,15 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
TRACE("%s -> %s\n", debugstr_w(str), debugstr_w(ret));
SysFreeString(str);
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}else {
if(r)
*r = jsval_string(ret);
else
SysFreeString(ret);
}
return S_OK;
}
static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR str, ret;
WCHAR *ptr;
......@@ -869,13 +857,12 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
TRACE("\n");
if(!argc) {
if(retv) {
if(r) {
ret = SysAllocString(undefinedW);
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}
return S_OK;
......@@ -942,18 +929,15 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
TRACE("%s -> %s\n", debugstr_w(str), debugstr_w(ret));
SysFreeString(str);
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}else {
if(r)
*r = jsval_string(ret);
else
SysFreeString(ret);
}
return S_OK;
}
static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR str, ret;
char buf[4];
......@@ -964,13 +948,12 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
TRACE("\n");
if(!argc) {
if(retv) {
if(r) {
ret = SysAllocString(undefinedW);
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}
return S_OK;
......@@ -1015,19 +998,16 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
SysFreeString(str);
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
} else {
if(r)
*r = jsval_string(ret);
else
SysFreeString(ret);
}
return S_OK;
}
/* ECMA-262 3rd Edition 15.1.3.2 */
static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR str, ret;
const WCHAR *ptr;
......@@ -1038,13 +1018,12 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
TRACE("\n");
if(!argc) {
if(retv) {
if(r) {
ret = SysAllocString(undefinedW);
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}
return S_OK;
......@@ -1138,13 +1117,10 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
SysFreeString(str);
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}else {
if(r)
*r = jsval_string(ret);
else
SysFreeString(ret);
}
return S_OK;
}
......
......@@ -33,6 +33,7 @@
#include "wine/unicode.h"
#include "wine/list.h"
typedef struct _jsval_t jsval_t;
typedef struct _script_ctx_t script_ctx_t;
typedef struct _exec_ctx_t exec_ctx_t;
typedef struct _dispex_prop_t dispex_prop_t;
......@@ -152,7 +153,7 @@ static inline jsdisp_t *get_jsdisp(vdisp_t *vdisp)
return is_jsdisp(vdisp) ? vdisp->u.jsdisp : NULL;
}
typedef HRESULT (*builtin_invoke_t)(script_ctx_t*,vdisp_t*,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*);
typedef HRESULT (*builtin_invoke_t)(script_ctx_t*,vdisp_t*,WORD,unsigned,VARIANT*,jsval_t*,jsexcept_t*);
typedef struct {
const WCHAR *name;
......@@ -192,9 +193,10 @@ static inline IDispatch *to_disp(jsdisp_t *jsdisp)
jsdisp_t *as_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
jsdisp_t *to_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
static inline void jsdisp_addref(jsdisp_t *jsdisp)
static inline jsdisp_t *jsdisp_addref(jsdisp_t *jsdisp)
{
IDispatchEx_AddRef(&jsdisp->IDispatchEx_iface);
return jsdisp;
}
static inline void jsdisp_release(jsdisp_t *jsdisp)
......@@ -207,10 +209,10 @@ HRESULT init_dispex(jsdisp_t*,script_ctx_t*,const builtin_info_t*,jsdisp_t*) DEC
HRESULT init_dispex_from_constr(jsdisp_t*,script_ctx_t*,const builtin_info_t*,jsdisp_t*) DECLSPEC_HIDDEN;
HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT disp_call_value(script_ctx_t*,IDispatch*,IDispatch*,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_call_value(jsdisp_t*,IDispatch*,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT disp_call_value(script_ctx_t*,IDispatch*,IDispatch*,WORD,unsigned,VARIANT*,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_call_value(jsdisp_t*,IDispatch*,WORD,unsigned,VARIANT*,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_call(jsdisp_t*,DISPID,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_call_name(jsdisp_t*,const WCHAR*,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_call_name(jsdisp_t*,const WCHAR*,WORD,unsigned,VARIANT*,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT disp_propget(script_ctx_t*,IDispatch*,DISPID,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_propget(jsdisp_t*,DISPID,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
......@@ -228,8 +230,8 @@ HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,cons
jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_builtin_constructor(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD,
jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT Function_invoke(jsdisp_t*,IDispatch*,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*);
HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,unsigned,VARIANT*,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT Function_invoke(jsdisp_t*,IDispatch*,WORD,unsigned,VARIANT*,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT throw_eval_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
HRESULT throw_generic_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
......@@ -259,10 +261,12 @@ 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_number_jsval(script_ctx_t*,jsval_t,jsexcept_t*,double*) 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;
HRESULT to_string_jsval(script_ctx_t*,jsval_t,jsexcept_t*,BSTR*) DECLSPEC_HIDDEN;
HRESULT to_object(script_ctx_t*,VARIANT*,IDispatch**) DECLSPEC_HIDDEN;
HRESULT variant_change_type(script_ctx_t*,VARIANT*,VARIANT*,VARTYPE) DECLSPEC_HIDDEN;
......@@ -377,7 +381,7 @@ HRESULT regexp_match_next(script_ctx_t*,jsdisp_t*,DWORD,const WCHAR*,DWORD,const
DWORD*,DWORD*,match_result_t*) DECLSPEC_HIDDEN;
HRESULT regexp_match(script_ctx_t*,jsdisp_t*,const WCHAR*,DWORD,BOOL,match_result_t**,DWORD*) DECLSPEC_HIDDEN;
HRESULT parse_regexp_flags(const WCHAR*,DWORD,DWORD*) DECLSPEC_HIDDEN;
HRESULT regexp_string_match(script_ctx_t*,jsdisp_t*,BSTR,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT regexp_string_match(script_ctx_t*,jsdisp_t*,BSTR,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN;
static inline BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
{
......@@ -536,3 +540,5 @@ static inline LPWSTR heap_strdupW(LPCWSTR str)
return ret;
}
#include "jsval.h"
......@@ -185,6 +185,118 @@ jsheap_t *jsheap_mark(jsheap_t *heap)
return heap;
}
static BSTR clone_bstr(BSTR str)
{
return SysAllocStringLen(str, str ? SysStringLen(str) : 0);
}
void jsval_release(jsval_t val)
{
switch(val.type) {
case JSV_OBJECT:
IDispatch_Release(val.u.obj);
break;
case JSV_STRING:
SysFreeString(val.u.str);
break;
case JSV_VARIANT:
VariantClear(val.u.v);
heap_free(val.u.v);
break;
default:
break;
}
}
HRESULT jsval_variant(jsval_t *val, VARIANT *var)
{
HRESULT hres;
val->type = JSV_VARIANT;
val->u.v = heap_alloc(sizeof(VARIANT));
if(!val->u.v)
return E_OUTOFMEMORY;
V_VT(val->u.v) = VT_EMPTY;
hres = VariantCopy(val->u.v, var);
if(FAILED(hres))
heap_free(val->u.v);
return hres;
}
HRESULT variant_to_jsval(VARIANT *var, jsval_t *r)
{
switch(V_VT(var)) {
case VT_EMPTY:
*r = jsval_undefined();
return S_OK;
case VT_NULL:
*r = jsval_null();
return S_OK;
case VT_BOOL:
*r = jsval_bool(V_BOOL(var));
return S_OK;
case VT_I4:
*r = jsval_number(V_I4(var));
return S_OK;
case VT_R8:
*r = jsval_number(V_R8(var));
return S_OK;
case VT_BSTR: {
BSTR str = clone_bstr(V_BSTR(var));
if(!str)
return E_OUTOFMEMORY;
*r = jsval_string(str);
return S_OK;
}
case VT_DISPATCH: {
IDispatch_AddRef(V_DISPATCH(var));
*r = jsval_disp(V_DISPATCH(var));
return S_OK;
}
case VT_I2:
case VT_INT:
assert(0);
default:
return jsval_variant(r, var);
}
}
HRESULT jsval_to_variant(jsval_t val, VARIANT *retv)
{
switch(val.type) {
case JSV_UNDEFINED:
V_VT(retv) = VT_EMPTY;
return S_OK;
case JSV_NULL:
V_VT(retv) = VT_NULL;
return S_OK;
case JSV_OBJECT:
V_VT(retv) = VT_DISPATCH;
IDispatch_AddRef(val.u.obj);
V_DISPATCH(retv) = val.u.obj;
return S_OK;
case JSV_STRING:
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = clone_bstr(val.u.str);
if(!V_BSTR(retv))
return E_OUTOFMEMORY;
return S_OK;
case JSV_NUMBER:
num_set_val(retv, val.u.n);
return S_OK;
case JSV_BOOL:
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = val.u.b ? VARIANT_TRUE : VARIANT_FALSE;
return S_OK;
case JSV_VARIANT:
return VariantCopy(retv, val.u.v);
}
assert(0);
return E_FAIL;
}
/* ECMA-262 3rd Edition 9.1 */
HRESULT to_primitive(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret, hint_t hint)
{
......@@ -457,6 +569,26 @@ HRESULT to_number(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, double *ret)
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;
}
/* ECMA-262 3rd Edition 9.4 */
HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, double *ret)
{
......@@ -619,6 +751,26 @@ HRESULT to_string(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, BSTR *str)
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)
{
......
/*
* Copyright 2012 Jacek Caban for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef JSVAL_H
#define JSVAL_H
typedef enum {
JSV_UNDEFINED,
JSV_NULL,
JSV_OBJECT,
JSV_STRING,
JSV_NUMBER,
JSV_BOOL,
JSV_VARIANT
} jsval_type_t;
struct _jsval_t {
jsval_type_t type;
union {
IDispatch *obj;
BSTR str;
double n;
BOOL b;
VARIANT *v;
} u;
};
static inline jsval_t jsval_bool(BOOL b)
{
jsval_t ret;
ret.type = JSV_BOOL;
ret.u.b = b;
return ret;
}
static inline jsval_t jsval_string(BSTR str)
{
jsval_t ret;
ret.type = JSV_STRING;
ret.u.str = str;
return ret;
}
static inline jsval_t jsval_disp(IDispatch *obj)
{
jsval_t ret;
ret.type = JSV_OBJECT;
ret.u.obj = obj;
return ret;
}
static inline jsval_t jsval_obj(jsdisp_t *obj)
{
return jsval_disp(to_disp(obj));
}
static inline jsval_t jsval_null(void)
{
jsval_t ret = { JSV_NULL };
return ret;
}
static inline jsval_t jsval_undefined(void)
{
jsval_t ret = { JSV_UNDEFINED };
return ret;
}
static inline jsval_t jsval_number(double n)
{
jsval_t ret;
ret.type = JSV_NUMBER;
ret.u.n = n;
return ret;
}
static inline BOOL is_object_instance(jsval_t v)
{
return v.type == JSV_OBJECT;
}
static inline BOOL is_undefined(jsval_t v)
{
return v.type == JSV_UNDEFINED;
}
static inline BOOL is_null(jsval_t v)
{
return v.type == JSV_NULL;
}
static inline BOOL is_null_instance(jsval_t v)
{
return v.type == JSV_NULL || (v.type == JSV_OBJECT && !v.u.obj);
}
static inline BOOL is_string(jsval_t v)
{
return v.type == JSV_STRING;
}
static inline BOOL is_number(jsval_t v)
{
return v.type == JSV_NUMBER;
}
static inline BOOL is_variant(jsval_t v)
{
return v.type == JSV_VARIANT;
}
static inline BOOL is_bool(jsval_t v)
{
return v.type == JSV_BOOL;
}
static inline IDispatch *get_object(jsval_t v)
{
return v.u.obj;
}
static inline double get_number(jsval_t v)
{
return v.u.n;
}
static inline BSTR get_string(jsval_t v)
{
return v.u.str;
}
static inline VARIANT *get_variant(jsval_t v)
{
return v.u.v;
}
static inline BOOL get_bool(jsval_t v)
{
return v.u.b;
}
HRESULT variant_to_jsval(VARIANT*,jsval_t*) DECLSPEC_HIDDEN;
HRESULT jsval_to_variant(jsval_t,VARIANT*) DECLSPEC_HIDDEN;
void jsval_release(jsval_t) DECLSPEC_HIDDEN;
HRESULT jsval_variant(jsval_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT jsval_copy(jsval_t,jsval_t*) DECLSPEC_HIDDEN;
#endif
......@@ -59,7 +59,7 @@ static const WCHAR tanW[] = {'t','a','n',0};
/* ECMA-262 3rd Edition 15.8.2.12 */
static HRESULT Math_abs(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double d;
HRESULT hres;
......@@ -67,8 +67,8 @@ static HRESULT Math_abs(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
TRACE("\n");
if(!argc) {
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -76,13 +76,13 @@ static HRESULT Math_abs(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
if(FAILED(hres))
return hres;
if(retv)
num_set_val(retv, d < 0.0 ? -d : d);
if(r)
*r = jsval_number(d < 0.0 ? -d : d);
return S_OK;
}
static HRESULT Math_acos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -90,7 +90,8 @@ static HRESULT Math_acos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
TRACE("\n");
if(!argc) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -98,13 +99,13 @@ static HRESULT Math_acos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
if(retv)
num_set_val(retv, x < -1.0 || x > 1.0 ? NAN : acos(x));
if(r)
*r = jsval_number(x < -1.0 || x > 1.0 ? NAN : acos(x));
return S_OK;
}
static HRESULT Math_asin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -112,7 +113,8 @@ static HRESULT Math_asin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
TRACE("\n");
if(!argc) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -120,13 +122,13 @@ static HRESULT Math_asin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
if(retv)
num_set_val(retv, x < -1.0 || x > 1.0 ? NAN : asin(x));
if(r)
*r = jsval_number(x < -1.0 || x > 1.0 ? NAN : asin(x));
return S_OK;
}
static HRESULT Math_atan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -134,7 +136,8 @@ static HRESULT Math_atan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
TRACE("\n");
if(!argc) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -142,12 +145,13 @@ static HRESULT Math_atan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
if(retv) num_set_val(retv, atan(x));
if(r)
*r = jsval_number(atan(x));
return S_OK;
}
static HRESULT Math_atan2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x, y;
HRESULT hres;
......@@ -155,7 +159,8 @@ static HRESULT Math_atan2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
TRACE("\n");
if(argc<2) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -167,13 +172,14 @@ static HRESULT Math_atan2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
if(FAILED(hres))
return hres;
if(retv) num_set_val(retv, atan2(y, x));
if(r)
*r = jsval_number(atan2(y, x));
return S_OK;
}
/* ECMA-262 3rd Edition 15.8.2.6 */
static HRESULT Math_ceil(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -181,8 +187,8 @@ static HRESULT Math_ceil(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
TRACE("\n");
if(!argc) {
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -190,13 +196,13 @@ static HRESULT Math_ceil(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
if(retv)
num_set_val(retv, ceil(x));
if(r)
*r = jsval_number(ceil(x));
return S_OK;
}
static HRESULT Math_cos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -204,7 +210,8 @@ static HRESULT Math_cos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
TRACE("\n");
if(!argc) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -212,12 +219,13 @@ static HRESULT Math_cos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
if(FAILED(hres))
return hres;
if(retv) num_set_val(retv, cos(x));
if(r)
*r = jsval_number(cos(x));
return S_OK;
}
static HRESULT Math_exp(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -225,7 +233,8 @@ static HRESULT Math_exp(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
TRACE("\n");
if(!argc) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -233,12 +242,13 @@ static HRESULT Math_exp(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
if(FAILED(hres))
return hres;
if(retv) num_set_val(retv, exp(x));
if(r)
*r = jsval_number(exp(x));
return S_OK;
}
static HRESULT Math_floor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -246,8 +256,8 @@ static HRESULT Math_floor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
TRACE("\n");
if(!argc) {
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -255,13 +265,13 @@ static HRESULT Math_floor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
if(FAILED(hres))
return hres;
if(retv)
num_set_val(retv, floor(x));
if(r)
*r = jsval_number(floor(x));
return S_OK;
}
static HRESULT Math_log(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -269,8 +279,8 @@ static HRESULT Math_log(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
TRACE("\n");
if(!argc) {
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -278,14 +288,14 @@ static HRESULT Math_log(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
if(FAILED(hres))
return hres;
if(retv)
num_set_val(retv, x < -0.0 ? NAN : log(x));
if(r)
*r = jsval_number(x < -0.0 ? NAN : log(x));
return S_OK;
}
/* ECMA-262 3rd Edition 15.8.2.11 */
static HRESULT Math_max(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DOUBLE max, d;
DWORD i;
......@@ -294,8 +304,8 @@ static HRESULT Math_max(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
TRACE("\n");
if(!argc) {
if(retv)
num_set_val(retv, -INFINITY);
if(r)
*r = jsval_number(-INFINITY);
return S_OK;
}
......@@ -312,14 +322,14 @@ static HRESULT Math_max(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
max = d;
}
if(retv)
num_set_val(retv, max);
if(r)
*r = jsval_number(max);
return S_OK;
}
/* ECMA-262 3rd Edition 15.8.2.12 */
static HRESULT Math_min(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DOUBLE min, d;
DWORD i;
......@@ -328,8 +338,8 @@ static HRESULT Math_min(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
TRACE("\n");
if(!argc) {
if(retv)
num_set_val(retv, INFINITY);
if(r)
*r = jsval_number(INFINITY);
return S_OK;
}
......@@ -346,14 +356,14 @@ static HRESULT Math_min(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
min = d;
}
if(retv)
num_set_val(retv, min);
if(r)
*r = jsval_number(min);
return S_OK;
}
/* ECMA-262 3rd Edition 15.8.2.13 */
static HRESULT Math_pow(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x, y;
HRESULT hres;
......@@ -361,7 +371,8 @@ static HRESULT Math_pow(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
TRACE("\n");
if(argc < 2) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -373,31 +384,30 @@ static HRESULT Math_pow(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
if(FAILED(hres))
return hres;
if(retv)
num_set_val(retv, pow(x, y));
if(r)
*r = jsval_number(pow(x, y));
return S_OK;
}
/* ECMA-262 3rd Edition 15.8.2.14 */
static HRESULT Math_random(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
UINT r;
UINT x;
TRACE("\n");
if(!RtlGenRandom(&r, sizeof(r)))
if(!RtlGenRandom(&x, sizeof(x)))
return E_UNEXPECTED;
if(retv)
num_set_val(retv, (DOUBLE)r/(DOUBLE)UINT_MAX);
if(r)
*r = jsval_number((double)x/(double)UINT_MAX);
return S_OK;
}
/* ECMA-262 3rd Edition 15.8.2.15 */
static HRESULT Math_round(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -405,8 +415,8 @@ static HRESULT Math_round(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
TRACE("\n");
if(!argc) {
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -414,13 +424,13 @@ static HRESULT Math_round(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
if(FAILED(hres))
return hres;
if(retv)
num_set_val(retv, floor(x+0.5));
if(r)
*r = jsval_number(floor(x+0.5));
return S_OK;
}
static HRESULT Math_sin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -428,7 +438,8 @@ static HRESULT Math_sin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
TRACE("\n");
if(!argc) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -436,12 +447,13 @@ static HRESULT Math_sin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
if(FAILED(hres))
return hres;
if(retv) num_set_val(retv, sin(x));
if(r)
*r = jsval_number(sin(x));
return S_OK;
}
static HRESULT Math_sqrt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -449,7 +461,8 @@ static HRESULT Math_sqrt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
TRACE("\n");
if(!argc) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -457,12 +470,13 @@ static HRESULT Math_sqrt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
if(retv) num_set_val(retv, sqrt(x));
if(r)
*r = jsval_number(sqrt(x));
return S_OK;
}
static HRESULT Math_tan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double x;
HRESULT hres;
......@@ -470,7 +484,8 @@ static HRESULT Math_tan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
TRACE("\n");
if(!argc) {
if(retv) num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
......@@ -478,7 +493,8 @@ static HRESULT Math_tan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
if(FAILED(hres))
return hres;
if(retv) num_set_val(retv, tan(x));
if(r)
*r = jsval_number(tan(x));
return S_OK;
}
......
......@@ -219,7 +219,7 @@ static inline void number_to_exponential(double val, int prec, BSTR *out)
/* ECMA-262 3rd Edition 15.7.4.2 */
static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
NumberInstance *number;
INT radix = 10;
......@@ -334,24 +334,22 @@ static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
return E_OUTOFMEMORY;
}
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = str;
}else {
if(r)
*r = jsval_string(str);
else
SysFreeString(str);
}
return S_OK;
}
static HRESULT Number_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Number_toFixed(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
NumberInstance *number;
DOUBLE val;
......@@ -385,17 +383,15 @@ static HRESULT Number_toFixed(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
number_to_fixed(val, prec, &str);
}
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = str;
}else {
if(r)
*r = jsval_string(str);
else
SysFreeString(str);
}
return S_OK;
}
static HRESULT Number_toExponential(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
NumberInstance *number;
DOUBLE val;
......@@ -431,17 +427,15 @@ static HRESULT Number_toExponential(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla
number_to_exponential(val, prec, &str);
}
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = str;
}else {
if(r)
*r = jsval_string(str);
else
SysFreeString(str);
}
return S_OK;
}
static HRESULT Number_toPrecision(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
NumberInstance *number;
INT prec = 0, size;
......@@ -481,17 +475,15 @@ static HRESULT Number_toPrecision(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
number_to_fixed(val, prec-size, &str);
}
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = str;
}else {
if(r)
*r = jsval_string(str);
else
SysFreeString(str);
}
return S_OK;
}
static HRESULT Number_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
NumberInstance *number;
......@@ -500,13 +492,13 @@ static HRESULT Number_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
if(!(number = number_this(jsthis)))
return throw_type_error(ctx, ei, JS_E_NUMBER_EXPECTED, NULL);
if(retv)
num_set_val(retv, number->value);
if(r)
*r = jsval_number(number->value);
return S_OK;
}
static HRESULT Number_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
NumberInstance *number = number_from_vdisp(jsthis);
......@@ -514,7 +506,7 @@ static HRESULT Number_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
case INVOKE_FUNC:
return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
case DISPATCH_PROPERTYGET:
num_set_val(retv, number->value);
*r = jsval_number(number->value);
break;
default:
......@@ -552,7 +544,7 @@ static const builtin_info_t NumberInst_info = {
};
static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
double n;
HRESULT hres;
......@@ -562,8 +554,8 @@ static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
switch(flags) {
case INVOKE_FUNC:
if(!argc) {
if(retv)
num_set_int(retv, 0);
if(r)
*r = jsval_number(0);
return S_OK;
}
......@@ -571,8 +563,8 @@ static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
if(retv)
num_set_val(retv, n);
if(r)
*r = jsval_number(n);
break;
case DISPATCH_CONSTRUCT: {
......@@ -590,7 +582,7 @@ static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
var_set_jsdisp(retv, obj);
*r = jsval_obj(obj);
break;
}
default:
......
......@@ -33,7 +33,7 @@ static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','
static const WCHAR default_valueW[] = {'[','o','b','j','e','c','t',' ','O','b','j','e','c','t',']',0};
static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *jsdisp;
const WCHAR *str;
......@@ -66,20 +66,20 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
return E_FAIL;
}
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocStringLen(NULL, 9+strlenW(str));
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocStringLen(NULL, 9+strlenW(str));
if(!ret)
return E_OUTOFMEMORY;
sprintfW(V_BSTR(retv), formatW, str);
sprintfW(ret, formatW, str);
*r = jsval_string(ret);
}
return S_OK;
}
static HRESULT Object_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -88,26 +88,23 @@ static HRESULT Object_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD fl
return E_FAIL;
}
return jsdisp_call_name(jsthis->u.jsdisp, toStringW, DISPATCH_METHOD, 0, NULL, retv, ei);
return jsdisp_call_name(jsthis->u.jsdisp, toStringW, DISPATCH_METHOD, 0, NULL, r, ei);
}
static HRESULT Object_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
if(retv) {
if(r) {
IDispatch_AddRef(jsthis->u.disp);
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = jsthis->u.disp;
*r = jsval_disp(jsthis->u.disp);
}
return S_OK;
}
static HRESULT Object_hasOwnProperty(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR name;
DISPID id;
......@@ -116,11 +113,8 @@ static HRESULT Object_hasOwnProperty(script_ctx_t *ctx, vdisp_t *jsthis, WORD fl
TRACE("\n");
if(!argc) {
if(retv) {
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = VARIANT_FALSE;
}
if(r)
*r = jsval_bool(FALSE);
return S_OK;
}
......@@ -135,11 +129,8 @@ static HRESULT Object_hasOwnProperty(script_ctx_t *ctx, vdisp_t *jsthis, WORD fl
if(FAILED(hres))
return hres;
if(retv) {
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = result;
}
if(r)
*r = jsval_bool(result);
return S_OK;
}
......@@ -151,41 +142,40 @@ static HRESULT Object_hasOwnProperty(script_ctx_t *ctx, vdisp_t *jsthis, WORD fl
&name, 1, ctx->lcid, &id);
}
if(retv) {
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = SUCCEEDED(hres) ? VARIANT_TRUE : VARIANT_FALSE;
}
if(r)
*r = jsval_bool(SUCCEEDED(hres));
return S_OK;
}
static HRESULT Object_propertyIsEnumerable(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Object_isPrototypeOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Object_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
switch(flags) {
case INVOKE_FUNC:
return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
case DISPATCH_PROPERTYGET:
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(default_valueW);
if(!V_BSTR(retv))
case DISPATCH_PROPERTYGET: {
BSTR ret = SysAllocString(default_valueW);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
break;
}
default:
FIXME("unimplemented flags %x\n", flags);
return E_NOTIMPL;
......@@ -226,7 +216,7 @@ static const builtin_info_t ObjectInst_info = {
};
static HRESULT ObjectConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
HRESULT hres;
......@@ -242,12 +232,10 @@ static HRESULT ObjectConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = disp;
}else {
if(r)
*r = jsval_disp(disp);
else
IDispatch_Release(disp);
}
return S_OK;
}
}
......@@ -259,8 +247,8 @@ static HRESULT ObjectConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
if(retv)
var_set_jsdisp(retv, obj);
if(r)
*r = jsval_obj(obj);
else
jsdisp_release(obj);
break;
......
......@@ -3474,18 +3474,17 @@ HRESULT regexp_match(script_ctx_t *ctx, jsdisp_t *dispex, const WCHAR *str, DWOR
}
static HRESULT RegExp_source(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
switch(flags) {
case DISPATCH_PROPERTYGET: {
RegExpInstance *This = regexp_from_vdisp(jsthis);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(This->str);
if(!V_BSTR(retv))
BSTR ret = SysAllocString(This->str);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
break;
}
default:
......@@ -3497,21 +3496,21 @@ static HRESULT RegExp_source(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
}
static HRESULT RegExp_global(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT RegExp_ignoreCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT RegExp_multiline(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
......@@ -3535,7 +3534,7 @@ static INT index_from_var(script_ctx_t *ctx, VARIANT *v)
}
static HRESULT RegExp_lastIndex(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -3543,8 +3542,7 @@ static HRESULT RegExp_lastIndex(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
case DISPATCH_PROPERTYGET: {
RegExpInstance *regexp = regexp_from_vdisp(jsthis);
V_VT(retv) = VT_EMPTY;
return VariantCopy(retv, &regexp->last_index_var);
return variant_to_jsval(&regexp->last_index_var, r);
}
case DISPATCH_PROPERTYPUT: {
RegExpInstance *regexp = regexp_from_vdisp(jsthis);
......@@ -3566,7 +3564,7 @@ static HRESULT RegExp_lastIndex(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
}
static HRESULT RegExp_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
......@@ -3697,7 +3695,7 @@ static HRESULT run_exec(script_ctx_t *ctx, vdisp_t *jsthis, VARIANT *arg, jsexce
}
static HRESULT RegExp_exec(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
match_result_t *parens = NULL, match;
DWORD parens_cnt = 0;
......@@ -3711,17 +3709,15 @@ static HRESULT RegExp_exec(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsig
if(FAILED(hres))
return hres;
if(retv) {
if(r) {
if(b) {
IDispatch *ret;
hres = create_match_array(ctx, string, &match, parens, parens_cnt, ei, &ret);
if(SUCCEEDED(hres)) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = ret;
}
if(SUCCEEDED(hres))
*r = jsval_disp(ret);
}else {
V_VT(retv) = VT_NULL;
*r = jsval_null();
}
}
......@@ -3731,7 +3727,7 @@ static HRESULT RegExp_exec(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsig
}
static HRESULT RegExp_test(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
match_result_t match;
VARIANT undef_var;
......@@ -3753,15 +3749,13 @@ static HRESULT RegExp_test(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsig
if(FAILED(hres))
return hres;
if(retv) {
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = b;
}
if(r)
*r = jsval_bool(b);
return S_OK;
}
static HRESULT RegExp_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -3927,7 +3921,7 @@ HRESULT create_regexp_var(script_ctx_t *ctx, VARIANT *src_arg, VARIANT *flags_ar
}
HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, BSTR str,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR indexW[] = {'i','n','d','e','x',0};
static const WCHAR inputW[] = {'i','n','p','u','t',0};
......@@ -3951,17 +3945,15 @@ HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, BSTR str,
if(FAILED(hres))
return hres;
if(retv) {
if(r) {
if(hres == S_OK) {
IDispatch *ret;
hres = create_match_array(ctx, str, &match, parens, parens_cnt, ei, &ret);
if(SUCCEEDED(hres)) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = ret;
}
if(SUCCEEDED(hres))
*r = jsval_disp(ret);
}else {
V_VT(retv) = VT_NULL;
*r = jsval_null();
}
}
......@@ -3976,8 +3968,8 @@ HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, BSTR str,
if(!match_cnt) {
TRACE("no match\n");
if(retv)
V_VT(retv) = VT_NULL;
if(r)
*r = jsval_null();
return S_OK;
}
......@@ -4019,15 +4011,15 @@ HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, BSTR str,
heap_free(match_result);
if(SUCCEEDED(hres) && retv)
var_set_jsdisp(retv, array);
if(SUCCEEDED(hres) && r)
*r = jsval_obj(array);
else
jsdisp_release(array);
return hres;
}
static HRESULT RegExpConstr_leftContext(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -4039,8 +4031,7 @@ static HRESULT RegExpConstr_leftContext(script_ctx_t *ctx, vdisp_t *jsthis, WORD
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
break;
}
case DISPATCH_PROPERTYPUT:
......@@ -4054,7 +4045,7 @@ static HRESULT RegExpConstr_leftContext(script_ctx_t *ctx, vdisp_t *jsthis, WORD
}
static HRESULT RegExpConstr_rightContext(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -4066,8 +4057,7 @@ static HRESULT RegExpConstr_rightContext(script_ctx_t *ctx, vdisp_t *jsthis, WOR
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
break;
}
case DISPATCH_PROPERTYPUT:
......@@ -4081,7 +4071,7 @@ static HRESULT RegExpConstr_rightContext(script_ctx_t *ctx, vdisp_t *jsthis, WOR
}
static HRESULT RegExpConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
......@@ -4097,8 +4087,8 @@ static HRESULT RegExpConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return throw_regexp_error(ctx, ei, JS_E_REGEXP_SYNTAX, NULL);
}
if(retv)
var_set_jsdisp(retv, jsdisp);
if(r)
*r = jsval_obj(jsdisp);
else
jsdisp_release(jsdisp);
return S_OK;
......@@ -4121,8 +4111,8 @@ static HRESULT RegExpConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
if(retv)
var_set_jsdisp(retv, ret);
if(r)
*r = jsval_obj(ret);
else
jsdisp_release(ret);
return S_OK;
......
......@@ -103,7 +103,7 @@ static HRESULT get_string_val(script_ctx_t *ctx, vdisp_t *jsthis, jsexcept_t *ei
}
static HRESULT String_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("%p\n", jsthis);
......@@ -111,7 +111,7 @@ static HRESULT String_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
case DISPATCH_PROPERTYGET: {
StringInstance *string = string_from_vdisp(jsthis);
num_set_int(retv, string->length);
*r = jsval_number(string->length);
break;
}
default:
......@@ -122,7 +122,7 @@ static HRESULT String_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
return S_OK;
}
static HRESULT stringobj_to_string(vdisp_t *jsthis, VARIANT *retv)
static HRESULT stringobj_to_string(vdisp_t *jsthis, jsval_t *r)
{
StringInstance *string;
......@@ -131,36 +131,35 @@ static HRESULT stringobj_to_string(vdisp_t *jsthis, VARIANT *retv)
return E_FAIL;
}
if(retv) {
if(r) {
BSTR str = SysAllocString(string->str);
if(!str)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = str;
*r = jsval_string(str);
}
return S_OK;
}
/* ECMA-262 3rd Edition 15.5.4.2 */
static HRESULT String_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return stringobj_to_string(jsthis, retv);
return stringobj_to_string(jsthis, r);
}
/* ECMA-262 3rd Edition 15.5.4.2 */
static HRESULT String_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
TRACE("\n");
return stringobj_to_string(jsthis, retv);
return stringobj_to_string(jsthis, r);
}
static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, VARIANT *retv,
static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, jsval_t *r,
jsexcept_t *ei, const WCHAR *tagname)
{
const WCHAR *str;
......@@ -174,7 +173,7 @@ static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, V
if(FAILED(hres))
return hres;
if(retv) {
if(r) {
BSTR ret = SysAllocStringLen(NULL, length + 2*strlenW(tagname) + 5);
if(!ret) {
SysFreeString(val_str);
......@@ -182,16 +181,14 @@ static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, V
}
sprintfW(ret, tagfmt, tagname, str, tagname);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}
SysFreeString(val_str);
return S_OK;
}
static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsigned argc, VARIANT *argv, VARIANT *retv,
static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsigned argc, VARIANT *argv, jsval_t *r,
jsexcept_t *ei, const WCHAR *tagname, const WCHAR *attr)
{
static const WCHAR tagfmtW[]
......@@ -237,7 +234,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
}
}
if(retv) {
if(r) {
BSTR ret = SysAllocStringLen(NULL, length + 2*strlenW(tagname)
+ strlenW(attr) + SysStringLen(attr_value) + 9);
if(!ret) {
......@@ -247,9 +244,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
}
sprintfW(ret, tagfmtW, tagname, attr, attr_value, str, tagname);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
}
SysFreeString(attr_value);
......@@ -258,38 +253,38 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
}
static HRESULT String_anchor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR fontW[] = {'A',0};
static const WCHAR colorW[] = {'N','A','M','E',0};
return do_attribute_tag_format(ctx, jsthis, argc, argv, retv, ei, fontW, colorW);
return do_attribute_tag_format(ctx, jsthis, argc, argv, r, ei, fontW, colorW);
}
static HRESULT String_big(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR bigtagW[] = {'B','I','G',0};
return do_attributeless_tag_format(ctx, jsthis, retv, ei, bigtagW);
return do_attributeless_tag_format(ctx, jsthis, r, ei, bigtagW);
}
static HRESULT String_blink(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR blinktagW[] = {'B','L','I','N','K',0};
return do_attributeless_tag_format(ctx, jsthis, retv, ei, blinktagW);
return do_attributeless_tag_format(ctx, jsthis, r, ei, blinktagW);
}
static HRESULT String_bold(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR boldtagW[] = {'B',0};
return do_attributeless_tag_format(ctx, jsthis, retv, ei, boldtagW);
return do_attributeless_tag_format(ctx, jsthis, r, ei, boldtagW);
}
/* ECMA-262 3rd Edition 15.5.4.5 */
static HRESULT String_charAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
const WCHAR *str;
DWORD length;
......@@ -314,7 +309,7 @@ static HRESULT String_charAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
pos = is_int32(d) ? d : -1;
}
if(!retv) {
if(!r) {
SysFreeString(val_str);
return S_OK;
}
......@@ -328,14 +323,13 @@ static HRESULT String_charAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
return E_OUTOFMEMORY;
}
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
*r = jsval_string(ret);
return S_OK;
}
/* ECMA-262 3rd Edition 15.5.4.5 */
static HRESULT String_charCodeAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
const WCHAR *str;
BSTR val_str;
......@@ -359,16 +353,16 @@ static HRESULT String_charCodeAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(!is_int32(d) || d < 0 || d >= length) {
SysFreeString(val_str);
if(retv)
num_set_val(retv, NAN);
if(r)
*r = jsval_number(NAN);
return S_OK;
}
idx = d;
}
if(retv)
num_set_int(retv, str[idx]);
if(r)
*r = jsval_number(str[idx]);
SysFreeString(val_str);
return S_OK;
......@@ -376,7 +370,7 @@ static HRESULT String_charCodeAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
/* ECMA-262 3rd Edition 15.5.4.6 */
static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR *strs = NULL, ret = NULL;
DWORD len = 0, i, l, str_cnt;
......@@ -423,42 +417,40 @@ static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
if(FAILED(hres))
return hres;
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}else {
if(r)
*r = jsval_string(ret);
else
SysFreeString(ret);
}
return S_OK;
}
static HRESULT String_fixed(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR fixedtagW[] = {'T','T',0};
return do_attributeless_tag_format(ctx, jsthis, retv, ei, fixedtagW);
return do_attributeless_tag_format(ctx, jsthis, r, ei, fixedtagW);
}
static HRESULT String_fontcolor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR fontW[] = {'F','O','N','T',0};
static const WCHAR colorW[] = {'C','O','L','O','R',0};
return do_attribute_tag_format(ctx, jsthis, argc, argv, retv, ei, fontW, colorW);
return do_attribute_tag_format(ctx, jsthis, argc, argv, r, ei, fontW, colorW);
}
static HRESULT String_fontsize(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR fontW[] = {'F','O','N','T',0};
static const WCHAR colorW[] = {'S','I','Z','E',0};
return do_attribute_tag_format(ctx, jsthis, argc, argv, retv, ei, fontW, colorW);
return do_attribute_tag_format(ctx, jsthis, argc, argv, r, ei, fontW, colorW);
}
static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
DWORD length, pos = 0;
const WCHAR *str;
......@@ -473,8 +465,8 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
return hres;
if(!argc) {
if(retv)
num_set_int(retv, -1);
if(r)
*r = jsval_number(-1);
SysFreeString(val_str);
return S_OK;
}
......@@ -508,21 +500,21 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
if(FAILED(hres))
return hres;
if(retv)
num_set_int(retv, ret);
if(r)
*r = jsval_number(ret);
return S_OK;
}
static HRESULT String_italics(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR italicstagW[] = {'I',0};
return do_attributeless_tag_format(ctx, jsthis, retv, ei, italicstagW);
return do_attributeless_tag_format(ctx, jsthis, r, ei, italicstagW);
}
/* ECMA-262 3rd Edition 15.5.4.8 */
static HRESULT String_lastIndexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR search_str, val_str;
DWORD length, pos = 0, search_len;
......@@ -537,8 +529,8 @@ static HRESULT String_lastIndexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return hres;
if(!argc) {
if(retv)
num_set_int(retv, -1);
if(r)
*r = jsval_number(-1);
SysFreeString(val_str);
return S_OK;
}
......@@ -577,23 +569,23 @@ static HRESULT String_lastIndexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
if(retv)
num_set_int(retv, ret);
if(r)
*r = jsval_number(ret);
return S_OK;
}
static HRESULT String_link(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR fontW[] = {'A',0};
static const WCHAR colorW[] = {'H','R','E','F',0};
return do_attribute_tag_format(ctx, jsthis, argc, argv, retv, ei, fontW, colorW);
return do_attribute_tag_format(ctx, jsthis, argc, argv, r, ei, fontW, colorW);
}
/* ECMA-262 3rd Edition 15.5.4.10 */
static HRESULT String_match(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
const WCHAR *str;
jsdisp_t *regexp;
......@@ -604,10 +596,8 @@ static HRESULT String_match(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
TRACE("\n");
if(!argc) {
if(retv) {
V_VT(retv) = VT_NULL;
}
if(r)
*r = jsval_null();
return S_OK;
}
......@@ -638,7 +628,7 @@ static HRESULT String_match(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(!val_str)
val_str = SysAllocStringLen(str, length);
if(val_str)
hres = regexp_string_match(ctx, regexp, val_str, retv, ei);
hres = regexp_string_match(ctx, regexp, val_str, r, ei);
else
hres = E_OUTOFMEMORY;
}
......@@ -687,7 +677,7 @@ static HRESULT rep_call(script_ctx_t *ctx, jsdisp_t *func, const WCHAR *str, mat
{
VARIANT *argv;
unsigned argc;
VARIANT var;
jsval_t val;
DWORD i;
HRESULT hres = S_OK;
......@@ -722,7 +712,7 @@ static HRESULT rep_call(script_ctx_t *ctx, jsdisp_t *func, const WCHAR *str, mat
}
if(SUCCEEDED(hres))
hres = jsdisp_call_value(func, NULL, DISPATCH_METHOD, argc, argv, &var, ei);
hres = jsdisp_call_value(func, NULL, DISPATCH_METHOD, argc, argv, &val, ei);
for(i=0; i < parens_cnt+3; i++) {
if(i != parens_cnt+1)
......@@ -733,14 +723,14 @@ static HRESULT rep_call(script_ctx_t *ctx, jsdisp_t *func, const WCHAR *str, mat
if(FAILED(hres))
return hres;
hres = to_string(ctx, &var, ei, ret);
VariantClear(&var);
hres = to_string_jsval(ctx, val, ei, ret);
jsval_release(val);
return hres;
}
/* ECMA-262 3rd Edition 15.5.4.11 */
static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
const WCHAR *str;
DWORD parens_cnt = 0, parens_size=0, rep_len=0, length;
......@@ -758,15 +748,14 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
return hres;
if(!argc) {
if(retv) {
if(r) {
if(!val_str) {
val_str = SysAllocStringLen(str, length);
if(!val_str)
return E_OUTOFMEMORY;
}
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = val_str;
*r = jsval_string(val_str);
}
return S_OK;
}
......@@ -961,14 +950,13 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
jsdisp_release(regexp);
SysFreeString(val_str);
if(SUCCEEDED(hres) && retv) {
if(SUCCEEDED(hres) && r) {
ret_str = SysAllocStringLen(ret.buf, ret.len);
if(!ret_str)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret_str;
TRACE("= %s\n", debugstr_w(ret_str));
*r = jsval_string(ret_str);
}
heap_free(ret.buf);
......@@ -976,7 +964,7 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
}
static HRESULT String_search(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
jsdisp_t *regexp = NULL;
const WCHAR *str, *cp;
......@@ -992,8 +980,8 @@ static HRESULT String_search(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
return hres;
if(!argc) {
if(retv)
V_VT(retv) = VT_NULL;
if(r)
*r = jsval_null();
SysFreeString(val_str);
return S_OK;
}
......@@ -1023,14 +1011,14 @@ static HRESULT String_search(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
if(FAILED(hres))
return hres;
if(retv)
num_set_int(retv, hres == S_OK ? match.str-str : -1);
if(r)
*r = jsval_number(hres == S_OK ? match.str-str : -1);
return S_OK;
}
/* ECMA-262 3rd Edition 15.5.4.13 */
static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
const WCHAR *str;
BSTR val_str;
......@@ -1092,15 +1080,14 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(end < start)
end = start;
if(retv) {
if(r) {
BSTR retstr = SysAllocStringLen(str+start, end-start);
if(!retstr) {
SysFreeString(val_str);
return E_OUTOFMEMORY;
}
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = retstr;
*r = jsval_string(retstr);
}
SysFreeString(val_str);
......@@ -1108,14 +1095,14 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
}
static HRESULT String_small(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR smalltagW[] = {'S','M','A','L','L',0};
return do_attributeless_tag_format(ctx, jsthis, retv, ei, smalltagW);
return do_attributeless_tag_format(ctx, jsthis, r, ei, smalltagW);
}
static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
match_result_t *match_result = NULL;
DWORD length, match_cnt, i, match_len = 0;
......@@ -1230,8 +1217,8 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
SysFreeString(val_str);
heap_free(match_result);
if(SUCCEEDED(hres) && retv)
var_set_jsdisp(retv, array);
if(SUCCEEDED(hres) && r)
*r = jsval_obj(array);
else
jsdisp_release(array);
......@@ -1239,22 +1226,22 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
}
static HRESULT String_strike(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR striketagW[] = {'S','T','R','I','K','E',0};
return do_attributeless_tag_format(ctx, jsthis, retv, ei, striketagW);
return do_attributeless_tag_format(ctx, jsthis, r, ei, striketagW);
}
static HRESULT String_sub(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR subtagW[] = {'S','U','B',0};
return do_attributeless_tag_format(ctx, jsthis, retv, ei, subtagW);
return do_attributeless_tag_format(ctx, jsthis, r, ei, subtagW);
}
/* ECMA-262 3rd Edition 15.5.4.15 */
static HRESULT String_substring(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
const WCHAR *str;
BSTR val_str;
......@@ -1301,13 +1288,13 @@ static HRESULT String_substring(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
end = tmp;
}
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocStringLen(str+start, end-start);
if(!V_BSTR(retv)) {
if(r) {
BSTR ret = SysAllocStringLen(str+start, end-start);
if(!ret) {
SysFreeString(val_str);
return E_OUTOFMEMORY;
}
*r = jsval_string(ret);
}
SysFreeString(val_str);
return S_OK;
......@@ -1315,7 +1302,7 @@ static HRESULT String_substring(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
/* ECMA-262 3rd Edition B.2.3 */
static HRESULT String_substr(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
BSTR val_str;
const WCHAR *str;
......@@ -1357,10 +1344,11 @@ static HRESULT String_substr(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
}
hres = S_OK;
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocStringLen(str+start, len);
if(!V_BSTR(retv))
if(r) {
BSTR ret = SysAllocStringLen(str+start, len);
if(ret)
*r = jsval_string(ret);
else
hres = E_OUTOFMEMORY;
}
......@@ -1369,14 +1357,14 @@ static HRESULT String_substr(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
}
static HRESULT String_sup(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
static const WCHAR suptagW[] = {'S','U','P',0};
return do_attributeless_tag_format(ctx, jsthis, retv, ei, suptagW);
return do_attributeless_tag_format(ctx, jsthis, r, ei, suptagW);
}
static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
const WCHAR* str;
DWORD length;
......@@ -1389,7 +1377,7 @@ static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
if(retv) {
if(r) {
if(!val_str) {
val_str = SysAllocStringLen(str, length);
if(!val_str)
......@@ -1397,16 +1385,14 @@ static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
}
strlwrW(val_str);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = val_str;
*r = jsval_string(val_str);
}
else SysFreeString(val_str);
return S_OK;
}
static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
const WCHAR* str;
DWORD length;
......@@ -1419,7 +1405,7 @@ static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
if(retv) {
if(r) {
if(!val_str) {
val_str = SysAllocStringLen(str, length);
if(!val_str)
......@@ -1427,37 +1413,35 @@ static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
}
struprW(val_str);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = val_str;
*r = jsval_string(val_str);
}
else SysFreeString(val_str);
return S_OK;
}
static HRESULT String_toLocaleLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT String_toLocaleUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT String_localeCompare(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT String_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
StringInstance *This = string_from_vdisp(jsthis);
......@@ -1471,8 +1455,7 @@ static HRESULT String_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(!str)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = str;
*r = jsval_string(str);
break;
}
default:
......@@ -1551,12 +1534,14 @@ static const builtin_info_t StringInst_info = {
/* ECMA-262 3rd Edition 15.5.3.2 */
static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
unsigned argc, VARIANT *argv, jsval_t *r, jsexcept_t *ei)
{
DWORD i, code;
BSTR ret;
HRESULT hres;
TRACE("\n");
ret = SysAllocStringLen(NULL, argc);
if(!ret)
return E_OUTOFMEMORY;
......@@ -1571,17 +1556,15 @@ static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WOR
ret[i] = code;
}
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}
else SysFreeString(ret);
if(r)
*r = jsval_string(ret);
else
SysFreeString(ret);
return S_OK;
}
static HRESULT StringConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
HRESULT hres;
......@@ -1601,8 +1584,7 @@ static HRESULT StringConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return E_OUTOFMEMORY;
}
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = str;
*r = jsval_string(str);
break;
}
case DISPATCH_CONSTRUCT: {
......@@ -1624,7 +1606,7 @@ static HRESULT StringConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
var_set_jsdisp(retv, ret);
*r = jsval_obj(ret);
break;
}
......
......@@ -45,7 +45,7 @@ static inline VBArrayInstance *vbarray_this(vdisp_t *jsthis)
}
static HRESULT VBArray_dimensions(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
VBArrayInstance *vbarray;
......@@ -55,13 +55,13 @@ static HRESULT VBArray_dimensions(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
if(!vbarray)
return throw_type_error(ctx, ei, JS_E_VBARRAY_EXPECTED, NULL);
if(retv)
num_set_int(retv, SafeArrayGetDim(vbarray->safearray));
if(r)
*r = jsval_number(SafeArrayGetDim(vbarray->safearray));
return S_OK;
}
static HRESULT VBArray_getItem(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
VBArrayInstance *vbarray;
int i, *indexes;
......@@ -96,14 +96,13 @@ static HRESULT VBArray_getItem(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, un
else if(FAILED(hres))
return hres;
if(retv)
hres = VariantCopy(retv, &out);
if(r)
hres = jsval_variant(r, &out);
return hres;
}
static HRESULT VBArray_lbound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
VBArrayInstance *vbarray;
int dim;
......@@ -128,13 +127,13 @@ static HRESULT VBArray_lbound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, uns
else if(FAILED(hres))
return hres;
if(retv)
num_set_int(retv, dim);
if(r)
*r = jsval_number(dim);
return S_OK;
}
static HRESULT VBArray_toArray(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
VBArrayInstance *vbarray;
jsdisp_t *array;
......@@ -176,13 +175,13 @@ static HRESULT VBArray_toArray(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, un
SafeArrayUnaccessData(vbarray->safearray);
if(retv)
var_set_jsdisp(retv, array);
if(r)
*r = jsval_obj(array);
return S_OK;
}
static HRESULT VBArray_ubound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
VBArrayInstance *vbarray;
int dim;
......@@ -207,13 +206,13 @@ static HRESULT VBArray_ubound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, uns
else if(FAILED(hres))
return hres;
if(retv)
num_set_int(retv, dim);
if(r)
*r = jsval_number(dim);
return S_OK;
}
static HRESULT VBArray_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
FIXME("\n");
......@@ -275,7 +274,7 @@ static HRESULT alloc_vbarray(script_ctx_t *ctx, jsdisp_t *object_prototype, VBAr
}
static HRESULT VBArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, VARIANT *argv,
VARIANT *retv, jsexcept_t *ei)
jsval_t *r, jsexcept_t *ei)
{
VBArrayInstance *vbarray;
HRESULT hres;
......@@ -287,8 +286,7 @@ static HRESULT VBArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags
if(argc<1 || V_VT(argv) != (VT_ARRAY|VT_VARIANT))
return throw_type_error(ctx, ei, JS_E_VBARRAY_EXPECTED, NULL);
hres = VariantCopy(retv, argv);
return hres;
return variant_to_jsval(argv, r);
case DISPATCH_CONSTRUCT:
if(argc<1 || V_VT(argv) != (VT_ARRAY|VT_VARIANT))
......@@ -304,7 +302,7 @@ static HRESULT VBArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags
return hres;
}
var_set_jsdisp(retv, &vbarray->dispex);
*r = jsval_obj(&vbarray->dispex);
break;
default:
......
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