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
22 #define WIN32_NO_STATUS
24 #define COM_NO_WINDOWS_H
36 #include <wine/debug.h>
37 #include <wine/list.h>
38 #include <wine/unicode.h>
40 WINE_DEFAULT_DEBUG_CHANNEL(vbscript
);
48 struct list custom_blocks
;
51 void heap_pool_init(heap_pool_t
*) DECLSPEC_HIDDEN
;
52 void *heap_pool_alloc(heap_pool_t
*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
;
53 void *heap_pool_grow(heap_pool_t
*,void*,DWORD
,DWORD
) DECLSPEC_HIDDEN
;
54 void heap_pool_clear(heap_pool_t
*) DECLSPEC_HIDDEN
;
55 void heap_pool_free(heap_pool_t
*) DECLSPEC_HIDDEN
;
56 heap_pool_t
*heap_pool_mark(heap_pool_t
*) DECLSPEC_HIDDEN
;
58 typedef struct _function_t function_t
;
59 typedef struct _vbscode_t vbscode_t
;
60 typedef struct _script_ctx_t script_ctx_t
;
61 typedef struct _vbdisp_t vbdisp_t
;
63 typedef struct named_item_t
{
76 } vbdisp_invoke_type_t
;
86 function_t
*entries
[VBDISP_ANY
];
87 } vbdisp_funcprop_desc_t
;
94 HRESULT (*proc
)(vbdisp_t
*,VARIANT
*,unsigned,VARIANT
*);
100 typedef struct _class_desc_t
{
104 unsigned class_initialize_id
;
105 unsigned class_terminate_id
;
107 vbdisp_funcprop_desc_t
*funcs
;
110 vbdisp_prop_desc_t
*props
;
112 unsigned builtin_prop_cnt
;
113 const builtin_prop_t
*builtin_props
;
115 function_t
*value_func
;
117 struct _class_desc_t
*next
;
121 IDispatchEx IDispatchEx_iface
;
127 const class_desc_t
*desc
;
131 typedef struct _ident_map_t ident_map_t
;
134 IDispatchEx IDispatchEx_iface
;
137 ident_map_t
*ident_map
;
138 unsigned ident_map_cnt
;
139 unsigned ident_map_size
;
144 HRESULT
create_vbdisp(const class_desc_t
*,vbdisp_t
**) DECLSPEC_HIDDEN
;
145 HRESULT
disp_get_id(IDispatch
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
146 HRESULT
vbdisp_get_id(vbdisp_t
*,BSTR
,vbdisp_invoke_type_t
,BOOL
,DISPID
*) DECLSPEC_HIDDEN
;
147 HRESULT
disp_call(script_ctx_t
*,IDispatch
*,DISPID
,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
148 HRESULT
disp_propput(script_ctx_t
*,IDispatch
*,DISPID
,DISPPARAMS
*) DECLSPEC_HIDDEN
;
149 void collect_objects(script_ctx_t
*) DECLSPEC_HIDDEN
;
150 HRESULT
create_procedure_disp(script_ctx_t
*,vbscode_t
*,IDispatch
**) DECLSPEC_HIDDEN
;
151 HRESULT
create_script_disp(script_ctx_t
*,ScriptDisp
**) DECLSPEC_HIDDEN
;
153 static inline unsigned arg_cnt(const DISPPARAMS
*dp
)
155 return dp
->cArgs
- dp
->cNamedArgs
;
158 static inline VARIANT
*get_arg(DISPPARAMS
*dp
, DWORD i
)
160 return dp
->rgvarg
+ dp
->cArgs
-i
-1;
163 typedef struct _dynamic_var_t
{
164 struct _dynamic_var_t
*next
;
170 struct _script_ctx_t
{
171 IActiveScriptSite
*site
;
174 IInternetHostSecurityManager
*secmgr
;
177 IDispatch
*host_global
;
179 ScriptDisp
*script_obj
;
181 class_desc_t global_desc
;
182 vbdisp_t
*global_obj
;
184 class_desc_t err_desc
;
187 dynamic_var_t
*global_vars
;
188 function_t
*global_funcs
;
189 class_desc_t
*classes
;
195 struct list code_list
;
196 struct list named_items
;
199 HRESULT
init_global(script_ctx_t
*) DECLSPEC_HIDDEN
;
200 HRESULT
init_err(script_ctx_t
*) DECLSPEC_HIDDEN
;
202 IUnknown
*create_ax_site(script_ctx_t
*) DECLSPEC_HIDDEN
;
217 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
218 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
219 X(bool, 1, ARG_INT, 0) \
220 X(case, 0, ARG_ADDR, 0) \
222 X(const, 1, ARG_BSTR, 0) \
224 X(double, 1, ARG_DOUBLE, 0) \
226 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
228 X(errmode, 1, ARG_INT, 0) \
233 X(icall, 1, ARG_BSTR, ARG_UINT) \
234 X(icallv, 1, ARG_BSTR, ARG_UINT) \
237 X(incc, 1, ARG_BSTR, 0) \
239 X(jmp, 0, ARG_ADDR, 0) \
240 X(jmp_false, 0, ARG_ADDR, 0) \
241 X(jmp_true, 0, ARG_ADDR, 0) \
242 X(long, 1, ARG_INT, 0) \
245 X(mcall, 1, ARG_BSTR, ARG_UINT) \
246 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
252 X(new, 1, ARG_STR, 0) \
253 X(newenum, 1, 0, 0) \
255 X(nothing, 1, 0, 0) \
258 X(pop, 1, ARG_UINT, 0) \
260 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
261 X(set_member, 1, ARG_BSTR, ARG_UINT) \
262 X(short, 1, ARG_INT, 0) \
263 X(step, 0, ARG_ADDR, ARG_BSTR) \
265 X(string, 1, ARG_STR, 0) \
271 #define X(x,n,a,b) OP_##x,
311 function_type_t type
;
327 BOOL option_explicit
;
330 function_t main_code
;
333 unsigned bstr_pool_size
;
340 void release_vbscode(vbscode_t
*) DECLSPEC_HIDDEN
;
341 HRESULT
compile_script(script_ctx_t
*,const WCHAR
*,const WCHAR
*,vbscode_t
**) DECLSPEC_HIDDEN
;
342 HRESULT
exec_script(script_ctx_t
*,function_t
*,IDispatch
*,DISPPARAMS
*,VARIANT
*) DECLSPEC_HIDDEN
;
343 void release_dynamic_vars(dynamic_var_t
*) DECLSPEC_HIDDEN
;
355 #define XDIID(iface) iface ## _tid,
361 HRESULT
get_typeinfo(tid_t
,ITypeInfo
**) DECLSPEC_HIDDEN
;
362 void release_regexp_typelib(void) DECLSPEC_HIDDEN
;
365 #define INT32_MIN (-2147483647-1)
369 #define INT32_MAX (2147483647)
372 static inline BOOL
is_int32(double d
)
374 return INT32_MIN
<= d
&& d
<= INT32_MAX
&& (double)(int)d
== d
;
377 HRESULT WINAPI
VBScriptFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
378 HRESULT WINAPI
VBScriptRegExpFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**) DECLSPEC_HIDDEN
;
380 const char *debugstr_variant(const VARIANT
*) DECLSPEC_HIDDEN
;
382 static inline void *heap_alloc(size_t len
)
384 return HeapAlloc(GetProcessHeap(), 0, len
);
387 static inline void *heap_alloc_zero(size_t len
)
389 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
392 static inline void *heap_realloc(void *mem
, size_t len
)
394 return HeapReAlloc(GetProcessHeap(), 0, mem
, len
);
397 static inline BOOL
heap_free(void *mem
)
399 return HeapFree(GetProcessHeap(), 0, mem
);
402 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
409 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
410 ret
= heap_alloc(size
);
412 memcpy(ret
, str
, size
);
420 #include "vbscript_defs.h"