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
29 #include "vbscript_classes.h"
31 #include "wine/list.h"
32 #include "wine/unicode.h"
40 struct list custom_blocks
;
43 void heap_pool_init(heap_pool_t
*) DECLSPEC_HIDDEN
;
44 void *heap_pool_alloc(heap_pool_t
*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
;
45 void *heap_pool_grow(heap_pool_t
*,void*,DWORD
,DWORD
) DECLSPEC_HIDDEN
;
46 void heap_pool_clear(heap_pool_t
*) DECLSPEC_HIDDEN
;
47 void heap_pool_free(heap_pool_t
*) DECLSPEC_HIDDEN
;
48 heap_pool_t
*heap_pool_mark(heap_pool_t
*) DECLSPEC_HIDDEN
;
50 typedef struct _function_t function_t
;
51 typedef struct _vbscode_t vbscode_t
;
52 typedef struct _script_ctx_t script_ctx_t
;
53 typedef struct _vbdisp_t vbdisp_t
;
55 typedef struct named_item_t
{
68 } vbdisp_invoke_type_t
;
78 function_t
*entries
[VBDISP_ANY
];
79 } vbdisp_funcprop_desc_t
;
86 HRESULT (*proc
)(vbdisp_t
*,VARIANT
*,unsigned,VARIANT
*);
92 typedef struct _class_desc_t
{
96 unsigned class_initialize_id
;
97 unsigned class_terminate_id
;
99 vbdisp_funcprop_desc_t
*funcs
;
102 vbdisp_prop_desc_t
*props
;
104 unsigned builtin_prop_cnt
;
105 const builtin_prop_t
*builtin_props
;
107 function_t
*value_func
;
109 struct _class_desc_t
*next
;
113 IDispatchEx IDispatchEx_iface
;
119 const class_desc_t
*desc
;
123 typedef struct _ident_map_t ident_map_t
;
126 IDispatchEx IDispatchEx_iface
;
129 ident_map_t
*ident_map
;
130 unsigned ident_map_cnt
;
131 unsigned ident_map_size
;
136 HRESULT
create_vbdisp(const class_desc_t
*,vbdisp_t
**) DECLSPEC_HIDDEN
;
137 HRESULT
disp_get_id(IDispatch
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
138 HRESULT
vbdisp_get_id(vbdisp_t
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
139 HRESULT
disp_call(script_ctx_t
*,IDispatch
*,DISPID
,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
140 HRESULT
disp_propput(script_ctx_t
*,IDispatch
*,DISPID
,DISPPARAMS
*) DECLSPEC_HIDDEN
;
141 void collect_objects(script_ctx_t
*) DECLSPEC_HIDDEN
;
142 HRESULT
create_procedure_disp(script_ctx_t
*,vbscode_t
*,IDispatch
**) DECLSPEC_HIDDEN
;
143 HRESULT
create_script_disp(script_ctx_t
*,ScriptDisp
**) DECLSPEC_HIDDEN
;
145 static inline unsigned arg_cnt(const DISPPARAMS
*dp
)
147 return dp
->cArgs
- dp
->cNamedArgs
;
150 static inline VARIANT
*get_arg(DISPPARAMS
*dp
, DWORD i
)
152 return dp
->rgvarg
+ dp
->cArgs
-i
-1;
155 typedef struct _dynamic_var_t
{
156 struct _dynamic_var_t
*next
;
162 struct _script_ctx_t
{
163 IActiveScriptSite
*site
;
166 IInternetHostSecurityManager
*secmgr
;
169 IDispatch
*host_global
;
171 ScriptDisp
*script_obj
;
173 class_desc_t global_desc
;
174 vbdisp_t
*global_obj
;
176 class_desc_t err_desc
;
179 dynamic_var_t
*global_vars
;
180 function_t
*global_funcs
;
181 class_desc_t
*classes
;
187 struct list code_list
;
188 struct list named_items
;
191 HRESULT
init_global(script_ctx_t
*) DECLSPEC_HIDDEN
;
192 HRESULT
init_err(script_ctx_t
*) DECLSPEC_HIDDEN
;
194 IUnknown
*create_ax_site(script_ctx_t
*) DECLSPEC_HIDDEN
;
209 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
210 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
211 X(bool, 1, ARG_INT, 0) \
212 X(case, 0, ARG_ADDR, 0) \
214 X(const, 1, ARG_BSTR, 0) \
216 X(double, 1, ARG_DOUBLE, 0) \
218 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
220 X(errmode, 1, ARG_INT, 0) \
225 X(icall, 1, ARG_BSTR, ARG_UINT) \
226 X(icallv, 1, ARG_BSTR, ARG_UINT) \
229 X(incc, 1, ARG_BSTR, 0) \
231 X(jmp, 0, ARG_ADDR, 0) \
232 X(jmp_false, 0, ARG_ADDR, 0) \
233 X(jmp_true, 0, ARG_ADDR, 0) \
234 X(long, 1, ARG_INT, 0) \
237 X(mcall, 1, ARG_BSTR, ARG_UINT) \
238 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
244 X(new, 1, ARG_STR, 0) \
245 X(newenum, 1, 0, 0) \
247 X(nothing, 1, 0, 0) \
250 X(pop, 1, ARG_UINT, 0) \
252 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
253 X(set_member, 1, ARG_BSTR, ARG_UINT) \
254 X(short, 1, ARG_INT, 0) \
255 X(step, 0, ARG_ADDR, ARG_BSTR) \
257 X(string, 1, ARG_STR, 0) \
263 #define X(x,n,a,b) OP_##x,
303 function_type_t type
;
319 BOOL option_explicit
;
322 function_t main_code
;
325 unsigned bstr_pool_size
;
332 void release_vbscode(vbscode_t
*) DECLSPEC_HIDDEN
;
333 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,const WCHAR
*,vbscode_t
**) DECLSPEC_HIDDEN
;
334 HRESULT
exec_script(script_ctx_t
*,function_t
*,IDispatch
*,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
335 void release_dynamic_vars(dynamic_var_t
*) DECLSPEC_HIDDEN
;
347 #define XDIID(iface) iface ## _tid,
353 HRESULT
get_typeinfo(tid_t
,ITypeInfo
**) DECLSPEC_HIDDEN
;
354 void release_regexp_typelib(void) DECLSPEC_HIDDEN
;
357 #define INT32_MIN (-2147483647-1)
361 #define INT32_MAX (2147483647)
364 static inline BOOL
is_int32(double d
)
366 return INT32_MIN
<= d
&& d
<= INT32_MAX
&& (double)(int)d
== d
;
369 HRESULT WINAPI
VBScriptFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
370 HRESULT WINAPI
VBScriptRegExpFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
372 const char *debugstr_variant(const VARIANT
*) DECLSPEC_HIDDEN
;
374 static inline void *heap_alloc(size_t len
)
376 return HeapAlloc(GetProcessHeap(), 0, len
);
379 static inline void *heap_alloc_zero(size_t len
)
381 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
384 static inline void *heap_realloc(void *mem
, size_t len
)
386 return HeapReAlloc(GetProcessHeap(), 0, mem
, len
);
389 static inline BOOL
heap_free(void *mem
)
391 return HeapFree(GetProcessHeap(), 0, mem
);
394 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
401 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
402 ret
= heap_alloc(size
);
404 memcpy(ret
, str
, size
);