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
);
27 static DISPID propput_dispid
= DISPID_PROPERTYPUT
;
41 dynamic_var_t
*dynamic_vars
;
53 typedef HRESULT (*instr_func_t
)(exec_ctx_t
*);
83 static BOOL
lookup_dynamic_vars(dynamic_var_t
*var
, const WCHAR
*name
, ref_t
*ref
)
86 if(!wcsicmp(var
->name
, name
)) {
87 ref
->type
= var
->is_const
? REF_CONST
: REF_VAR
;
98 static HRESULT
lookup_identifier(exec_ctx_t
*ctx
, BSTR name
, vbdisp_invoke_type_t invoke_type
, ref_t
*ref
)
107 if(invoke_type
== VBDISP_LET
108 && (ctx
->func
->type
== FUNC_FUNCTION
|| ctx
->func
->type
== FUNC_PROPGET
|| ctx
->func
->type
== FUNC_DEFGET
)
109 && !wcsicmp(name
, ctx
->func
->name
)) {
111 ref
->u
.v
= &ctx
->ret_val
;
115 for(i
=0; i
< ctx
->func
->var_cnt
; i
++) {
116 if(!wcsicmp(ctx
->func
->vars
[i
].name
, name
)) {
118 ref
->u
.v
= ctx
->vars
+i
;
123 for(i
=0; i
< ctx
->func
->arg_cnt
; i
++) {
124 if(!wcsicmp(ctx
->func
->args
[i
].name
, name
)) {
126 ref
->u
.v
= ctx
->args
+i
;
131 if(lookup_dynamic_vars(ctx
->func
->type
== FUNC_GLOBAL
? ctx
->script
->global_vars
: ctx
->dynamic_vars
, name
, ref
))
134 if(ctx
->func
->type
!= FUNC_GLOBAL
) {
136 /* FIXME: Bind such identifier while generating bytecode. */
137 for(i
=0; i
< ctx
->vbthis
->desc
->prop_cnt
; i
++) {
138 if(!wcsicmp(ctx
->vbthis
->desc
->props
[i
].name
, name
)) {
140 ref
->u
.v
= ctx
->vbthis
->props
+i
;
146 hres
= disp_get_id(ctx
->this_obj
, name
, invoke_type
, TRUE
, &id
);
147 if(SUCCEEDED(hres
)) {
148 ref
->type
= REF_DISP
;
149 ref
->u
.d
.disp
= ctx
->this_obj
;
155 if(ctx
->func
->code_ctx
->context
) {
156 hres
= disp_get_id(ctx
->func
->code_ctx
->context
, name
, invoke_type
, TRUE
, &id
);
157 if(SUCCEEDED(hres
)) {
158 ref
->type
= REF_DISP
;
159 ref
->u
.d
.disp
= ctx
->func
->code_ctx
->context
;
165 if(ctx
->func
->type
!= FUNC_GLOBAL
&& lookup_dynamic_vars(ctx
->script
->global_vars
, name
, ref
))
168 for(func
= ctx
->script
->global_funcs
; func
; func
= func
->next
) {
169 if(!wcsicmp(func
->name
, name
)) {
170 ref
->type
= REF_FUNC
;
176 hres
= get_builtin_id(ctx
->script
->global_obj
, name
, &id
);
177 if(SUCCEEDED(hres
)) {
178 ref
->type
= REF_DISP
;
179 ref
->u
.d
.disp
= &ctx
->script
->global_obj
->IDispatch_iface
;
184 disp
= lookup_named_item(ctx
->script
, name
, SCRIPTITEM_ISVISIBLE
);
191 LIST_FOR_EACH_ENTRY(item
, &ctx
->script
->named_items
, named_item_t
, entry
) {
192 if((item
->flags
& SCRIPTITEM_GLOBALMEMBERS
)) {
193 hres
= disp_get_id(item
->disp
, name
, invoke_type
, FALSE
, &id
);
194 if(SUCCEEDED(hres
)) {
195 ref
->type
= REF_DISP
;
196 ref
->u
.d
.disp
= item
->disp
;
203 ref
->type
= REF_NONE
;
207 static HRESULT
add_dynamic_var(exec_ctx_t
*ctx
, const WCHAR
*name
,
208 BOOL is_const
, VARIANT
**out_var
)
210 dynamic_var_t
*new_var
;
215 heap
= ctx
->func
->type
== FUNC_GLOBAL
? &ctx
->script
->heap
: &ctx
->heap
;
217 new_var
= heap_pool_alloc(heap
, sizeof(*new_var
));
219 return E_OUTOFMEMORY
;
221 size
= (lstrlenW(name
)+1)*sizeof(WCHAR
);
222 str
= heap_pool_alloc(heap
, size
);
224 return E_OUTOFMEMORY
;
225 memcpy(str
, name
, size
);
227 new_var
->is_const
= is_const
;
228 V_VT(&new_var
->v
) = VT_EMPTY
;
230 if(ctx
->func
->type
== FUNC_GLOBAL
) {
231 new_var
->next
= ctx
->script
->global_vars
;
232 ctx
->script
->global_vars
= new_var
;
234 new_var
->next
= ctx
->dynamic_vars
;
235 ctx
->dynamic_vars
= new_var
;
238 *out_var
= &new_var
->v
;
242 void clear_ei(EXCEPINFO
*ei
)
244 SysFreeString(ei
->bstrSource
);
245 SysFreeString(ei
->bstrDescription
);
246 SysFreeString(ei
->bstrHelpFile
);
247 memset(ei
, 0, sizeof(*ei
));
250 static inline VARIANT
*stack_pop(exec_ctx_t
*ctx
)
253 return ctx
->stack
+ --ctx
->top
;
256 static inline VARIANT
*stack_top(exec_ctx_t
*ctx
, unsigned n
)
258 assert(ctx
->top
>= n
);
259 return ctx
->stack
+ (ctx
->top
-n
-1);
262 static HRESULT
stack_push(exec_ctx_t
*ctx
, VARIANT
*v
)
264 if(ctx
->stack_size
== ctx
->top
) {
267 new_stack
= heap_realloc(ctx
->stack
, ctx
->stack_size
*2*sizeof(*ctx
->stack
));
270 return E_OUTOFMEMORY
;
273 ctx
->stack
= new_stack
;
274 ctx
->stack_size
*= 2;
277 ctx
->stack
[ctx
->top
++] = *v
;
281 static inline HRESULT
stack_push_null(exec_ctx_t
*ctx
)
285 return stack_push(ctx
, &v
);
288 static void stack_popn(exec_ctx_t
*ctx
, unsigned n
)
291 VariantClear(stack_pop(ctx
));
294 static void stack_pop_deref(exec_ctx_t
*ctx
, variant_val_t
*r
)
299 if(V_VT(v
) == (VT_BYREF
|VT_VARIANT
)) {
301 r
->v
= V_VARIANTREF(v
);
308 static inline void release_val(variant_val_t
*v
)
314 static HRESULT
stack_pop_val(exec_ctx_t
*ctx
, variant_val_t
*r
)
316 stack_pop_deref(ctx
, r
);
318 if(V_VT(r
->v
) == VT_DISPATCH
) {
321 hres
= get_disp_value(ctx
->script
, V_DISPATCH(r
->v
), &r
->store
);
322 if(r
->owned
&& V_DISPATCH(r
->v
))
323 IDispatch_Release(V_DISPATCH(r
->v
));
334 static HRESULT
stack_assume_val(exec_ctx_t
*ctx
, unsigned n
)
336 VARIANT
*v
= stack_top(ctx
, n
);
339 if(V_VT(v
) == (VT_BYREF
|VT_VARIANT
)) {
340 VARIANT
*ref
= V_VARIANTREF(v
);
343 hres
= VariantCopy(v
, ref
);
348 if(V_VT(v
) == VT_DISPATCH
) {
351 disp
= V_DISPATCH(v
);
352 hres
= get_disp_value(ctx
->script
, disp
, v
);
354 IDispatch_Release(disp
);
362 static int stack_pop_bool(exec_ctx_t
*ctx
, BOOL
*b
)
367 hres
= stack_pop_val(ctx
, &val
);
386 FIXME("unsupported for %s\n", debugstr_variant(val
.v
));
393 static HRESULT
stack_pop_disp(exec_ctx_t
*ctx
, IDispatch
**ret
)
395 VARIANT
*v
= stack_pop(ctx
);
397 if(V_VT(v
) == VT_DISPATCH
) {
398 *ret
= V_DISPATCH(v
);
402 if(V_VT(v
) != (VT_VARIANT
|VT_BYREF
)) {
403 FIXME("not supported type: %s\n", debugstr_variant(v
));
409 if(V_VT(v
) != VT_DISPATCH
) {
410 FIXME("not disp %s\n", debugstr_variant(v
));
415 IDispatch_AddRef(V_DISPATCH(v
));
416 *ret
= V_DISPATCH(v
);
420 static HRESULT
stack_assume_disp(exec_ctx_t
*ctx
, unsigned n
, IDispatch
**disp
)
422 VARIANT
*v
= stack_top(ctx
, n
), *ref
;
424 if(V_VT(v
) != VT_DISPATCH
) {
425 if(V_VT(v
) != (VT_VARIANT
|VT_BYREF
)) {
426 FIXME("not supported type: %s\n", debugstr_variant(v
));
430 ref
= V_VARIANTREF(v
);
431 if(V_VT(ref
) != VT_DISPATCH
) {
432 FIXME("not disp %s\n", debugstr_variant(ref
));
436 V_VT(v
) = VT_DISPATCH
;
437 V_DISPATCH(v
) = V_DISPATCH(ref
);
439 IDispatch_AddRef(V_DISPATCH(v
));
443 *disp
= V_DISPATCH(v
);
447 static inline void instr_jmp(exec_ctx_t
*ctx
, unsigned addr
)
449 ctx
->instr
= ctx
->code
->instrs
+ addr
;
452 static void vbstack_to_dp(exec_ctx_t
*ctx
, unsigned arg_cnt
, BOOL is_propput
, DISPPARAMS
*dp
)
454 dp
->cNamedArgs
= is_propput
? 1 : 0;
455 dp
->cArgs
= arg_cnt
+ dp
->cNamedArgs
;
456 dp
->rgdispidNamedArgs
= is_propput
? &propput_dispid
: NULL
;
462 assert(ctx
->top
>= arg_cnt
);
464 for(i
=1; i
*2 <= arg_cnt
; i
++) {
465 tmp
= ctx
->stack
[ctx
->top
-i
];
466 ctx
->stack
[ctx
->top
-i
] = ctx
->stack
[ctx
->top
-arg_cnt
+i
-1];
467 ctx
->stack
[ctx
->top
-arg_cnt
+i
-1] = tmp
;
470 dp
->rgvarg
= ctx
->stack
+ ctx
->top
-dp
->cArgs
;
472 dp
->rgvarg
= is_propput
? ctx
->stack
+ctx
->top
-1 : NULL
;
476 static HRESULT
array_access(exec_ctx_t
*ctx
, SAFEARRAY
*array
, DISPPARAMS
*dp
, VARIANT
**ret
)
478 unsigned i
, argc
= arg_cnt(dp
);
483 FIXME("NULL array\n");
487 hres
= SafeArrayLock(array
);
491 if(array
->cDims
!= argc
) {
492 FIXME("argc %d does not match cDims %d\n", dp
->cArgs
, array
->cDims
);
493 SafeArrayUnlock(array
);
497 indices
= heap_alloc(sizeof(*indices
) * argc
);
499 SafeArrayUnlock(array
);
500 return E_OUTOFMEMORY
;
503 for(i
=0; i
<argc
; i
++) {
504 hres
= to_int(get_arg(dp
, i
), indices
+i
);
507 SafeArrayUnlock(array
);
512 hres
= SafeArrayPtrOfIndex(array
, indices
, (void**)ret
);
513 SafeArrayUnlock(array
);
518 static HRESULT
do_icall(exec_ctx_t
*ctx
, VARIANT
*res
)
520 BSTR identifier
= ctx
->instr
->arg1
.bstr
;
521 const unsigned arg_cnt
= ctx
->instr
->arg2
.uint
;
526 hres
= lookup_identifier(ctx
, identifier
, VBDISP_CALLGET
, &ref
);
536 FIXME("REF_VAR no res\n");
540 v
= V_VT(ref
.u
.v
) == (VT_VARIANT
|VT_BYREF
) ? V_VARIANTREF(ref
.u
.v
) : ref
.u
.v
;
543 SAFEARRAY
*array
= NULL
;
546 case VT_ARRAY
|VT_BYREF
|VT_VARIANT
:
547 array
= *V_ARRAYREF(ref
.u
.v
);
549 case VT_ARRAY
|VT_VARIANT
:
550 array
= V_ARRAY(ref
.u
.v
);
553 vbstack_to_dp(ctx
, arg_cnt
, FALSE
, &dp
);
554 hres
= disp_call(ctx
->script
, V_DISPATCH(v
), DISPID_VALUE
, &dp
, res
);
559 FIXME("arguments not implemented\n");
566 vbstack_to_dp(ctx
, arg_cnt
, FALSE
, &dp
);
567 hres
= array_access(ctx
, array
, &dp
, &v
);
572 V_VT(res
) = VT_BYREF
|VT_VARIANT
;
577 vbstack_to_dp(ctx
, arg_cnt
, FALSE
, &dp
);
578 hres
= disp_call(ctx
->script
, ref
.u
.d
.disp
, ref
.u
.d
.id
, &dp
, res
);
583 vbstack_to_dp(ctx
, arg_cnt
, FALSE
, &dp
);
584 hres
= exec_script(ctx
->script
, FALSE
, ref
.u
.f
, NULL
, &dp
, res
);
590 FIXME("arguments on object\n");
595 IDispatch_AddRef(ref
.u
.obj
);
596 V_VT(res
) = VT_DISPATCH
;
597 V_DISPATCH(res
) = ref
.u
.obj
;
601 if(res
&& !ctx
->func
->code_ctx
->option_explicit
&& arg_cnt
== 0) {
603 hres
= add_dynamic_var(ctx
, identifier
, FALSE
, &new);
606 V_VT(res
) = VT_BYREF
|VT_VARIANT
;
610 FIXME("%s not found\n", debugstr_w(identifier
));
611 return DISP_E_UNKNOWNNAME
;
614 stack_popn(ctx
, arg_cnt
);
618 static HRESULT
interp_icall(exec_ctx_t
*ctx
)
625 hres
= do_icall(ctx
, &v
);
629 return stack_push(ctx
, &v
);
632 static HRESULT
interp_icallv(exec_ctx_t
*ctx
)
635 return do_icall(ctx
, NULL
);
638 static HRESULT
do_mcall(exec_ctx_t
*ctx
, VARIANT
*res
)
640 const BSTR identifier
= ctx
->instr
->arg1
.bstr
;
641 const unsigned arg_cnt
= ctx
->instr
->arg2
.uint
;
647 hres
= stack_pop_disp(ctx
, &obj
);
656 vbstack_to_dp(ctx
, arg_cnt
, FALSE
, &dp
);
658 hres
= disp_get_id(obj
, identifier
, VBDISP_CALLGET
, FALSE
, &id
);
660 hres
= disp_call(ctx
->script
, obj
, id
, &dp
, res
);
661 IDispatch_Release(obj
);
665 stack_popn(ctx
, arg_cnt
);
669 static HRESULT
interp_mcall(exec_ctx_t
*ctx
)
676 hres
= do_mcall(ctx
, &res
);
680 return stack_push(ctx
, &res
);
683 static HRESULT
interp_mcallv(exec_ctx_t
*ctx
)
687 return do_mcall(ctx
, NULL
);
690 static HRESULT
assign_value(exec_ctx_t
*ctx
, VARIANT
*dst
, VARIANT
*src
, WORD flags
)
695 V_VT(&value
) = VT_EMPTY
;
696 hres
= VariantCopyInd(&value
, src
);
700 if(V_VT(&value
) == VT_DISPATCH
&& !(flags
& DISPATCH_PROPERTYPUTREF
)) {
701 IDispatch
*disp
= V_DISPATCH(&value
);
703 V_VT(&value
) = VT_EMPTY
;
704 hres
= get_disp_value(ctx
->script
, disp
, &value
);
706 IDispatch_Release(disp
);
716 static HRESULT
assign_ident(exec_ctx_t
*ctx
, BSTR name
, WORD flags
, DISPPARAMS
*dp
)
721 hres
= lookup_identifier(ctx
, name
, VBDISP_LET
, &ref
);
727 VARIANT
*v
= ref
.u
.v
;
729 if(V_VT(v
) == (VT_VARIANT
|VT_BYREF
))
735 if(!(V_VT(v
) & VT_ARRAY
)) {
736 FIXME("array assign on type %d\n", V_VT(v
));
741 case VT_ARRAY
|VT_BYREF
|VT_VARIANT
:
742 array
= *V_ARRAYREF(v
);
744 case VT_ARRAY
|VT_VARIANT
:
748 FIXME("Unsupported array type %x\n", V_VT(v
));
753 FIXME("null array\n");
757 hres
= array_access(ctx
, array
, dp
, &v
);
760 }else if(V_VT(v
) == (VT_ARRAY
|VT_BYREF
|VT_VARIANT
)) {
761 FIXME("non-array assign\n");
765 hres
= assign_value(ctx
, v
, dp
->rgvarg
, flags
);
769 hres
= disp_propput(ctx
->script
, ref
.u
.d
.disp
, ref
.u
.d
.id
, flags
, dp
);
772 FIXME("functions not implemented\n");
778 FIXME("REF_CONST\n");
781 if(ctx
->func
->code_ctx
->option_explicit
) {
782 FIXME("throw exception\n");
788 FIXME("arg_cnt %d not supported\n", arg_cnt(dp
));
792 TRACE("creating variable %s\n", debugstr_w(name
));
793 hres
= add_dynamic_var(ctx
, name
, FALSE
, &new_var
);
795 hres
= assign_value(ctx
, new_var
, dp
->rgvarg
, flags
);
802 static HRESULT
interp_assign_ident(exec_ctx_t
*ctx
)
804 const BSTR arg
= ctx
->instr
->arg1
.bstr
;
805 const unsigned arg_cnt
= ctx
->instr
->arg2
.uint
;
809 TRACE("%s\n", debugstr_w(arg
));
811 vbstack_to_dp(ctx
, arg_cnt
, TRUE
, &dp
);
812 hres
= assign_ident(ctx
, arg
, DISPATCH_PROPERTYPUT
, &dp
);
816 stack_popn(ctx
, arg_cnt
+1);
820 static HRESULT
interp_set_ident(exec_ctx_t
*ctx
)
822 const BSTR arg
= ctx
->instr
->arg1
.bstr
;
823 const unsigned arg_cnt
= ctx
->instr
->arg2
.uint
;
827 TRACE("%s\n", debugstr_w(arg
));
830 FIXME("arguments not supported\n");
834 hres
= stack_assume_disp(ctx
, 0, NULL
);
838 vbstack_to_dp(ctx
, 0, TRUE
, &dp
);
839 hres
= assign_ident(ctx
, ctx
->instr
->arg1
.bstr
, DISPATCH_PROPERTYPUTREF
, &dp
);
847 static HRESULT
interp_assign_member(exec_ctx_t
*ctx
)
849 BSTR identifier
= ctx
->instr
->arg1
.bstr
;
850 const unsigned arg_cnt
= ctx
->instr
->arg2
.uint
;
856 TRACE("%s\n", debugstr_w(identifier
));
858 hres
= stack_assume_disp(ctx
, arg_cnt
+1, &obj
);
867 hres
= disp_get_id(obj
, identifier
, VBDISP_LET
, FALSE
, &id
);
868 if(SUCCEEDED(hres
)) {
869 vbstack_to_dp(ctx
, arg_cnt
, TRUE
, &dp
);
870 hres
= disp_propput(ctx
->script
, obj
, id
, DISPATCH_PROPERTYPUT
, &dp
);
875 stack_popn(ctx
, arg_cnt
+2);
879 static HRESULT
interp_set_member(exec_ctx_t
*ctx
)
881 BSTR identifier
= ctx
->instr
->arg1
.bstr
;
882 const unsigned arg_cnt
= ctx
->instr
->arg2
.uint
;
888 TRACE("%s\n", debugstr_w(identifier
));
891 FIXME("arguments not supported\n");
895 hres
= stack_assume_disp(ctx
, 1, &obj
);
904 hres
= stack_assume_disp(ctx
, 0, NULL
);
908 hres
= disp_get_id(obj
, identifier
, VBDISP_SET
, FALSE
, &id
);
909 if(SUCCEEDED(hres
)) {
910 vbstack_to_dp(ctx
, arg_cnt
, TRUE
, &dp
);
911 hres
= disp_propput(ctx
->script
, obj
, id
, DISPATCH_PROPERTYPUTREF
, &dp
);
920 static HRESULT
interp_const(exec_ctx_t
*ctx
)
922 BSTR arg
= ctx
->instr
->arg1
.bstr
;
927 TRACE("%s\n", debugstr_w(arg
));
929 assert(ctx
->func
->type
== FUNC_GLOBAL
);
931 hres
= lookup_identifier(ctx
, arg
, VBDISP_CALLGET
, &ref
);
935 if(ref
.type
!= REF_NONE
) {
936 FIXME("%s already defined\n", debugstr_w(arg
));
940 hres
= stack_assume_val(ctx
, 0);
944 hres
= add_dynamic_var(ctx
, arg
, TRUE
, &v
);
948 *v
= *stack_pop(ctx
);
952 static HRESULT
interp_val(exec_ctx_t
*ctx
)
960 hres
= stack_pop_val(ctx
, &val
);
966 hres
= VariantCopy(&v
, val
.v
);
971 return stack_push(ctx
, val
.owned
? val
.v
: &v
);
974 static HRESULT
interp_pop(exec_ctx_t
*ctx
)
976 const unsigned n
= ctx
->instr
->arg1
.uint
;
984 static HRESULT
interp_new(exec_ctx_t
*ctx
)
986 const WCHAR
*arg
= ctx
->instr
->arg1
.bstr
;
987 class_desc_t
*class_desc
;
992 static const WCHAR regexpW
[] = {'r','e','g','e','x','p',0};
994 TRACE("%s\n", debugstr_w(arg
));
996 if(!wcsicmp(arg
, regexpW
)) {
997 V_VT(&v
) = VT_DISPATCH
;
998 hres
= create_regexp(&V_DISPATCH(&v
));
1002 return stack_push(ctx
, &v
);
1005 for(class_desc
= ctx
->script
->classes
; class_desc
; class_desc
= class_desc
->next
) {
1006 if(!wcsicmp(class_desc
->name
, arg
))
1010 FIXME("Class %s not found\n", debugstr_w(arg
));
1014 hres
= create_vbdisp(class_desc
, &obj
);
1018 V_VT(&v
) = VT_DISPATCH
;
1019 V_DISPATCH(&v
) = (IDispatch
*)&obj
->IDispatchEx_iface
;
1020 return stack_push(ctx
, &v
);
1023 static HRESULT
interp_dim(exec_ctx_t
*ctx
)
1025 const BSTR ident
= ctx
->instr
->arg1
.bstr
;
1026 const unsigned array_id
= ctx
->instr
->arg2
.uint
;
1027 const array_desc_t
*array_desc
;
1031 TRACE("%s\n", debugstr_w(ident
));
1033 assert(array_id
< ctx
->func
->array_cnt
);
1035 ctx
->arrays
= heap_alloc_zero(ctx
->func
->array_cnt
* sizeof(SAFEARRAY
*));
1037 return E_OUTOFMEMORY
;
1040 hres
= lookup_identifier(ctx
, ident
, VBDISP_LET
, &ref
);
1042 FIXME("lookup %s failed: %08x\n", debugstr_w(ident
), hres
);
1046 if(ref
.type
!= REF_VAR
) {
1047 FIXME("got ref.type = %d\n", ref
.type
);
1051 if(ctx
->arrays
[array_id
]) {
1052 FIXME("Array already initialized\n");
1056 array_desc
= ctx
->func
->array_descs
+ array_id
;
1057 if(array_desc
->dim_cnt
) {
1058 ctx
->arrays
[array_id
] = SafeArrayCreate(VT_VARIANT
, array_desc
->dim_cnt
, array_desc
->bounds
);
1059 if(!ctx
->arrays
[array_id
])
1060 return E_OUTOFMEMORY
;
1063 V_VT(ref
.u
.v
) = VT_ARRAY
|VT_BYREF
|VT_VARIANT
;
1064 V_ARRAYREF(ref
.u
.v
) = ctx
->arrays
+array_id
;
1068 static HRESULT
interp_step(exec_ctx_t
*ctx
)
1070 const BSTR ident
= ctx
->instr
->arg2
.bstr
;
1076 TRACE("%s\n", debugstr_w(ident
));
1078 V_VT(&zero
) = VT_I2
;
1080 hres
= VarCmp(stack_top(ctx
, 0), &zero
, ctx
->script
->lcid
, 0);
1084 gteq_zero
= hres
== VARCMP_GT
|| hres
== VARCMP_EQ
;
1086 hres
= lookup_identifier(ctx
, ident
, VBDISP_ANY
, &ref
);
1090 if(ref
.type
!= REF_VAR
) {
1091 FIXME("%s is not REF_VAR\n", debugstr_w(ident
));
1095 hres
= VarCmp(ref
.u
.v
, stack_top(ctx
, 1), ctx
->script
->lcid
, 0);
1099 if(hres
== VARCMP_EQ
|| hres
== (gteq_zero
? VARCMP_LT
: VARCMP_GT
)) {
1103 instr_jmp(ctx
, ctx
->instr
->arg1
.uint
);
1108 static HRESULT
interp_newenum(exec_ctx_t
*ctx
)
1116 stack_pop_deref(ctx
, &v
);
1117 assert(V_VT(stack_top(ctx
, 0)) == VT_EMPTY
);
1118 r
= stack_top(ctx
, 0);
1121 case VT_DISPATCH
|VT_BYREF
:
1124 DISPPARAMS dp
= {0};
1127 hres
= disp_call(ctx
->script
, V_ISBYREF(v
.v
) ? *V_DISPATCHREF(v
.v
) : V_DISPATCH(v
.v
), DISPID_NEWENUM
, &dp
, &iterv
);
1132 if(V_VT(&iterv
) != VT_UNKNOWN
&& V_VT(&iterv
) != VT_DISPATCH
) {
1133 FIXME("Unsupported iterv %s\n", debugstr_variant(&iterv
));
1134 VariantClear(&iterv
);
1138 hres
= IUnknown_QueryInterface(V_UNKNOWN(&iterv
), &IID_IEnumVARIANT
, (void**)&iter
);
1139 IUnknown_Release(V_UNKNOWN(&iterv
));
1141 FIXME("Could not get IEnumVARIANT iface: %08x\n", hres
);
1145 V_VT(r
) = VT_UNKNOWN
;
1146 V_UNKNOWN(r
) = (IUnknown
*)iter
;
1149 case VT_VARIANT
|VT_ARRAY
:
1150 case VT_VARIANT
|VT_ARRAY
|VT_BYREF
: {
1153 hres
= create_safearray_iter(V_ISBYREF(v
.v
) ? *V_ARRAYREF(v
.v
) : V_ARRAY(v
.v
), &iter
);
1157 V_VT(r
) = VT_UNKNOWN
;
1158 V_UNKNOWN(r
) = (IUnknown
*)iter
;
1162 FIXME("Unsupported for %s\n", debugstr_variant(v
.v
));
1170 static HRESULT
interp_enumnext(exec_ctx_t
*ctx
)
1172 const unsigned loop_end
= ctx
->instr
->arg1
.uint
;
1173 const BSTR ident
= ctx
->instr
->arg2
.bstr
;
1175 DISPPARAMS dp
= {&v
, &propput_dispid
, 1, 1};
1182 if(V_VT(stack_top(ctx
, 0)) == VT_EMPTY
) {
1183 FIXME("uninitialized\n");
1187 assert(V_VT(stack_top(ctx
, 0)) == VT_UNKNOWN
);
1188 iter
= (IEnumVARIANT
*)V_UNKNOWN(stack_top(ctx
, 0));
1190 V_VT(&v
) = VT_EMPTY
;
1191 hres
= IEnumVARIANT_Next(iter
, 1, &v
, NULL
);
1195 do_continue
= hres
== S_OK
;
1196 hres
= assign_ident(ctx
, ident
, DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
, &dp
);
1205 instr_jmp(ctx
, loop_end
);
1210 static HRESULT
interp_jmp(exec_ctx_t
*ctx
)
1212 const unsigned arg
= ctx
->instr
->arg1
.uint
;
1216 instr_jmp(ctx
, arg
);
1220 static HRESULT
interp_jmp_false(exec_ctx_t
*ctx
)
1222 const unsigned arg
= ctx
->instr
->arg1
.uint
;
1228 hres
= stack_pop_bool(ctx
, &b
);
1235 instr_jmp(ctx
, ctx
->instr
->arg1
.uint
);
1239 static HRESULT
interp_jmp_true(exec_ctx_t
*ctx
)
1241 const unsigned arg
= ctx
->instr
->arg1
.uint
;
1247 hres
= stack_pop_bool(ctx
, &b
);
1252 instr_jmp(ctx
, ctx
->instr
->arg1
.uint
);
1258 static HRESULT
interp_ret(exec_ctx_t
*ctx
)
1266 static HRESULT
interp_retval(exec_ctx_t
*ctx
)
1273 hres
= stack_pop_val(ctx
, &val
);
1278 VariantClear(&ctx
->ret_val
);
1279 ctx
->ret_val
= *val
.v
;
1282 hres
= VariantCopy(&ctx
->ret_val
, val
.v
);
1290 static HRESULT
interp_stop(exec_ctx_t
*ctx
)
1294 /* NOTE: this should have effect in debugging mode (that we don't support yet) */
1298 static HRESULT
interp_me(exec_ctx_t
*ctx
)
1304 IDispatch_AddRef(ctx
->this_obj
);
1305 V_VT(&v
) = VT_DISPATCH
;
1306 V_DISPATCH(&v
) = ctx
->this_obj
;
1307 return stack_push(ctx
, &v
);
1310 static HRESULT
interp_bool(exec_ctx_t
*ctx
)
1312 const VARIANT_BOOL arg
= ctx
->instr
->arg1
.lng
;
1315 TRACE("%s\n", arg
? "true" : "false");
1319 return stack_push(ctx
, &v
);
1322 static HRESULT
interp_errmode(exec_ctx_t
*ctx
)
1324 const int err_mode
= ctx
->instr
->arg1
.uint
;
1326 TRACE("%d\n", err_mode
);
1328 ctx
->resume_next
= err_mode
;
1329 clear_ei(&ctx
->script
->ei
);
1333 static HRESULT
interp_string(exec_ctx_t
*ctx
)
1340 V_BSTR(&v
) = SysAllocString(ctx
->instr
->arg1
.str
);
1342 return E_OUTOFMEMORY
;
1344 return stack_push(ctx
, &v
);
1347 static HRESULT
interp_int(exec_ctx_t
*ctx
)
1349 const LONG arg
= ctx
->instr
->arg1
.lng
;
1354 if(arg
== (INT16
)arg
) {
1361 return stack_push(ctx
, &v
);
1364 static HRESULT
interp_double(exec_ctx_t
*ctx
)
1366 const DOUBLE
*arg
= ctx
->instr
->arg1
.dbl
;
1369 TRACE("%lf\n", *arg
);
1373 return stack_push(ctx
, &v
);
1376 static HRESULT
interp_empty(exec_ctx_t
*ctx
)
1382 V_VT(&v
) = VT_EMPTY
;
1383 return stack_push(ctx
, &v
);
1386 static HRESULT
interp_null(exec_ctx_t
*ctx
)
1389 return stack_push_null(ctx
);
1392 static HRESULT
interp_nothing(exec_ctx_t
*ctx
)
1398 V_VT(&v
) = VT_DISPATCH
;
1399 V_DISPATCH(&v
) = NULL
;
1400 return stack_push(ctx
, &v
);
1403 static HRESULT
interp_hres(exec_ctx_t
*ctx
)
1405 const unsigned arg
= ctx
->instr
->arg1
.uint
;
1410 V_VT(&v
) = VT_ERROR
;
1412 return stack_push(ctx
, &v
);
1415 static HRESULT
interp_not(exec_ctx_t
*ctx
)
1423 hres
= stack_pop_val(ctx
, &val
);
1427 hres
= VarNot(val
.v
, &v
);
1432 return stack_push(ctx
, &v
);
1435 static HRESULT
interp_and(exec_ctx_t
*ctx
)
1443 hres
= stack_pop_val(ctx
, &r
);
1447 hres
= stack_pop_val(ctx
, &l
);
1448 if(SUCCEEDED(hres
)) {
1449 hres
= VarAnd(l
.v
, r
.v
, &v
);
1456 return stack_push(ctx
, &v
);
1459 static HRESULT
interp_or(exec_ctx_t
*ctx
)
1467 hres
= stack_pop_val(ctx
, &r
);
1471 hres
= stack_pop_val(ctx
, &l
);
1472 if(SUCCEEDED(hres
)) {
1473 hres
= VarOr(l
.v
, r
.v
, &v
);
1480 return stack_push(ctx
, &v
);
1483 static HRESULT
interp_xor(exec_ctx_t
*ctx
)
1491 hres
= stack_pop_val(ctx
, &r
);
1495 hres
= stack_pop_val(ctx
, &l
);
1496 if(SUCCEEDED(hres
)) {
1497 hres
= VarXor(l
.v
, r
.v
, &v
);
1504 return stack_push(ctx
, &v
);
1507 static HRESULT
interp_eqv(exec_ctx_t
*ctx
)
1515 hres
= stack_pop_val(ctx
, &r
);
1519 hres
= stack_pop_val(ctx
, &l
);
1520 if(SUCCEEDED(hres
)) {
1521 hres
= VarEqv(l
.v
, r
.v
, &v
);
1528 return stack_push(ctx
, &v
);
1531 static HRESULT
interp_imp(exec_ctx_t
*ctx
)
1539 hres
= stack_pop_val(ctx
, &r
);
1543 hres
= stack_pop_val(ctx
, &l
);
1544 if(SUCCEEDED(hres
)) {
1545 hres
= VarImp(l
.v
, r
.v
, &v
);
1552 return stack_push(ctx
, &v
);
1555 static HRESULT
var_cmp(exec_ctx_t
*ctx
, VARIANT
*l
, VARIANT
*r
)
1557 TRACE("%s %s\n", debugstr_variant(l
), debugstr_variant(r
));
1559 /* FIXME: Fix comparing string to number */
1561 return VarCmp(l
, r
, ctx
->script
->lcid
, 0);
1564 static HRESULT
cmp_oper(exec_ctx_t
*ctx
)
1569 hres
= stack_pop_val(ctx
, &r
);
1573 hres
= stack_pop_val(ctx
, &l
);
1574 if(SUCCEEDED(hres
)) {
1575 hres
= var_cmp(ctx
, l
.v
, r
.v
);
1583 static HRESULT
interp_equal(exec_ctx_t
*ctx
)
1590 hres
= cmp_oper(ctx
);
1593 if(hres
== VARCMP_NULL
)
1594 return stack_push_null(ctx
);
1597 V_BOOL(&v
) = hres
== VARCMP_EQ
? VARIANT_TRUE
: VARIANT_FALSE
;
1598 return stack_push(ctx
, &v
);
1601 static HRESULT
interp_nequal(exec_ctx_t
*ctx
)
1608 hres
= cmp_oper(ctx
);
1611 if(hres
== VARCMP_NULL
)
1612 return stack_push_null(ctx
);
1615 V_BOOL(&v
) = hres
!= VARCMP_EQ
? VARIANT_TRUE
: VARIANT_FALSE
;
1616 return stack_push(ctx
, &v
);
1619 static HRESULT
interp_gt(exec_ctx_t
*ctx
)
1626 hres
= cmp_oper(ctx
);
1629 if(hres
== VARCMP_NULL
)
1630 return stack_push_null(ctx
);
1633 V_BOOL(&v
) = hres
== VARCMP_GT
? VARIANT_TRUE
: VARIANT_FALSE
;
1634 return stack_push(ctx
, &v
);
1637 static HRESULT
interp_gteq(exec_ctx_t
*ctx
)
1644 hres
= cmp_oper(ctx
);
1647 if(hres
== VARCMP_NULL
)
1648 return stack_push_null(ctx
);
1651 V_BOOL(&v
) = hres
== VARCMP_GT
|| hres
== VARCMP_EQ
? VARIANT_TRUE
: VARIANT_FALSE
;
1652 return stack_push(ctx
, &v
);
1655 static HRESULT
interp_lt(exec_ctx_t
*ctx
)
1662 hres
= cmp_oper(ctx
);
1665 if(hres
== VARCMP_NULL
)
1666 return stack_push_null(ctx
);
1669 V_BOOL(&v
) = hres
== VARCMP_LT
? VARIANT_TRUE
: VARIANT_FALSE
;
1670 return stack_push(ctx
, &v
);
1673 static HRESULT
interp_lteq(exec_ctx_t
*ctx
)
1680 hres
= cmp_oper(ctx
);
1683 if(hres
== VARCMP_NULL
)
1684 return stack_push_null(ctx
);
1687 V_BOOL(&v
) = hres
== VARCMP_LT
|| hres
== VARCMP_EQ
? VARIANT_TRUE
: VARIANT_FALSE
;
1688 return stack_push(ctx
, &v
);
1691 static HRESULT
interp_case(exec_ctx_t
*ctx
)
1693 const unsigned arg
= ctx
->instr
->arg1
.uint
;
1699 hres
= stack_pop_val(ctx
, &v
);
1703 hres
= var_cmp(ctx
, stack_top(ctx
, 0), v
.v
);
1708 if(hres
== VARCMP_EQ
) {
1710 instr_jmp(ctx
, arg
);
1718 static HRESULT
disp_cmp(IDispatch
*disp1
, IDispatch
*disp2
, VARIANT_BOOL
*ret
)
1720 IObjectIdentity
*identity
;
1721 IUnknown
*unk1
, *unk2
;
1724 if(disp1
== disp2
) {
1725 *ret
= VARIANT_TRUE
;
1729 if(!disp1
|| !disp2
) {
1730 *ret
= VARIANT_FALSE
;
1734 hres
= IDispatch_QueryInterface(disp1
, &IID_IUnknown
, (void**)&unk1
);
1738 hres
= IDispatch_QueryInterface(disp2
, &IID_IUnknown
, (void**)&unk2
);
1740 IUnknown_Release(unk1
);
1745 *ret
= VARIANT_TRUE
;
1747 hres
= IUnknown_QueryInterface(unk1
, &IID_IObjectIdentity
, (void**)&identity
);
1748 if(SUCCEEDED(hres
)) {
1749 hres
= IObjectIdentity_IsEqualObject(identity
, unk2
);
1750 IObjectIdentity_Release(identity
);
1751 *ret
= hres
== S_OK
? VARIANT_TRUE
: VARIANT_FALSE
;
1753 *ret
= VARIANT_FALSE
;
1757 IUnknown_Release(unk1
);
1758 IUnknown_Release(unk2
);
1762 static HRESULT
interp_is(exec_ctx_t
*ctx
)
1770 hres
= stack_pop_disp(ctx
, &r
);
1774 hres
= stack_pop_disp(ctx
, &l
);
1775 if(SUCCEEDED(hres
)) {
1777 hres
= disp_cmp(l
, r
, &V_BOOL(&v
));
1779 IDispatch_Release(l
);
1782 IDispatch_Release(r
);
1786 return stack_push(ctx
, &v
);
1789 static HRESULT
interp_concat(exec_ctx_t
*ctx
)
1797 hres
= stack_pop_val(ctx
, &r
);
1801 hres
= stack_pop_val(ctx
, &l
);
1802 if(SUCCEEDED(hres
)) {
1803 hres
= VarCat(l
.v
, r
.v
, &v
);
1810 return stack_push(ctx
, &v
);
1813 static HRESULT
interp_add(exec_ctx_t
*ctx
)
1821 hres
= stack_pop_val(ctx
, &r
);
1825 hres
= stack_pop_val(ctx
, &l
);
1826 if(SUCCEEDED(hres
)) {
1827 hres
= VarAdd(l
.v
, r
.v
, &v
);
1834 return stack_push(ctx
, &v
);
1837 static HRESULT
interp_sub(exec_ctx_t
*ctx
)
1845 hres
= stack_pop_val(ctx
, &r
);
1849 hres
= stack_pop_val(ctx
, &l
);
1850 if(SUCCEEDED(hres
)) {
1851 hres
= VarSub(l
.v
, r
.v
, &v
);
1858 return stack_push(ctx
, &v
);
1861 static HRESULT
interp_mod(exec_ctx_t
*ctx
)
1869 hres
= stack_pop_val(ctx
, &r
);
1873 hres
= stack_pop_val(ctx
, &l
);
1874 if(SUCCEEDED(hres
)) {
1875 hres
= VarMod(l
.v
, r
.v
, &v
);
1882 return stack_push(ctx
, &v
);
1885 static HRESULT
interp_idiv(exec_ctx_t
*ctx
)
1893 hres
= stack_pop_val(ctx
, &r
);
1897 hres
= stack_pop_val(ctx
, &l
);
1898 if(SUCCEEDED(hres
)) {
1899 hres
= VarIdiv(l
.v
, r
.v
, &v
);
1906 return stack_push(ctx
, &v
);
1909 static HRESULT
interp_div(exec_ctx_t
*ctx
)
1917 hres
= stack_pop_val(ctx
, &r
);
1921 hres
= stack_pop_val(ctx
, &l
);
1922 if(SUCCEEDED(hres
)) {
1923 hres
= VarDiv(l
.v
, r
.v
, &v
);
1930 return stack_push(ctx
, &v
);
1933 static HRESULT
interp_mul(exec_ctx_t
*ctx
)
1941 hres
= stack_pop_val(ctx
, &r
);
1945 hres
= stack_pop_val(ctx
, &l
);
1946 if(SUCCEEDED(hres
)) {
1947 hres
= VarMul(l
.v
, r
.v
, &v
);
1954 return stack_push(ctx
, &v
);
1957 static HRESULT
interp_exp(exec_ctx_t
*ctx
)
1965 hres
= stack_pop_val(ctx
, &r
);
1969 hres
= stack_pop_val(ctx
, &l
);
1970 if(SUCCEEDED(hres
)) {
1971 hres
= VarPow(l
.v
, r
.v
, &v
);
1978 return stack_push(ctx
, &v
);
1981 static HRESULT
interp_neg(exec_ctx_t
*ctx
)
1987 hres
= stack_pop_val(ctx
, &val
);
1991 hres
= VarNeg(val
.v
, &v
);
1996 return stack_push(ctx
, &v
);
1999 static HRESULT
interp_incc(exec_ctx_t
*ctx
)
2001 const BSTR ident
= ctx
->instr
->arg1
.bstr
;
2008 hres
= lookup_identifier(ctx
, ident
, VBDISP_LET
, &ref
);
2012 if(ref
.type
!= REF_VAR
) {
2013 FIXME("ref.type is not REF_VAR\n");
2017 hres
= VarAdd(stack_top(ctx
, 0), ref
.u
.v
, &v
);
2021 VariantClear(ref
.u
.v
);
2026 static HRESULT
interp_catch(exec_ctx_t
*ctx
)
2028 /* Nothing to do here, the OP is for unwinding only. */
2032 static const instr_func_t op_funcs
[] = {
2033 #define X(x,n,a,b) interp_ ## x,
2038 static const unsigned op_move
[] = {
2039 #define X(x,n,a,b) n,
2044 void release_dynamic_vars(dynamic_var_t
*var
)
2047 VariantClear(&var
->v
);
2052 static void release_exec(exec_ctx_t
*ctx
)
2056 VariantClear(&ctx
->ret_val
);
2057 release_dynamic_vars(ctx
->dynamic_vars
);
2060 IDispatch_Release(ctx
->this_obj
);
2063 for(i
=0; i
< ctx
->func
->arg_cnt
; i
++)
2064 VariantClear(ctx
->args
+i
);
2068 for(i
=0; i
< ctx
->func
->var_cnt
; i
++)
2069 VariantClear(ctx
->vars
+i
);
2073 for(i
=0; i
< ctx
->func
->var_cnt
; i
++) {
2075 SafeArrayDestroy(ctx
->arrays
[i
]);
2077 heap_free(ctx
->arrays
);
2080 heap_pool_free(&ctx
->heap
);
2081 heap_free(ctx
->args
);
2082 heap_free(ctx
->vars
);
2083 heap_free(ctx
->stack
);
2086 HRESULT
exec_script(script_ctx_t
*ctx
, BOOL extern_caller
, function_t
*func
, vbdisp_t
*vbthis
, DISPPARAMS
*dp
, VARIANT
*res
)
2088 exec_ctx_t exec
= {func
->code_ctx
};
2090 HRESULT hres
= S_OK
;
2092 exec
.code
= func
->code_ctx
;
2094 if(dp
? func
->arg_cnt
!= arg_cnt(dp
) : func
->arg_cnt
) {
2095 FIXME("wrong arg_cnt %d, expected %d\n", dp
? arg_cnt(dp
) : 0, func
->arg_cnt
);
2099 heap_pool_init(&exec
.heap
);
2105 exec
.args
= heap_alloc_zero(func
->arg_cnt
* sizeof(VARIANT
));
2107 release_exec(&exec
);
2108 return E_OUTOFMEMORY
;
2111 for(i
=0; i
< func
->arg_cnt
; i
++) {
2113 if(V_VT(v
) == (VT_VARIANT
|VT_BYREF
)) {
2114 if(func
->args
[i
].by_ref
)
2117 hres
= VariantCopyInd(exec
.args
+i
, V_VARIANTREF(v
));
2119 hres
= VariantCopyInd(exec
.args
+i
, v
);
2122 release_exec(&exec
);
2131 exec
.vars
= heap_alloc_zero(func
->var_cnt
* sizeof(VARIANT
));
2133 release_exec(&exec
);
2134 return E_OUTOFMEMORY
;
2140 exec
.stack_size
= 16;
2142 exec
.stack
= heap_alloc(exec
.stack_size
* sizeof(VARIANT
));
2144 release_exec(&exec
);
2145 return E_OUTOFMEMORY
;
2149 IActiveScriptSite_OnEnterScript(ctx
->site
);
2152 exec
.this_obj
= (IDispatch
*)&vbthis
->IDispatchEx_iface
;
2153 exec
.vbthis
= vbthis
;
2154 }else if (ctx
->host_global
) {
2155 exec
.this_obj
= ctx
->host_global
;
2157 exec
.this_obj
= (IDispatch
*)&ctx
->script_obj
->IDispatchEx_iface
;
2159 IDispatch_AddRef(exec
.this_obj
);
2161 exec
.instr
= exec
.code
->instrs
+ func
->code_off
;
2166 op
= exec
.instr
->op
;
2167 hres
= op_funcs
[op
](&exec
);
2169 if(hres
!= SCRIPT_E_RECORDED
) {
2172 ctx
->ei
.scode
= hres
= map_hres(hres
);
2173 ctx
->ei
.bstrSource
= get_vbscript_string(VBS_RUNTIME_ERROR
);
2174 ctx
->ei
.bstrDescription
= get_vbscript_error_string(hres
);
2176 hres
= ctx
->ei
.scode
;
2179 if(exec
.resume_next
) {
2182 WARN("Failed %08x in resume next mode\n", hres
);
2185 * Unwinding here is simple. We need to find the next OP_catch, which contains
2186 * information about expected stack size and jump offset on error. Generated
2187 * bytecode needs to guarantee, that simple jump and stack adjustment will
2188 * guarantee proper execution continuation.
2190 while((++exec
.instr
)->op
!= OP_catch
);
2192 TRACE("unwind jmp %d stack_off %d\n", exec
.instr
->arg1
.uint
, exec
.instr
->arg2
.uint
);
2194 stack_off
= exec
.instr
->arg2
.uint
;
2195 instr_jmp(&exec
, exec
.instr
->arg1
.uint
);
2197 if(exec
.top
> stack_off
) {
2198 stack_popn(&exec
, exec
.top
-stack_off
);
2199 }else if(exec
.top
< stack_off
) {
2202 V_VT(&v
) = VT_EMPTY
;
2203 while(exec
.top
< stack_off
) {
2204 hres
= stack_push(&exec
, &v
);
2212 WARN("Failed %08x\n", hres
);
2213 stack_popn(&exec
, exec
.top
);
2218 exec
.instr
+= op_move
[op
];
2224 IActiveScriptSite_OnLeaveScript(ctx
->site
);
2227 ctx
->ei
.scode
= hres
;
2228 hres
= report_script_error(ctx
);
2232 if(SUCCEEDED(hres
) && res
) {
2233 *res
= exec
.ret_val
;
2234 V_VT(&exec
.ret_val
) = VT_EMPTY
;
2237 release_exec(&exec
);