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
31 #include "vbscript_classes.h"
32 #include "vbscript_defs.h"
34 #include "wine/heap.h"
35 #include "wine/list.h"
43 struct list custom_blocks
;
46 void heap_pool_init(heap_pool_t
*) DECLSPEC_HIDDEN
;
47 void *heap_pool_alloc(heap_pool_t
*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
;
48 void *heap_pool_grow(heap_pool_t
*,void*,DWORD
,DWORD
) DECLSPEC_HIDDEN
;
49 void heap_pool_clear(heap_pool_t
*) DECLSPEC_HIDDEN
;
50 void heap_pool_free(heap_pool_t
*) DECLSPEC_HIDDEN
;
51 heap_pool_t
*heap_pool_mark(heap_pool_t
*) DECLSPEC_HIDDEN
;
53 typedef struct _function_t function_t
;
54 typedef struct _vbscode_t vbscode_t
;
55 typedef struct _script_ctx_t script_ctx_t
;
56 typedef struct _vbdisp_t vbdisp_t
;
63 } vbdisp_invoke_type_t
;
67 SAFEARRAYBOUND
*bounds
;
80 function_t
*entries
[VBDISP_ANY
];
81 } vbdisp_funcprop_desc_t
;
83 typedef struct _class_desc_t
{
87 unsigned class_initialize_id
;
88 unsigned class_terminate_id
;
90 vbdisp_funcprop_desc_t
*funcs
;
93 vbdisp_prop_desc_t
*props
;
96 array_desc_t
*array_descs
;
98 function_t
*value_func
;
100 struct _class_desc_t
*next
;
104 IDispatchEx IDispatchEx_iface
;
110 const class_desc_t
*desc
;
115 typedef struct _dynamic_var_t
{
116 struct _dynamic_var_t
*next
;
124 IDispatchEx IDispatchEx_iface
;
127 dynamic_var_t
**global_vars
;
128 size_t global_vars_cnt
;
129 size_t global_vars_size
;
131 function_t
**global_funcs
;
132 size_t global_funcs_cnt
;
133 size_t global_funcs_size
;
135 class_desc_t
*classes
;
141 typedef struct _builtin_prop_t builtin_prop_t
;
144 IDispatch IDispatch_iface
;
147 const builtin_prop_t
*members
;
151 typedef struct named_item_t
{
152 ScriptDisp
*script_obj
;
161 HRESULT
create_vbdisp(const class_desc_t
*,vbdisp_t
**) DECLSPEC_HIDDEN
;
162 HRESULT
disp_get_id(IDispatch
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
163 HRESULT
vbdisp_get_id(vbdisp_t
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
164 HRESULT
disp_call(script_ctx_t
*,IDispatch
*,DISPID
,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
165 HRESULT
disp_propput(script_ctx_t
*,IDispatch
*,DISPID
,WORD
,DISPPARAMS
*) DECLSPEC_HIDDEN
;
166 HRESULT
get_disp_value(script_ctx_t
*,IDispatch
*,VARIANT
*) DECLSPEC_HIDDEN
;
167 void collect_objects(script_ctx_t
*) DECLSPEC_HIDDEN
;
168 HRESULT
create_script_disp(script_ctx_t
*,ScriptDisp
**) DECLSPEC_HIDDEN
;
170 HRESULT
to_int(VARIANT
*,int*) DECLSPEC_HIDDEN
;
172 static inline unsigned arg_cnt(const DISPPARAMS
*dp
)
174 return dp
->cArgs
- dp
->cNamedArgs
;
177 static inline VARIANT
*get_arg(DISPPARAMS
*dp
, DWORD i
)
179 return dp
->rgvarg
+ dp
->cArgs
-i
-1;
182 struct _script_ctx_t
{
183 IActiveScriptSite
*site
;
186 IInternetHostSecurityManager
*secmgr
;
189 ScriptDisp
*script_obj
;
191 BuiltinDisp
*global_obj
;
192 BuiltinDisp
*err_obj
;
195 vbscode_t
*error_loc_code
;
196 unsigned error_loc_offset
;
199 struct list code_list
;
200 struct list named_items
;
203 HRESULT
init_global(script_ctx_t
*) DECLSPEC_HIDDEN
;
204 HRESULT
init_err(script_ctx_t
*) DECLSPEC_HIDDEN
;
206 IUnknown
*create_ax_site(script_ctx_t
*) DECLSPEC_HIDDEN
;
221 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
222 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
223 X(bool, 1, ARG_INT, 0) \
224 X(catch, 1, ARG_ADDR, ARG_UINT) \
225 X(case, 0, ARG_ADDR, 0) \
227 X(const, 1, ARG_BSTR, 0) \
229 X(dim, 1, ARG_BSTR, ARG_UINT) \
231 X(double, 1, ARG_DOUBLE, 0) \
233 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
235 X(hres, 1, ARG_UINT, 0) \
236 X(errmode, 1, ARG_INT, 0) \
241 X(icall, 1, ARG_BSTR, ARG_UINT) \
242 X(icallv, 1, ARG_BSTR, ARG_UINT) \
245 X(incc, 1, ARG_BSTR, 0) \
246 X(int, 1, ARG_INT, 0) \
248 X(jmp, 0, ARG_ADDR, 0) \
249 X(jmp_false, 0, ARG_ADDR, 0) \
250 X(jmp_true, 0, ARG_ADDR, 0) \
253 X(mcall, 1, ARG_BSTR, ARG_UINT) \
254 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
260 X(new, 1, ARG_STR, 0) \
261 X(newenum, 1, 0, 0) \
263 X(nothing, 1, 0, 0) \
266 X(pop, 1, ARG_UINT, 0) \
267 X(redim, 1, ARG_BSTR, ARG_UINT) \
268 X(redim_preserve, 1, ARG_BSTR, ARG_UINT) \
271 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
272 X(set_member, 1, ARG_BSTR, ARG_UINT) \
273 X(stack, 1, ARG_UINT, 0) \
274 X(step, 0, ARG_ADDR, ARG_BSTR) \
276 X(string, 1, ARG_STR, 0) \
279 X(vcall, 1, ARG_UINT, 0) \
280 X(vcallv, 1, ARG_UINT, 0) \
284 #define X(x,n,a,b) OP_##x,
324 function_type_t type
;
331 array_desc_t
*array_descs
;
346 BOOL option_explicit
;
350 function_t main_code
;
351 named_item_t
*named_item
;
354 unsigned bstr_pool_size
;
359 class_desc_t
*classes
;
360 class_desc_t
*last_class
;
365 static inline void grab_vbscode(vbscode_t
*code
)
370 void release_vbscode(vbscode_t
*) DECLSPEC_HIDDEN
;
371 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,const WCHAR
*,const WCHAR
*,DWORD_PTR
,unsigned,DWORD
,vbscode_t
**) DECLSPEC_HIDDEN
;
372 HRESULT
compile_procedure(script_ctx_t
*,const WCHAR
*,const WCHAR
*,const WCHAR
*,DWORD_PTR
,unsigned,DWORD
,class_desc_t
**) DECLSPEC_HIDDEN
;
373 HRESULT
exec_script(script_ctx_t
*,BOOL
,function_t
*,vbdisp_t
*,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
374 void release_dynamic_var(dynamic_var_t
*) DECLSPEC_HIDDEN
;
375 named_item_t
*lookup_named_item(script_ctx_t
*,const WCHAR
*,unsigned) DECLSPEC_HIDDEN
;
376 void release_named_item(named_item_t
*) DECLSPEC_HIDDEN
;
377 void clear_ei(EXCEPINFO
*) DECLSPEC_HIDDEN
;
378 HRESULT
report_script_error(script_ctx_t
*,const vbscode_t
*,unsigned) DECLSPEC_HIDDEN
;
379 void detach_global_objects(script_ctx_t
*) DECLSPEC_HIDDEN
;
380 HRESULT
get_builtin_id(BuiltinDisp
*,const WCHAR
*,DISPID
*) DECLSPEC_HIDDEN
;
382 void release_regexp_typelib(void) DECLSPEC_HIDDEN
;
383 HRESULT
get_dispatch_typeinfo(ITypeInfo
**) DECLSPEC_HIDDEN
;
385 static inline BOOL
is_int32(double d
)
387 return INT32_MIN
<= d
&& d
<= INT32_MAX
&& (double)(int)d
== d
;
390 static inline BOOL
is_digit(WCHAR c
)
392 return '0' <= c
&& c
<= '9';
395 HRESULT
create_regexp(IDispatch
**) DECLSPEC_HIDDEN
;
396 BSTR
string_replace(BSTR
,BSTR
,BSTR
,int,int,int) DECLSPEC_HIDDEN
;
398 HRESULT
map_hres(HRESULT
) DECLSPEC_HIDDEN
;
400 HRESULT
create_safearray_iter(SAFEARRAY
*sa
, IEnumVARIANT
**ev
) DECLSPEC_HIDDEN
;
402 #define FACILITY_VBS 0xa
403 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
405 HRESULT WINAPI
VBScriptFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
406 HRESULT WINAPI
VBScriptRegExpFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
408 BSTR
get_vbscript_string(int) DECLSPEC_HIDDEN
;
409 BSTR
get_vbscript_error_string(HRESULT
) DECLSPEC_HIDDEN
;
411 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
418 size
= (lstrlenW(str
)+1)*sizeof(WCHAR
);
419 ret
= heap_alloc(size
);
421 memcpy(ret
, str
, size
);
427 #define VBSCRIPT_BUILD_VERSION 16978
428 #define VBSCRIPT_MAJOR_VERSION 5
429 #define VBSCRIPT_MINOR_VERSION 8