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
35 #include "vbscript_classes.h"
37 #include "wine/heap.h"
38 #include "wine/list.h"
39 #include "wine/unicode.h"
47 struct list custom_blocks
;
50 void heap_pool_init(heap_pool_t
*) DECLSPEC_HIDDEN
;
51 void *heap_pool_alloc(heap_pool_t
*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
;
52 void *heap_pool_grow(heap_pool_t
*,void*,DWORD
,DWORD
) DECLSPEC_HIDDEN
;
53 void heap_pool_clear(heap_pool_t
*) DECLSPEC_HIDDEN
;
54 void heap_pool_free(heap_pool_t
*) DECLSPEC_HIDDEN
;
55 heap_pool_t
*heap_pool_mark(heap_pool_t
*) DECLSPEC_HIDDEN
;
57 typedef struct _function_t function_t
;
58 typedef struct _vbscode_t vbscode_t
;
59 typedef struct _script_ctx_t script_ctx_t
;
60 typedef struct _vbdisp_t vbdisp_t
;
62 typedef struct named_item_t
{
75 } vbdisp_invoke_type_t
;
79 SAFEARRAYBOUND
*bounds
;
92 function_t
*entries
[VBDISP_ANY
];
93 } vbdisp_funcprop_desc_t
;
100 HRESULT (*proc
)(vbdisp_t
*,VARIANT
*,unsigned,VARIANT
*);
106 typedef struct _class_desc_t
{
110 unsigned class_initialize_id
;
111 unsigned class_terminate_id
;
113 vbdisp_funcprop_desc_t
*funcs
;
116 vbdisp_prop_desc_t
*props
;
119 array_desc_t
*array_descs
;
121 unsigned builtin_prop_cnt
;
122 const builtin_prop_t
*builtin_props
;
124 function_t
*value_func
;
126 struct _class_desc_t
*next
;
130 IDispatchEx IDispatchEx_iface
;
136 const class_desc_t
*desc
;
141 typedef struct _ident_map_t ident_map_t
;
144 IDispatchEx IDispatchEx_iface
;
147 ident_map_t
*ident_map
;
148 unsigned ident_map_cnt
;
149 unsigned ident_map_size
;
154 HRESULT
create_vbdisp(const class_desc_t
*,vbdisp_t
**) DECLSPEC_HIDDEN
;
155 HRESULT
disp_get_id(IDispatch
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
156 HRESULT
vbdisp_get_id(vbdisp_t
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
157 HRESULT
disp_call(script_ctx_t
*,IDispatch
*,DISPID
,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
158 HRESULT
disp_propput(script_ctx_t
*,IDispatch
*,DISPID
,WORD
,DISPPARAMS
*) DECLSPEC_HIDDEN
;
159 HRESULT
get_disp_value(script_ctx_t
*,IDispatch
*,VARIANT
*) DECLSPEC_HIDDEN
;
160 void collect_objects(script_ctx_t
*) DECLSPEC_HIDDEN
;
161 HRESULT
create_procedure_disp(script_ctx_t
*,vbscode_t
*,IDispatch
**) DECLSPEC_HIDDEN
;
162 HRESULT
create_script_disp(script_ctx_t
*,ScriptDisp
**) DECLSPEC_HIDDEN
;
164 HRESULT
to_int(VARIANT
*,int*) DECLSPEC_HIDDEN
;
166 static inline unsigned arg_cnt(const DISPPARAMS
*dp
)
168 return dp
->cArgs
- dp
->cNamedArgs
;
171 static inline VARIANT
*get_arg(DISPPARAMS
*dp
, DWORD i
)
173 return dp
->rgvarg
+ dp
->cArgs
-i
-1;
176 typedef struct _dynamic_var_t
{
177 struct _dynamic_var_t
*next
;
183 struct _script_ctx_t
{
184 IActiveScriptSite
*site
;
187 IInternetHostSecurityManager
*secmgr
;
190 IDispatch
*host_global
;
192 ScriptDisp
*script_obj
;
194 class_desc_t global_desc
;
195 vbdisp_t
*global_obj
;
197 class_desc_t err_desc
;
202 dynamic_var_t
*global_vars
;
203 function_t
*global_funcs
;
204 class_desc_t
*classes
;
210 struct list code_list
;
211 struct list named_items
;
214 HRESULT
init_global(script_ctx_t
*) DECLSPEC_HIDDEN
;
215 HRESULT
init_err(script_ctx_t
*) DECLSPEC_HIDDEN
;
217 IUnknown
*create_ax_site(script_ctx_t
*) DECLSPEC_HIDDEN
;
232 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
233 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
234 X(bool, 1, ARG_INT, 0) \
235 X(catch, 1, ARG_ADDR, ARG_UINT) \
236 X(case, 0, ARG_ADDR, 0) \
238 X(const, 1, ARG_BSTR, 0) \
239 X(dim, 1, ARG_BSTR, ARG_UINT) \
241 X(double, 1, ARG_DOUBLE, 0) \
243 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
245 X(hres, 1, ARG_UINT, 0) \
246 X(errmode, 1, ARG_INT, 0) \
251 X(icall, 1, ARG_BSTR, ARG_UINT) \
252 X(icallv, 1, ARG_BSTR, ARG_UINT) \
255 X(incc, 1, ARG_BSTR, 0) \
257 X(jmp, 0, ARG_ADDR, 0) \
258 X(jmp_false, 0, ARG_ADDR, 0) \
259 X(jmp_true, 0, ARG_ADDR, 0) \
260 X(long, 1, ARG_INT, 0) \
263 X(mcall, 1, ARG_BSTR, ARG_UINT) \
264 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
270 X(new, 1, ARG_STR, 0) \
271 X(newenum, 1, 0, 0) \
273 X(nothing, 1, 0, 0) \
276 X(pop, 1, ARG_UINT, 0) \
278 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
279 X(set_member, 1, ARG_BSTR, ARG_UINT) \
280 X(short, 1, ARG_INT, 0) \
281 X(step, 0, ARG_ADDR, ARG_BSTR) \
283 X(string, 1, ARG_STR, 0) \
289 #define X(x,n,a,b) OP_##x,
329 function_type_t type
;
336 array_desc_t
*array_descs
;
347 BOOL option_explicit
;
350 function_t main_code
;
354 unsigned bstr_pool_size
;
361 void release_vbscode(vbscode_t
*) DECLSPEC_HIDDEN
;
362 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,const WCHAR
*,vbscode_t
**) DECLSPEC_HIDDEN
;
363 HRESULT
exec_script(script_ctx_t
*,function_t
*,vbdisp_t
*,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
364 void release_dynamic_vars(dynamic_var_t
*) DECLSPEC_HIDDEN
;
365 IDispatch
*lookup_named_item(script_ctx_t
*,const WCHAR
*,unsigned) DECLSPEC_HIDDEN
;
377 #define XDIID(iface) iface ## _tid,
383 HRESULT
get_typeinfo(tid_t
,ITypeInfo
**) DECLSPEC_HIDDEN
;
384 void release_regexp_typelib(void) DECLSPEC_HIDDEN
;
387 #define INT32_MIN (-2147483647-1)
391 #define INT32_MAX (2147483647)
394 static inline BOOL
is_int32(double d
)
396 return INT32_MIN
<= d
&& d
<= INT32_MAX
&& (double)(int)d
== d
;
399 HRESULT
create_regexp(IDispatch
**) DECLSPEC_HIDDEN
;
401 HRESULT
map_hres(HRESULT
) DECLSPEC_HIDDEN
;
403 HRESULT
create_safearray_iter(SAFEARRAY
*sa
, IEnumVARIANT
**ev
) DECLSPEC_HIDDEN
;
405 #define FACILITY_VBS 0xa
406 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
408 #define VBSE_ILLEGAL_FUNC_CALL 5
409 #define VBSE_OVERFLOW 6
410 #define VBSE_OUT_OF_MEMORY 7
411 #define VBSE_OUT_OF_BOUNDS 9
412 #define VBSE_ARRAY_LOCKED 10
413 #define VBSE_TYPE_MISMATCH 13
414 #define VBSE_FILE_NOT_FOUND 53
415 #define VBSE_IO_ERROR 57
416 #define VBSE_FILE_ALREADY_EXISTS 58
417 #define VBSE_DISK_FULL 61
418 #define VBSE_TOO_MANY_FILES 67
419 #define VBSE_PERMISSION_DENIED 70
420 #define VBSE_PATH_FILE_ACCESS 75
421 #define VBSE_PATH_NOT_FOUND 76
422 #define VBSE_ILLEGAL_NULL_USE 94
423 #define VBSE_OLE_NOT_SUPPORTED 430
424 #define VBSE_OLE_NO_PROP_OR_METHOD 438
425 #define VBSE_ACTION_NOT_SUPPORTED 445
426 #define VBSE_NAMED_ARGS_NOT_SUPPORTED 446
427 #define VBSE_LOCALE_SETTING_NOT_SUPPORTED 447
428 #define VBSE_NAMED_PARAM_NOT_FOUND 448
429 #define VBSE_INVALID_TYPELIB_VARIABLE 458
430 #define VBSE_FUNC_ARITY_MISMATCH 450
431 #define VBSE_PARAMETER_NOT_OPTIONAL 449
432 #define VBSE_NOT_ENUM 451
433 #define VBSE_INVALID_DLL_FUNCTION_NAME 453
434 #define VBSE_CANT_CREATE_TMP_FILE 322
435 #define VBSE_OLE_FILE_NOT_FOUND 432
436 #define VBSE_CANT_CREATE_OBJECT 429
437 #define VBSE_SERVER_NOT_FOUND 462
439 HRESULT WINAPI
VBScriptFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
440 HRESULT WINAPI
VBScriptRegExpFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
442 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
449 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
450 ret
= heap_alloc(size
);
452 memcpy(ret
, str
, size
);
458 #define VBSCRIPT_BUILD_VERSION 16978
459 #define VBSCRIPT_MAJOR_VERSION 5
460 #define VBSCRIPT_MINOR_VERSION 8