2 * Copyright 2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
45 typedef HRESULT (*instr_func_t)(exec_ctx_t*);
74 static BOOL lookup_dynamic_vars(dynamic_var_t *var, const WCHAR *name, ref_t *ref)
77 if(!strcmpiW(var->name, name)) {
89 static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_t invoke_type, ref_t *ref)
97 static const WCHAR errW[] = {'e','r','r',0};
99 if(invoke_type == VBDISP_LET
100 && (ctx->func->type == FUNC_FUNCTION || ctx->func->type == FUNC_PROPGET || ctx->func->type == FUNC_DEFGET)
101 && !strcmpiW(name, ctx->func->name)) {
103 ref->u.v = &ctx->ret_val;
107 for(i=0; i < ctx->func->var_cnt; i++) {
108 if(!strcmpiW(ctx->func->vars[i].name, name)) {
110 ref->u.v = ctx->vars+i;
115 for(i=0; i < ctx->func->arg_cnt; i++) {
116 if(!strcmpiW(ctx->func->args[i].name, name)) {
118 ref->u.v = ctx->args+i;
123 hres = disp_get_id(ctx->this_obj, name, invoke_type, TRUE, &id);
124 if(SUCCEEDED(hres)) {
125 ref->type = REF_DISP;
126 ref->u.d.disp = ctx->this_obj;
131 if(lookup_dynamic_vars(ctx->script->global_vars, name, ref))
134 for(func = ctx->script->global_funcs; func; func = func->next) {
135 if(!strcmpiW(func->name, name)) {
136 ref->type = REF_FUNC;
142 LIST_FOR_EACH_ENTRY(item, &ctx->script->named_items, named_item_t, entry) {
143 if((item->flags & SCRIPTITEM_GLOBALMEMBERS) && item->disp != ctx->this_obj) {
144 hres = disp_get_id(item->disp, name, invoke_type, FALSE, &id);
145 if(SUCCEEDED(hres)) {
146 ref->type = REF_DISP;
147 ref->u.d.disp = item->disp;
153 if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpiW(item->name, name)) {
157 hres = IActiveScriptSite_GetItemInfo(ctx->script->site, name, SCRIPTINFO_IUNKNOWN, &unk, NULL);
159 WARN("GetItemInfo failed: %08x\n", hres);
163 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
164 IUnknown_Release(unk);
166 WARN("object does not implement IDispatch\n");
172 ref->u.obj = item->disp;
177 if(!strcmpiW(name, errW)) {
179 ref->u.obj = (IDispatch*)&ctx->script->err_obj->IDispatchEx_iface;
183 hres = vbdisp_get_id(ctx->script->global_obj, name, invoke_type, TRUE, &id);
184 if(SUCCEEDED(hres)) {
185 ref->type = REF_DISP;
186 ref->u.d.disp = (IDispatch*)&ctx->script->global_obj->IDispatchEx_iface;
191 if(!ctx->func->code_ctx->option_explicit)
192 FIXME("create an attempt to set\n");
194 ref->type = REF_NONE;
198 static inline VARIANT *stack_pop(exec_ctx_t *ctx)
201 return ctx->stack + --ctx->top;
204 static HRESULT stack_push(exec_ctx_t *ctx, VARIANT *v)
206 if(ctx->stack_size == ctx->top) {
209 new_stack = heap_realloc(ctx->stack, ctx->stack_size*2);
212 return E_OUTOFMEMORY;
215 ctx->stack = new_stack;
216 ctx->stack_size *= 2;
219 ctx->stack[ctx->top++] = *v;
223 static void stack_popn(exec_ctx_t *ctx, unsigned n)
226 VariantClear(stack_pop(ctx));
229 static HRESULT stack_pop_val(exec_ctx_t *ctx, variant_val_t *v)
233 var = stack_pop(ctx);
235 if(V_VT(var) == (VT_BYREF|VT_VARIANT)) {
237 var = V_VARIANTREF(var);
242 if(V_VT(var) == VT_DISPATCH) {
246 hres = disp_call(ctx->script, V_DISPATCH(var), DISPID_VALUE, &dp, &v->store);
248 IDispatch_Release(V_DISPATCH(var));
261 static inline void release_val(variant_val_t *v)
267 static HRESULT stack_pop_disp(exec_ctx_t *ctx, IDispatch **ret)
269 VARIANT *v = stack_pop(ctx);
271 if(V_VT(v) == VT_DISPATCH) {
272 *ret = V_DISPATCH(v);
276 if(V_VT(v) != (VT_VARIANT|VT_BYREF)) {
277 FIXME("not supported type: %s\n", debugstr_variant(v));
283 if(V_VT(v) != VT_DISPATCH) {
284 FIXME("not disp %s\n", debugstr_variant(v));
289 IDispatch_AddRef(V_DISPATCH(v));
290 *ret = V_DISPATCH(v);
294 static inline void instr_jmp(exec_ctx_t *ctx, unsigned addr)
296 ctx->instr = ctx->code->instrs + addr;
299 static void vbstack_to_dp(exec_ctx_t *ctx, unsigned arg_cnt, DISPPARAMS *dp)
302 dp->rgdispidNamedArgs = NULL;
309 assert(ctx->top >= arg_cnt);
311 for(i=1; i*2 <= arg_cnt; i++) {
312 tmp = ctx->stack[ctx->top-i];
313 ctx->stack[ctx->top-i] = ctx->stack[ctx->top-arg_cnt+i-1];
314 ctx->stack[ctx->top-arg_cnt+i-1] = tmp;
317 dp->rgvarg = ctx->stack + ctx->top-arg_cnt;
323 static HRESULT do_icall(exec_ctx_t *ctx, VARIANT *res)
325 BSTR identifier = ctx->instr->arg1.bstr;
326 const unsigned arg_cnt = ctx->instr->arg2.uint;
331 hres = lookup_identifier(ctx, identifier, VBDISP_CALLGET, &ref);
335 vbstack_to_dp(ctx, arg_cnt, &dp);
340 FIXME("REF_VAR no res\n");
345 FIXME("arguments not implemented\n");
349 V_VT(res) = VT_BYREF|VT_VARIANT;
350 V_BYREF(res) = V_VT(ref.u.v) == (VT_VARIANT|VT_BYREF) ? V_VARIANTREF(ref.u.v) : ref.u.v;
353 hres = disp_call(ctx->script, ref.u.d.disp, ref.u.d.id, &dp, res);
358 hres = exec_script(ctx->script, ref.u.f, NULL, &dp, res);
364 FIXME("arguments on object\n");
369 IDispatch_AddRef(ref.u.obj);
370 V_VT(res) = VT_DISPATCH;
371 V_DISPATCH(res) = ref.u.obj;
375 FIXME("%s not found\n", debugstr_w(identifier));
376 return DISP_E_UNKNOWNNAME;
379 stack_popn(ctx, arg_cnt);
383 static HRESULT interp_icall(exec_ctx_t *ctx)
390 hres = do_icall(ctx, &v);
394 return stack_push(ctx, &v);
397 static HRESULT interp_icallv(exec_ctx_t *ctx)
400 return do_icall(ctx, NULL);
403 static HRESULT do_mcall(exec_ctx_t *ctx, VARIANT *res)
405 const BSTR identifier = ctx->instr->arg1.bstr;
406 const unsigned arg_cnt = ctx->instr->arg2.uint;
412 hres = stack_pop_disp(ctx, &obj);
421 vbstack_to_dp(ctx, arg_cnt, &dp);
423 hres = disp_get_id(obj, identifier, VBDISP_CALLGET, FALSE, &id);
425 hres = disp_call(ctx->script, obj, id, &dp, res);
426 IDispatch_Release(obj);
430 stack_popn(ctx, arg_cnt);
434 static HRESULT interp_mcall(exec_ctx_t *ctx)
441 hres = do_mcall(ctx, &res);
445 return stack_push(ctx, &res);
448 static HRESULT interp_mcallv(exec_ctx_t *ctx)
452 return do_mcall(ctx, NULL);
455 static HRESULT assign_ident(exec_ctx_t *ctx, BSTR name, VARIANT *val, BOOL own_val)
460 hres = lookup_identifier(ctx, name, VBDISP_LET, &ref);
466 VARIANT *v = ref.u.v;
468 if(V_VT(v) == (VT_VARIANT|VT_BYREF))
476 hres = VariantCopy(v, val);
481 hres = disp_propput(ctx->script, ref.u.d.disp, ref.u.d.id, val);
486 FIXME("functions not implemented\n");
492 FIXME("%s not found\n", debugstr_w(name));
495 return DISP_E_UNKNOWNNAME;
501 static HRESULT interp_assign_ident(exec_ctx_t *ctx)
503 const BSTR arg = ctx->instr->arg1.bstr;
507 TRACE("%s\n", debugstr_w(arg));
509 hres = stack_pop_val(ctx, &v);
513 return assign_ident(ctx, arg, v.v, v.owned);
516 static HRESULT interp_set_ident(exec_ctx_t *ctx)
518 const BSTR arg = ctx->instr->arg1.bstr;
523 TRACE("%s\n", debugstr_w(arg));
525 hres = stack_pop_disp(ctx, &disp);
529 V_VT(&v) = VT_DISPATCH;
530 V_DISPATCH(&v) = disp;
531 return assign_ident(ctx, ctx->instr->arg1.bstr, &v, TRUE);
534 static HRESULT interp_assign_member(exec_ctx_t *ctx)
536 BSTR identifier = ctx->instr->arg1.bstr;
542 TRACE("%s\n", debugstr_w(identifier));
544 hres = stack_pop_disp(ctx, &obj);
553 hres = stack_pop_val(ctx, &val);
555 IDispatch_Release(obj);
559 hres = disp_get_id(obj, identifier, VBDISP_LET, FALSE, &id);
561 hres = disp_propput(ctx->script, obj, id, val.v);
564 IDispatch_Release(obj);
568 static HRESULT interp_set_member(exec_ctx_t *ctx)
570 BSTR identifier = ctx->instr->arg1.bstr;
571 IDispatch *obj, *val;
575 TRACE("%s\n", debugstr_w(identifier));
577 hres = stack_pop_disp(ctx, &obj);
586 hres = stack_pop_disp(ctx, &val);
588 IDispatch_Release(obj);
592 hres = disp_get_id(obj, identifier, VBDISP_SET, FALSE, &id);
593 if(SUCCEEDED(hres)) {
596 V_VT(&v) = VT_DISPATCH;
597 V_DISPATCH(&v) = val;
598 hres = disp_propput(ctx->script, obj, id, &v);
602 IDispatch_Release(val);
603 IDispatch_Release(obj);
607 static HRESULT interp_new(exec_ctx_t *ctx)
609 const WCHAR *arg = ctx->instr->arg1.bstr;
610 class_desc_t *class_desc;
615 TRACE("%s\n", debugstr_w(arg));
617 for(class_desc = ctx->script->classes; class_desc; class_desc = class_desc->next) {
618 if(!strcmpiW(class_desc->name, arg))
622 FIXME("Class %s not found\n", debugstr_w(arg));
626 hres = create_vbdisp(class_desc, &obj);
630 V_VT(&v) = VT_DISPATCH;
631 V_DISPATCH(&v) = (IDispatch*)&obj->IDispatchEx_iface;
632 return stack_push(ctx, &v);
635 static HRESULT interp_jmp(exec_ctx_t *ctx)
637 const unsigned arg = ctx->instr->arg1.uint;
645 static HRESULT interp_jmp_false(exec_ctx_t *ctx)
647 const unsigned arg = ctx->instr->arg1.uint;
653 hres = stack_pop_val(ctx, &val);
657 if(V_VT(val.v) != VT_BOOL) {
658 FIXME("unsupported for %s\n", debugstr_variant(val.v));
666 instr_jmp(ctx, ctx->instr->arg1.uint);
670 static HRESULT interp_jmp_true(exec_ctx_t *ctx)
672 const unsigned arg = ctx->instr->arg1.uint;
678 hres = stack_pop_val(ctx, &val);
682 if(V_VT(val.v) != VT_BOOL) {
683 FIXME("unsupported for %s\n", debugstr_variant(val.v));
689 instr_jmp(ctx, ctx->instr->arg1.uint);
695 static HRESULT interp_ret(exec_ctx_t *ctx)
703 static HRESULT interp_stop(exec_ctx_t *ctx)
707 /* NOTE: this should have effect in debugging mode (that we don't support yet) */
711 static HRESULT interp_me(exec_ctx_t *ctx)
717 IDispatch_AddRef(ctx->this_obj);
718 V_VT(&v) = VT_DISPATCH;
719 V_DISPATCH(&v) = ctx->this_obj;
720 return stack_push(ctx, &v);
723 static HRESULT interp_bool(exec_ctx_t *ctx)
725 const VARIANT_BOOL arg = ctx->instr->arg1.lng;
728 TRACE("%s\n", arg ? "true" : "false");
732 return stack_push(ctx, &v);
735 static HRESULT interp_errmode(exec_ctx_t *ctx)
737 const int err_mode = ctx->instr->arg1.uint;
738 FIXME("%d\n", err_mode);
742 static HRESULT interp_string(exec_ctx_t *ctx)
749 V_BSTR(&v) = SysAllocString(ctx->instr->arg1.str);
751 return E_OUTOFMEMORY;
753 return stack_push(ctx, &v);
756 static HRESULT interp_long(exec_ctx_t *ctx)
758 const LONG arg = ctx->instr->arg1.lng;
765 return stack_push(ctx, &v);
768 static HRESULT interp_short(exec_ctx_t *ctx)
770 const LONG arg = ctx->instr->arg1.lng;
777 return stack_push(ctx, &v);
780 static HRESULT interp_double(exec_ctx_t *ctx)
782 const DOUBLE *arg = ctx->instr->arg1.dbl;
785 TRACE("%lf\n", *arg);
789 return stack_push(ctx, &v);
792 static HRESULT interp_empty(exec_ctx_t *ctx)
799 return stack_push(ctx, &v);
802 static HRESULT interp_null(exec_ctx_t *ctx)
809 return stack_push(ctx, &v);
812 static HRESULT interp_nothing(exec_ctx_t *ctx)
818 V_VT(&v) = VT_DISPATCH;
819 V_DISPATCH(&v) = NULL;
820 return stack_push(ctx, &v);
823 static HRESULT interp_not(exec_ctx_t *ctx)
831 hres = stack_pop_val(ctx, &val);
835 hres = VarNot(val.v, &v);
840 return stack_push(ctx, &v);
843 static HRESULT interp_and(exec_ctx_t *ctx)
851 hres = stack_pop_val(ctx, &r);
855 hres = stack_pop_val(ctx, &l);
856 if(SUCCEEDED(hres)) {
857 hres = VarAnd(l.v, r.v, &v);
864 return stack_push(ctx, &v);
867 static HRESULT interp_or(exec_ctx_t *ctx)
875 hres = stack_pop_val(ctx, &r);
879 hres = stack_pop_val(ctx, &l);
880 if(SUCCEEDED(hres)) {
881 hres = VarOr(l.v, r.v, &v);
888 return stack_push(ctx, &v);
891 static HRESULT interp_xor(exec_ctx_t *ctx)
899 hres = stack_pop_val(ctx, &r);
903 hres = stack_pop_val(ctx, &l);
904 if(SUCCEEDED(hres)) {
905 hres = VarXor(l.v, r.v, &v);
912 return stack_push(ctx, &v);
915 static HRESULT interp_eqv(exec_ctx_t *ctx)
923 hres = stack_pop_val(ctx, &r);
927 hres = stack_pop_val(ctx, &l);
928 if(SUCCEEDED(hres)) {
929 hres = VarEqv(l.v, r.v, &v);
936 return stack_push(ctx, &v);
939 static HRESULT interp_imp(exec_ctx_t *ctx)
947 hres = stack_pop_val(ctx, &r);
951 hres = stack_pop_val(ctx, &l);
952 if(SUCCEEDED(hres)) {
953 hres = VarImp(l.v, r.v, &v);
960 return stack_push(ctx, &v);
963 static HRESULT cmp_oper(exec_ctx_t *ctx)
968 hres = stack_pop_val(ctx, &r);
972 hres = stack_pop_val(ctx, &l);
973 if(SUCCEEDED(hres)) {
974 if(V_VT(l.v) == VT_NULL || V_VT(r.v) == VT_NULL) {
975 FIXME("comparing nulls is not implemented\n");
978 hres = VarCmp(l.v, r.v, ctx->script->lcid, 0);
987 static HRESULT interp_equal(exec_ctx_t *ctx)
994 hres = cmp_oper(ctx);
999 V_BOOL(&v) = hres == VARCMP_EQ ? VARIANT_TRUE : VARIANT_FALSE;
1000 return stack_push(ctx, &v);
1003 static HRESULT interp_nequal(exec_ctx_t *ctx)
1010 hres = cmp_oper(ctx);
1015 V_BOOL(&v) = hres != VARCMP_EQ ? VARIANT_TRUE : VARIANT_FALSE;
1016 return stack_push(ctx, &v);
1019 static HRESULT interp_gt(exec_ctx_t *ctx)
1026 hres = cmp_oper(ctx);
1031 V_BOOL(&v) = hres == VARCMP_GT ? VARIANT_TRUE : VARIANT_FALSE;
1032 return stack_push(ctx, &v);
1035 static HRESULT interp_gteq(exec_ctx_t *ctx)
1042 hres = cmp_oper(ctx);
1047 V_BOOL(&v) = hres == VARCMP_GT || hres == VARCMP_EQ ? VARIANT_TRUE : VARIANT_FALSE;
1048 return stack_push(ctx, &v);
1051 static HRESULT interp_lt(exec_ctx_t *ctx)
1058 hres = cmp_oper(ctx);
1063 V_BOOL(&v) = hres == VARCMP_LT ? VARIANT_TRUE : VARIANT_FALSE;
1064 return stack_push(ctx, &v);
1067 static HRESULT interp_lteq(exec_ctx_t *ctx)
1074 hres = cmp_oper(ctx);
1079 V_BOOL(&v) = hres == VARCMP_LT || hres == VARCMP_EQ ? VARIANT_TRUE : VARIANT_FALSE;
1080 return stack_push(ctx, &v);
1083 static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, VARIANT_BOOL *ret)
1085 IObjectIdentity *identity;
1086 IUnknown *unk1, *unk2;
1089 if(disp1 == disp2) {
1090 *ret = VARIANT_TRUE;
1094 if(!disp1 || !disp2) {
1095 *ret = VARIANT_FALSE;
1099 hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
1103 hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
1105 IUnknown_Release(unk1);
1110 *ret = VARIANT_TRUE;
1112 hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
1113 if(SUCCEEDED(hres)) {
1114 hres = IObjectIdentity_IsEqualObject(identity, unk2);
1115 IObjectIdentity_Release(identity);
1116 *ret = hres == S_OK ? VARIANT_TRUE : VARIANT_FALSE;
1118 *ret = VARIANT_FALSE;
1122 IUnknown_Release(unk1);
1123 IUnknown_Release(unk2);
1127 static HRESULT interp_is(exec_ctx_t *ctx)
1135 hres = stack_pop_disp(ctx, &r);
1139 hres = stack_pop_disp(ctx, &l);
1140 if(SUCCEEDED(hres)) {
1142 hres = disp_cmp(l, r, &V_BOOL(&v));
1144 IDispatch_Release(l);
1147 IDispatch_Release(r);
1151 return stack_push(ctx, &v);
1154 static HRESULT interp_concat(exec_ctx_t *ctx)
1162 hres = stack_pop_val(ctx, &r);
1166 hres = stack_pop_val(ctx, &l);
1167 if(SUCCEEDED(hres)) {
1168 hres = VarCat(l.v, r.v, &v);
1175 return stack_push(ctx, &v);
1178 static HRESULT interp_add(exec_ctx_t *ctx)
1186 hres = stack_pop_val(ctx, &r);
1190 hres = stack_pop_val(ctx, &l);
1191 if(SUCCEEDED(hres)) {
1192 hres = VarAdd(l.v, r.v, &v);
1199 return stack_push(ctx, &v);
1202 static HRESULT interp_sub(exec_ctx_t *ctx)
1210 hres = stack_pop_val(ctx, &r);
1214 hres = stack_pop_val(ctx, &l);
1215 if(SUCCEEDED(hres)) {
1216 hres = VarSub(l.v, r.v, &v);
1223 return stack_push(ctx, &v);
1226 static HRESULT interp_mod(exec_ctx_t *ctx)
1234 hres = stack_pop_val(ctx, &r);
1238 hres = stack_pop_val(ctx, &l);
1239 if(SUCCEEDED(hres)) {
1240 hres = VarMod(l.v, r.v, &v);
1247 return stack_push(ctx, &v);
1250 static HRESULT interp_idiv(exec_ctx_t *ctx)
1258 hres = stack_pop_val(ctx, &r);
1262 hres = stack_pop_val(ctx, &l);
1263 if(SUCCEEDED(hres)) {
1264 hres = VarIdiv(l.v, r.v, &v);
1271 return stack_push(ctx, &v);
1274 static HRESULT interp_div(exec_ctx_t *ctx)
1282 hres = stack_pop_val(ctx, &r);
1286 hres = stack_pop_val(ctx, &l);
1287 if(SUCCEEDED(hres)) {
1288 hres = VarDiv(l.v, r.v, &v);
1295 return stack_push(ctx, &v);
1298 static HRESULT interp_mul(exec_ctx_t *ctx)
1306 hres = stack_pop_val(ctx, &r);
1310 hres = stack_pop_val(ctx, &l);
1311 if(SUCCEEDED(hres)) {
1312 hres = VarMul(l.v, r.v, &v);
1319 return stack_push(ctx, &v);
1322 static HRESULT interp_exp(exec_ctx_t *ctx)
1330 hres = stack_pop_val(ctx, &r);
1334 hres = stack_pop_val(ctx, &l);
1335 if(SUCCEEDED(hres)) {
1336 hres = VarPow(l.v, r.v, &v);
1343 return stack_push(ctx, &v);
1346 static HRESULT interp_neg(exec_ctx_t *ctx)
1352 hres = stack_pop_val(ctx, &val);
1356 hres = VarNeg(val.v, &v);
1361 return stack_push(ctx, &v);
1364 static const instr_func_t op_funcs[] = {
1365 #define X(x,n,a,b) interp_ ## x,
1370 static const unsigned op_move[] = {
1371 #define X(x,n,a,b) n,
1376 static void release_exec(exec_ctx_t *ctx)
1380 VariantClear(&ctx->ret_val);
1383 IDispatch_Release(ctx->this_obj);
1386 for(i=0; i < ctx->func->arg_cnt; i++)
1387 VariantClear(ctx->args+i);
1391 for(i=0; i < ctx->func->var_cnt; i++)
1392 VariantClear(ctx->vars+i);
1395 heap_free(ctx->args);
1396 heap_free(ctx->vars);
1397 heap_free(ctx->stack);
1400 HRESULT exec_script(script_ctx_t *ctx, function_t *func, IDispatch *this_obj, DISPPARAMS *dp, VARIANT *res)
1402 exec_ctx_t exec = {func->code_ctx};
1404 HRESULT hres = S_OK;
1406 exec.code = func->code_ctx;
1408 if(dp ? func->arg_cnt != arg_cnt(dp) : func->arg_cnt) {
1409 FIXME("wrong arg_cnt %d, expected %d\n", dp ? arg_cnt(dp) : 0, func->arg_cnt);
1417 exec.args = heap_alloc_zero(func->arg_cnt * sizeof(VARIANT));
1419 release_exec(&exec);
1420 return E_OUTOFMEMORY;
1423 for(i=0; i < func->arg_cnt; i++) {
1425 if(V_VT(v) == (VT_VARIANT|VT_BYREF)) {
1426 if(func->args[i].by_ref)
1429 hres = VariantCopy(exec.args+i, V_VARIANTREF(v));
1431 hres = VariantCopy(exec.args+i, v);
1434 release_exec(&exec);
1443 exec.vars = heap_alloc_zero(func->var_cnt * sizeof(VARIANT));
1445 release_exec(&exec);
1446 return E_OUTOFMEMORY;
1452 exec.stack_size = 16;
1454 exec.stack = heap_alloc(exec.stack_size * sizeof(VARIANT));
1456 release_exec(&exec);
1457 return E_OUTOFMEMORY;
1461 exec.this_obj = this_obj;
1462 else if (ctx->host_global)
1463 exec.this_obj = ctx->host_global;
1465 exec.this_obj = (IDispatch*)&ctx->script_obj->IDispatchEx_iface;
1466 IDispatch_AddRef(exec.this_obj);
1468 exec.instr = exec.code->instrs + func->code_off;
1473 op = exec.instr->op;
1474 hres = op_funcs[op](&exec);
1476 FIXME("Failed %08x\n", hres);
1477 stack_popn(&exec, exec.top);
1481 exec.instr += op_move[op];
1485 if(func->type != FUNC_FUNCTION && func->type != FUNC_PROPGET && func->type != FUNC_DEFGET)
1486 assert(V_VT(&exec.ret_val) == VT_EMPTY);
1488 if(SUCCEEDED(hres) && res) {
1489 *res = exec.ret_val;
1490 V_VT(&exec.ret_val) = VT_EMPTY;
1493 release_exec(&exec);