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
25 #define WIN32_NO_STATUS
27 #define COM_NO_WINDOWS_H
39 #include <wine/debug.h>
40 #include <wine/list.h>
41 #include <wine/unicode.h>
43 WINE_DEFAULT_DEBUG_CHANNEL(vbscript
);
51 struct list custom_blocks
;
54 void heap_pool_init(heap_pool_t
*) DECLSPEC_HIDDEN
;
55 void *heap_pool_alloc(heap_pool_t
*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
;
56 void *heap_pool_grow(heap_pool_t
*,void*,DWORD
,DWORD
) DECLSPEC_HIDDEN
;
57 void heap_pool_clear(heap_pool_t
*) DECLSPEC_HIDDEN
;
58 void heap_pool_free(heap_pool_t
*) DECLSPEC_HIDDEN
;
59 heap_pool_t
*heap_pool_mark(heap_pool_t
*) DECLSPEC_HIDDEN
;
61 typedef struct _function_t function_t
;
62 typedef struct _vbscode_t vbscode_t
;
63 typedef struct _script_ctx_t script_ctx_t
;
64 typedef struct _vbdisp_t vbdisp_t
;
66 typedef struct named_item_t
{
79 } vbdisp_invoke_type_t
;
83 SAFEARRAYBOUND
*bounds
;
96 function_t
*entries
[VBDISP_ANY
];
97 } vbdisp_funcprop_desc_t
;
104 HRESULT (*proc
)(vbdisp_t
*,VARIANT
*,unsigned,VARIANT
*);
110 typedef struct _class_desc_t
{
114 unsigned class_initialize_id
;
115 unsigned class_terminate_id
;
117 vbdisp_funcprop_desc_t
*funcs
;
120 vbdisp_prop_desc_t
*props
;
123 array_desc_t
*array_descs
;
125 unsigned builtin_prop_cnt
;
126 const builtin_prop_t
*builtin_props
;
128 function_t
*value_func
;
130 struct _class_desc_t
*next
;
134 IDispatchEx IDispatchEx_iface
;
140 const class_desc_t
*desc
;
145 typedef struct _ident_map_t ident_map_t
;
148 IDispatchEx IDispatchEx_iface
;
151 ident_map_t
*ident_map
;
152 unsigned ident_map_cnt
;
153 unsigned ident_map_size
;
158 HRESULT
create_vbdisp(const class_desc_t
*,vbdisp_t
**) DECLSPEC_HIDDEN
;
159 HRESULT
disp_get_id(IDispatch
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
160 HRESULT
vbdisp_get_id(vbdisp_t
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
161 HRESULT
disp_call(script_ctx_t
*,IDispatch
*,DISPID
,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
162 HRESULT
disp_propput(script_ctx_t
*,IDispatch
*,DISPID
,WORD
,DISPPARAMS
*) DECLSPEC_HIDDEN
;
163 HRESULT
get_disp_value(script_ctx_t
*,IDispatch
*,VARIANT
*) DECLSPEC_HIDDEN
;
164 void collect_objects(script_ctx_t
*) DECLSPEC_HIDDEN
;
165 HRESULT
create_procedure_disp(script_ctx_t
*,vbscode_t
*,IDispatch
**) DECLSPEC_HIDDEN
;
166 HRESULT
create_script_disp(script_ctx_t
*,ScriptDisp
**) DECLSPEC_HIDDEN
;
168 HRESULT
to_int(VARIANT
*,int*) DECLSPEC_HIDDEN
;
170 static inline unsigned arg_cnt(const DISPPARAMS
*dp
)
172 return dp
->cArgs
- dp
->cNamedArgs
;
175 static inline VARIANT
*get_arg(DISPPARAMS
*dp
, DWORD i
)
177 return dp
->rgvarg
+ dp
->cArgs
-i
-1;
180 typedef struct _dynamic_var_t
{
181 struct _dynamic_var_t
*next
;
187 struct _script_ctx_t
{
188 IActiveScriptSite
*site
;
191 IInternetHostSecurityManager
*secmgr
;
194 IDispatch
*host_global
;
196 ScriptDisp
*script_obj
;
198 class_desc_t global_desc
;
199 vbdisp_t
*global_obj
;
201 class_desc_t err_desc
;
206 dynamic_var_t
*global_vars
;
207 function_t
*global_funcs
;
208 class_desc_t
*classes
;
214 struct list code_list
;
215 struct list named_items
;
218 HRESULT
init_global(script_ctx_t
*) DECLSPEC_HIDDEN
;
219 HRESULT
init_err(script_ctx_t
*) DECLSPEC_HIDDEN
;
221 IUnknown
*create_ax_site(script_ctx_t
*) DECLSPEC_HIDDEN
;
236 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
237 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
238 X(bool, 1, ARG_INT, 0) \
239 X(catch, 1, ARG_ADDR, ARG_UINT) \
240 X(case, 0, ARG_ADDR, 0) \
242 X(const, 1, ARG_BSTR, 0) \
243 X(dim, 1, ARG_BSTR, ARG_UINT) \
245 X(double, 1, ARG_DOUBLE, 0) \
247 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
249 X(hres, 1, ARG_UINT, 0) \
250 X(errmode, 1, ARG_INT, 0) \
255 X(icall, 1, ARG_BSTR, ARG_UINT) \
256 X(icallv, 1, ARG_BSTR, ARG_UINT) \
259 X(incc, 1, ARG_BSTR, 0) \
261 X(jmp, 0, ARG_ADDR, 0) \
262 X(jmp_false, 0, ARG_ADDR, 0) \
263 X(jmp_true, 0, ARG_ADDR, 0) \
264 X(long, 1, ARG_INT, 0) \
267 X(mcall, 1, ARG_BSTR, ARG_UINT) \
268 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
274 X(new, 1, ARG_STR, 0) \
275 X(newenum, 1, 0, 0) \
277 X(nothing, 1, 0, 0) \
280 X(pop, 1, ARG_UINT, 0) \
282 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
283 X(set_member, 1, ARG_BSTR, ARG_UINT) \
284 X(short, 1, ARG_INT, 0) \
285 X(step, 0, ARG_ADDR, ARG_BSTR) \
287 X(string, 1, ARG_STR, 0) \
293 #define X(x,n,a,b) OP_##x,
333 function_type_t type
;
340 array_desc_t
*array_descs
;
351 BOOL option_explicit
;
354 function_t main_code
;
357 unsigned bstr_pool_size
;
364 void release_vbscode(vbscode_t
*) DECLSPEC_HIDDEN
;
365 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,const WCHAR
*,vbscode_t
**) DECLSPEC_HIDDEN
;
366 HRESULT
exec_script(script_ctx_t
*,function_t
*,vbdisp_t
*,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
367 void release_dynamic_vars(dynamic_var_t
*) DECLSPEC_HIDDEN
;
379 #define XDIID(iface) iface ## _tid,
385 HRESULT
get_typeinfo(tid_t
,ITypeInfo
**) DECLSPEC_HIDDEN
;
386 void release_regexp_typelib(void) DECLSPEC_HIDDEN
;
389 #define INT32_MIN (-2147483647-1)
393 #define INT32_MAX (2147483647)
396 static inline BOOL
is_int32(double d
)
398 return INT32_MIN
<= d
&& d
<= INT32_MAX
&& (double)(int)d
== d
;
401 HRESULT
create_regexp(IDispatch
**) DECLSPEC_HIDDEN
;
403 HRESULT
map_hres(HRESULT
) DECLSPEC_HIDDEN
;
405 HRESULT
create_safearray_iter(SAFEARRAY
*sa
, IEnumVARIANT
**ev
) DECLSPEC_HIDDEN
;
407 #define FACILITY_VBS 0xa
408 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
410 #define VBSE_ILLEGAL_FUNC_CALL 5
411 #define VBSE_OVERFLOW 6
412 #define VBSE_OUT_OF_MEMORY 7
413 #define VBSE_OUT_OF_BOUNDS 9
414 #define VBSE_ARRAY_LOCKED 10
415 #define VBSE_TYPE_MISMATCH 13
416 #define VBSE_FILE_NOT_FOUND 53
417 #define VBSE_IO_ERROR 57
418 #define VBSE_FILE_ALREADY_EXISTS 58
419 #define VBSE_DISK_FULL 61
420 #define VBSE_TOO_MANY_FILES 67
421 #define VBSE_PERMISSION_DENIED 70
422 #define VBSE_PATH_FILE_ACCESS 75
423 #define VBSE_PATH_NOT_FOUND 76
424 #define VBSE_ILLEGAL_NULL_USE 94
425 #define VBSE_OLE_NOT_SUPPORTED 430
426 #define VBSE_OLE_NO_PROP_OR_METHOD 438
427 #define VBSE_ACTION_NOT_SUPPORTED 445
428 #define VBSE_NAMED_ARGS_NOT_SUPPORTED 446
429 #define VBSE_LOCALE_SETTING_NOT_SUPPORTED 447
430 #define VBSE_NAMED_PARAM_NOT_FOUND 448
431 #define VBSE_INVALID_TYPELIB_VARIABLE 458
432 #define VBSE_FUNC_ARITY_MISMATCH 450
433 #define VBSE_PARAMETER_NOT_OPTIONAL 449
434 #define VBSE_NOT_ENUM 451
435 #define VBSE_INVALID_DLL_FUNCTION_NAME 453
436 #define VBSE_CANT_CREATE_TMP_FILE 322
437 #define VBSE_OLE_FILE_NOT_FOUND 432
438 #define VBSE_CANT_CREATE_OBJECT 429
439 #define VBSE_SERVER_NOT_FOUND 462
441 HRESULT WINAPI
VBScriptFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
442 HRESULT WINAPI
VBScriptRegExpFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
444 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc(size_t size
)
446 return HeapAlloc(GetProcessHeap(), 0, size
);
449 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t size
)
451 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
454 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc(void *mem
, size_t size
)
456 return HeapReAlloc(GetProcessHeap(), 0, mem
, size
);
459 static inline BOOL
heap_free(void *mem
)
461 return HeapFree(GetProcessHeap(), 0, mem
);
464 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
471 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
472 ret
= heap_alloc(size
);
474 memcpy(ret
, str
, size
);
480 #define VBSCRIPT_BUILD_VERSION 16978
481 #define VBSCRIPT_MAJOR_VERSION 5
482 #define VBSCRIPT_MINOR_VERSION 8
486 #include "vbscript_defs.h"
488 #endif /* _VBSCRIPT_H */