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
;
72 SAFEARRAYBOUND
*bounds
;
85 function_t
*entries
[VBDISP_ANY
];
86 } vbdisp_funcprop_desc_t
;
93 HRESULT (*proc
)(vbdisp_t
*,VARIANT
*,unsigned,VARIANT
*);
99 typedef struct _class_desc_t
{
103 unsigned class_initialize_id
;
104 unsigned class_terminate_id
;
106 vbdisp_funcprop_desc_t
*funcs
;
109 vbdisp_prop_desc_t
*props
;
112 array_desc_t
*array_descs
;
114 unsigned builtin_prop_cnt
;
115 const builtin_prop_t
*builtin_props
;
117 function_t
*value_func
;
119 struct _class_desc_t
*next
;
123 IDispatchEx IDispatchEx_iface
;
129 const class_desc_t
*desc
;
134 typedef struct _ident_map_t ident_map_t
;
137 IDispatchEx IDispatchEx_iface
;
140 ident_map_t
*ident_map
;
141 unsigned ident_map_cnt
;
142 unsigned ident_map_size
;
147 HRESULT
create_vbdisp(const class_desc_t
*,vbdisp_t
**) DECLSPEC_HIDDEN
;
148 HRESULT
disp_get_id(IDispatch
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
149 HRESULT
vbdisp_get_id(vbdisp_t
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
150 HRESULT
disp_call(script_ctx_t
*,IDispatch
*,DISPID
,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
151 HRESULT
disp_propput(script_ctx_t
*,IDispatch
*,DISPID
,DISPPARAMS
*) DECLSPEC_HIDDEN
;
152 void collect_objects(script_ctx_t
*) DECLSPEC_HIDDEN
;
153 HRESULT
create_procedure_disp(script_ctx_t
*,vbscode_t
*,IDispatch
**) DECLSPEC_HIDDEN
;
154 HRESULT
create_script_disp(script_ctx_t
*,ScriptDisp
**) DECLSPEC_HIDDEN
;
156 HRESULT
to_int(VARIANT
*,int*) DECLSPEC_HIDDEN
;
158 static inline unsigned arg_cnt(const DISPPARAMS
*dp
)
160 return dp
->cArgs
- dp
->cNamedArgs
;
163 static inline VARIANT
*get_arg(DISPPARAMS
*dp
, DWORD i
)
165 return dp
->rgvarg
+ dp
->cArgs
-i
-1;
168 typedef struct _dynamic_var_t
{
169 struct _dynamic_var_t
*next
;
175 struct _script_ctx_t
{
176 IActiveScriptSite
*site
;
179 IInternetHostSecurityManager
*secmgr
;
182 IDispatch
*host_global
;
184 ScriptDisp
*script_obj
;
186 class_desc_t global_desc
;
187 vbdisp_t
*global_obj
;
189 class_desc_t err_desc
;
194 dynamic_var_t
*global_vars
;
195 function_t
*global_funcs
;
196 class_desc_t
*classes
;
202 struct list code_list
;
203 struct list named_items
;
206 HRESULT
init_global(script_ctx_t
*) DECLSPEC_HIDDEN
;
207 HRESULT
init_err(script_ctx_t
*) DECLSPEC_HIDDEN
;
209 IUnknown
*create_ax_site(script_ctx_t
*) DECLSPEC_HIDDEN
;
224 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
225 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
226 X(bool, 1, ARG_INT, 0) \
227 X(catch, 1, ARG_ADDR, ARG_UINT) \
228 X(case, 0, ARG_ADDR, 0) \
230 X(const, 1, ARG_BSTR, 0) \
231 X(dim, 1, ARG_BSTR, ARG_UINT) \
233 X(double, 1, ARG_DOUBLE, 0) \
235 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
237 X(errmode, 1, ARG_INT, 0) \
242 X(icall, 1, ARG_BSTR, ARG_UINT) \
243 X(icallv, 1, ARG_BSTR, ARG_UINT) \
246 X(incc, 1, ARG_BSTR, 0) \
248 X(jmp, 0, ARG_ADDR, 0) \
249 X(jmp_false, 0, ARG_ADDR, 0) \
250 X(jmp_true, 0, ARG_ADDR, 0) \
251 X(long, 1, ARG_INT, 0) \
254 X(mcall, 1, ARG_BSTR, ARG_UINT) \
255 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
261 X(new, 1, ARG_STR, 0) \
262 X(newenum, 1, 0, 0) \
264 X(nothing, 1, 0, 0) \
267 X(pop, 1, ARG_UINT, 0) \
269 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
270 X(set_member, 1, ARG_BSTR, ARG_UINT) \
271 X(short, 1, ARG_INT, 0) \
272 X(step, 0, ARG_ADDR, ARG_BSTR) \
274 X(string, 1, ARG_STR, 0) \
280 #define X(x,n,a,b) OP_##x,
320 function_type_t type
;
327 array_desc_t
*array_descs
;
338 BOOL option_explicit
;
341 function_t main_code
;
344 unsigned bstr_pool_size
;
351 void release_vbscode(vbscode_t
*) DECLSPEC_HIDDEN
;
352 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,const WCHAR
*,vbscode_t
**) DECLSPEC_HIDDEN
;
353 HRESULT
exec_script(script_ctx_t
*,function_t
*,vbdisp_t
*,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
354 void release_dynamic_vars(dynamic_var_t
*) DECLSPEC_HIDDEN
;
366 #define XDIID(iface) iface ## _tid,
372 HRESULT
get_typeinfo(tid_t
,ITypeInfo
**) DECLSPEC_HIDDEN
;
373 void release_regexp_typelib(void) DECLSPEC_HIDDEN
;
376 #define INT32_MIN (-2147483647-1)
380 #define INT32_MAX (2147483647)
383 static inline BOOL
is_int32(double d
)
385 return INT32_MIN
<= d
&& d
<= INT32_MAX
&& (double)(int)d
== d
;
388 HRESULT
create_regexp(IDispatch
**) DECLSPEC_HIDDEN
;
390 HRESULT
map_hres(HRESULT
) DECLSPEC_HIDDEN
;
392 #define FACILITY_VBS 0xa
393 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
395 #define VBSE_ILLEGAL_FUNC_CALL 5
396 #define VBSE_OVERFLOW 6
397 #define VBSE_OUT_OF_MEMORY 7
398 #define VBSE_OUT_OF_BOUNDS 9
399 #define VBSE_ARRAY_LOCKED 10
400 #define VBSE_TYPE_MISMATCH 13
401 #define VBSE_FILE_NOT_FOUND 53
402 #define VBSE_IO_ERROR 57
403 #define VBSE_FILE_ALREADY_EXISTS 58
404 #define VBSE_DISK_FULL 61
405 #define VBSE_TOO_MANY_FILES 67
406 #define VBSE_PERMISSION_DENIED 70
407 #define VBSE_PATH_FILE_ACCESS 75
408 #define VBSE_PATH_NOT_FOUND 76
409 #define VBSE_ILLEGAL_NULL_USE 94
410 #define VBSE_OLE_NOT_SUPPORTED 430
411 #define VBSE_OLE_NO_PROP_OR_METHOD 438
412 #define VBSE_ACTION_NOT_SUPPORTED 445
413 #define VBSE_NAMED_ARGS_NOT_SUPPORTED 446
414 #define VBSE_LOCALE_SETTING_NOT_SUPPORTED 447
415 #define VBSE_NAMED_PARAM_NOT_FOUND 448
416 #define VBSE_INVALID_TYPELIB_VARIABLE 458
417 #define VBSE_FUNC_ARITY_MISMATCH 450
418 #define VBSE_PARAMETER_NOT_OPTIONAL 449
419 #define VBSE_NOT_ENUM 451
420 #define VBSE_INVALID_DLL_FUNCTION_NAME 453
421 #define VBSE_CANT_CREATE_TMP_FILE 322
422 #define VBSE_OLE_FILE_NOT_FOUND 432
423 #define VBSE_CANT_CREATE_OBJECT 429
424 #define VBSE_SERVER_NOT_FOUND 462
426 HRESULT WINAPI
VBScriptFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
427 HRESULT WINAPI
VBScriptRegExpFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
429 static inline void *heap_alloc(size_t len
)
431 return HeapAlloc(GetProcessHeap(), 0, len
);
434 static inline void *heap_alloc_zero(size_t len
)
436 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
439 static inline void *heap_realloc(void *mem
, size_t len
)
441 return HeapReAlloc(GetProcessHeap(), 0, mem
, len
);
444 static inline BOOL
heap_free(void *mem
)
446 return HeapFree(GetProcessHeap(), 0, mem
);
449 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
456 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
457 ret
= heap_alloc(size
);
459 memcpy(ret
, str
, size
);
465 #define VBSCRIPT_BUILD_VERSION 16978
466 #define VBSCRIPT_MAJOR_VERSION 5
467 #define VBSCRIPT_MINOR_VERSION 8