Commit 2ae0f440 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added a helper function for setting VARIANT value to jsdisp_t.

parent b66eb177
......@@ -235,12 +235,10 @@ static HRESULT Array_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
if(FAILED(hres))
return hres;
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(ret);
}else {
if(retv)
var_set_jsdisp(retv, ret);
else
jsdisp_release(ret);
}
return S_OK;
}
......@@ -508,8 +506,7 @@ static HRESULT Array_reverse(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISP
}
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(jsthis);
var_set_jsdisp(retv, jsthis);
IDispatch_AddRef(V_DISPATCH(retv));
}
......@@ -640,10 +637,8 @@ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPA
}
}
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(arr);
}
if(retv)
var_set_jsdisp(retv, arr);
else
jsdisp_release(arr);
......@@ -750,8 +745,7 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPAR
if(cmp_func)
jsdisp_release(cmp_func);
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(jsthis);
var_set_jsdisp(retv, jsthis);
IDispatch_AddRef(V_DISPATCH(retv));
}
return S_OK;
......@@ -856,8 +850,7 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPAR
return hres;
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(jsthis);
var_set_jsdisp(retv, jsthis);
IDispatch_AddRef(V_DISPATCH(retv));
}
......@@ -967,10 +960,8 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPP
return hres;
}
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(ret_array);
}
if(retv)
var_set_jsdisp(retv, ret_array);
return S_OK;
}
......@@ -1153,8 +1144,7 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
if(FAILED(hres))
return hres;
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(obj);
var_set_jsdisp(retv, obj);
return S_OK;
}
......@@ -1172,8 +1162,7 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
return hres;
}
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(obj);
var_set_jsdisp(retv, obj);
break;
}
default:
......
......@@ -137,8 +137,7 @@ static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(FAILED(hres))
return hres;
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(bool);
var_set_jsdisp(retv, bool);
return S_OK;
}
......
......@@ -2575,8 +2575,7 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
}
}
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(date);
var_set_jsdisp(retv, date);
return S_OK;
case INVOKE_FUNC: {
......
......@@ -321,9 +321,7 @@ static HRESULT prop_get(jsdisp_t *This, dispex_prop_t *prop, DISPPARAMS *dp,
break;
prop->type = PROP_VARIANT;
V_VT(&prop->u.var) = VT_DISPATCH;
V_DISPATCH(&prop->u.var) = (IDispatch*)_IDispatchEx_(obj);
var_set_jsdisp(&prop->u.var, obj);
hres = VariantCopy(retv, &prop->u.var);
}else {
vdisp_t vthis;
......@@ -839,8 +837,7 @@ HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const built
jsexcept_t jsexcept;
VARIANT var;
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(constr);
var_set_jsdisp(&var, constr);
memset(&jsexcept, 0, sizeof(jsexcept));
hres = prop_put(dispex, prop, &var, &jsexcept, NULL/*FIXME*/);
}
......
......@@ -383,8 +383,7 @@ static HRESULT literal_to_var(script_ctx_t *ctx, literal_t *literal, VARIANT *v)
if(FAILED(hres))
return hres;
V_VT(v) = VT_DISPATCH;
V_DISPATCH(v) = (IDispatch*)_IDispatchEx_(regexp);
var_set_jsdisp(v, regexp);
}
}
......@@ -433,8 +432,7 @@ HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *so
if(FAILED(hres))
return hres;
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(func_obj);
var_set_jsdisp(&var, func_obj);
hres = jsdisp_propput_name(ctx->var_disp, func->expr->identifier, &var, ei, NULL);
jsdisp_release(func_obj);
if(FAILED(hres))
......@@ -1353,8 +1351,7 @@ HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD fla
if(FAILED(hres))
return hres;
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
var_set_jsdisp(&var, dispex);
}
ret->type = EXPRVAL_VARIANT;
......@@ -1733,8 +1730,7 @@ HRESULT array_literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWOR
}
ret->type = EXPRVAL_VARIANT;
V_VT(&ret->u.var) = VT_DISPATCH;
V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(array);
var_set_jsdisp(&ret->u.var, array);
return S_OK;
}
......@@ -1786,8 +1782,7 @@ HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWO
}
ret->type = EXPRVAL_VARIANT;
V_VT(&ret->u.var) = VT_DISPATCH;
V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(obj);
var_set_jsdisp(&ret->u.var, obj);
return S_OK;
}
......
......@@ -265,10 +265,8 @@ static HRESULT error_constr(script_ctx_t *ctx, WORD flags, DISPPARAMS *dp,
if(FAILED(hres))
return hres;
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(err);
}
if(retv)
var_set_jsdisp(retv, err);
else
jsdisp_release(err);
......@@ -411,12 +409,8 @@ static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCH
if(FAILED(hres))
return hres;
if(!ei)
return id;
V_VT(&ei->var) = VT_DISPATCH;
V_DISPATCH(&ei->var) = (IDispatch*)_IDispatchEx_(err);
if(ei)
var_set_jsdisp(&ei->var, err);
return id;
}
......
......@@ -170,8 +170,7 @@ static HRESULT create_var_disp(script_ctx_t *ctx, FunctionInstance *function, js
if(FAILED(hres))
return hres;
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(arg_disp);
var_set_jsdisp(&var, arg_disp);
hres = jsdisp_propput_name(var_disp, argumentsW, &var, ei, caller);
if(SUCCEEDED(hres))
hres = init_parameters(var_disp, function, dp, ei, caller);
......@@ -246,13 +245,13 @@ static HRESULT invoke_constructor(script_ctx_t *ctx, FunctionInstance *function,
return hres;
}
V_VT(retv) = VT_DISPATCH;
if(V_VT(&var) == VT_DISPATCH) {
jsdisp_release(this_obj);
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = V_DISPATCH(&var);
}else {
VariantClear(&var);
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(this_obj);
var_set_jsdisp(retv, this_obj);
}
return S_OK;
}
......@@ -549,8 +548,7 @@ static HRESULT Function_arguments(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
case DISPATCH_PROPERTYGET: {
if(function->arguments) {
IDispatchEx_AddRef(_IDispatchEx_(function->arguments));
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(function->arguments);
var_set_jsdisp(retv, function->arguments);
}else {
V_VT(retv) = VT_NULL;
}
......@@ -625,8 +623,7 @@ static HRESULT set_prototype(script_ctx_t *ctx, jsdisp_t *dispex, jsdisp_t *prot
jsexcept_t jsexcept;
VARIANT var;
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(prototype);
var_set_jsdisp(&var, prototype);
memset(&jsexcept, 0, sizeof(jsexcept));
return jsdisp_propput_name(dispex, prototypeW, &var, &jsexcept, NULL/*FIXME*/);
......
......@@ -112,8 +112,7 @@ static HRESULT constructor_call(jsdisp_t *constr, WORD flags, DISPPARAMS *dp,
if(flags != DISPATCH_PROPERTYGET)
return jsdisp_call_value(constr, flags, dp, retv, ei, sp);
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(constr);
var_set_jsdisp(retv, constr);
IDispatchEx_AddRef(_IDispatchEx_(constr));
return S_OK;
}
......@@ -1136,8 +1135,7 @@ HRESULT init_global(script_ctx_t *ctx)
if(FAILED(hres))
return hres;
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(math);
var_set_jsdisp(&var, math);
hres = jsdisp_propput_name(ctx->global, MathW, &var, NULL/*FIXME*/, NULL/*FIXME*/);
jsdisp_release(math);
if(FAILED(hres))
......
......@@ -187,6 +187,11 @@ struct jsdisp_t {
#define _IDispatchEx_(x) ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
static inline IDispatch *to_disp(jsdisp_t *jsdisp)
{
return (IDispatch*)&jsdisp->lpIDispatchExVtbl;
}
static inline void jsdisp_release(jsdisp_t *jsdisp)
{
IDispatchEx_Release(_IDispatchEx_(jsdisp));
......@@ -403,6 +408,12 @@ static inline void num_set_inf(VARIANT *v, BOOL positive)
#endif
}
static inline void var_set_jsdisp(VARIANT *v, jsdisp_t *jsdisp)
{
V_VT(v) = VT_DISPATCH;
V_DISPATCH(v) = to_disp(jsdisp);
}
static inline DWORD make_grfdex(script_ctx_t *ctx, DWORD flags)
{
return (ctx->version << 28) | flags;
......
......@@ -302,8 +302,7 @@ static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(obj);
var_set_jsdisp(retv, obj);
break;
}
default:
......
......@@ -210,8 +210,7 @@ static HRESULT ObjectConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(obj);
var_set_jsdisp(retv, obj);
break;
}
......
......@@ -3987,12 +3987,10 @@ HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, BSTR str,
heap_free(match_result);
if(SUCCEEDED(hres) && retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array);
}else {
if(SUCCEEDED(hres) && retv)
var_set_jsdisp(retv, array);
else
jsdisp_release(array);
}
return hres;
}
......@@ -4066,12 +4064,10 @@ static HRESULT RegExpConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return throw_regexp_error(ctx, ei, IDS_REGEXP_SYNTAX_ERROR, NULL);
}
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(jsdisp);
}else {
if(retv)
var_set_jsdisp(retv, jsdisp);
else
jsdisp_release(jsdisp);
}
return S_OK;
}
jsdisp_release(jsdisp);
......@@ -4092,12 +4088,10 @@ static HRESULT RegExpConstr_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) = (IDispatch*)_IDispatchEx_(ret);
}else {
if(retv)
var_set_jsdisp(retv, ret);
else
jsdisp_release(ret);
}
return S_OK;
}
default:
......
......@@ -1267,12 +1267,10 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
SysFreeString(val_str);
heap_free(match_result);
if(SUCCEEDED(hres) && retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array);
}else {
if(SUCCEEDED(hres) && retv)
var_set_jsdisp(retv, array);
else
jsdisp_release(array);
}
return hres;
}
......@@ -1674,8 +1672,7 @@ static HRESULT StringConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(FAILED(hres))
return hres;
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(ret);
var_set_jsdisp(retv, ret);
break;
}
......
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