2 * Copyright 2008 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 "wine/unicode.h"
32 #include "wine/list.h"
34 typedef struct _script_ctx_t script_ctx_t
;
35 typedef struct _exec_ctx_t exec_ctx_t
;
36 typedef struct _dispex_prop_t dispex_prop_t
;
49 struct list custom_blocks
;
52 void jsheap_init(jsheap_t
*);
53 void *jsheap_alloc(jsheap_t
*,DWORD
);
54 void *jsheap_grow(jsheap_t
*,void*,DWORD
,DWORD
);
55 void jsheap_clear(jsheap_t
*);
56 void jsheap_free(jsheap_t
*);
57 jsheap_t
*jsheap_mark(jsheap_t
*);
59 typedef struct DispatchEx DispatchEx
;
61 #define PROPF_ARGMASK 0x00ff
62 #define PROPF_METHOD 0x0100
63 #define PROPF_ENUM 0x0200
64 #define PROPF_CONSTR 0x0400
79 typedef HRESULT (*builtin_invoke_t
)(DispatchEx
*,LCID
,WORD
,DISPPARAMS
*,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
83 builtin_invoke_t invoke
;
89 builtin_prop_t value_prop
;
91 const builtin_prop_t
*props
;
92 void (*destructor
)(DispatchEx
*);
93 void (*on_put
)(DispatchEx
*,const WCHAR
*);
97 const IDispatchExVtbl
*lpIDispatchExVtbl
;
103 dispex_prop_t
*props
;
106 DispatchEx
*prototype
;
108 const builtin_info_t
*builtin_info
;
111 #define _IDispatchEx_(x) ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
113 static inline void jsdisp_release(DispatchEx
*jsdisp
)
115 IDispatchEx_Release(_IDispatchEx_(jsdisp
));
118 HRESULT
create_dispex(script_ctx_t
*,const builtin_info_t
*,DispatchEx
*,DispatchEx
**);
119 HRESULT
init_dispex(DispatchEx
*,script_ctx_t
*,const builtin_info_t
*,DispatchEx
*);
120 HRESULT
init_dispex_from_constr(DispatchEx
*,script_ctx_t
*,const builtin_info_t
*,DispatchEx
*);
121 DispatchEx
*iface_to_jsdisp(IUnknown
*);
123 HRESULT
disp_call(IDispatch
*,DISPID
,LCID
,WORD
,DISPPARAMS
*,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
124 HRESULT
jsdisp_call_value(DispatchEx
*,LCID
,WORD
,DISPPARAMS
*,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
125 HRESULT
disp_propget(IDispatch
*,DISPID
,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
126 HRESULT
disp_propput(IDispatch
*,DISPID
,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
127 HRESULT
jsdisp_propput_name(DispatchEx
*,const WCHAR
*,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
128 HRESULT
jsdisp_propput_idx(DispatchEx
*,DWORD
,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
130 HRESULT
create_builtin_function(script_ctx_t
*,builtin_invoke_t
,DWORD
,DispatchEx
*,DispatchEx
**);
132 HRESULT
create_object(script_ctx_t
*,DispatchEx
*,DispatchEx
**);
133 HRESULT
create_math(script_ctx_t
*,DispatchEx
**);
134 HRESULT
create_array(script_ctx_t
*,DWORD
,DispatchEx
**);
135 HRESULT
create_regexp_str(script_ctx_t
*,const WCHAR
*,DWORD
,const WCHAR
*,DWORD
,DispatchEx
**);
136 HRESULT
create_string(script_ctx_t
*,const WCHAR
*,DWORD
,DispatchEx
**);
137 HRESULT
create_bool(script_ctx_t
*,VARIANT_BOOL
,DispatchEx
**);
138 HRESULT
create_number(script_ctx_t
*,VARIANT
*,DispatchEx
**);
140 HRESULT
to_primitive(script_ctx_t
*,VARIANT
*,jsexcept_t
*,VARIANT
*);
141 HRESULT
to_boolean(VARIANT
*,VARIANT_BOOL
*);
142 HRESULT
to_number(script_ctx_t
*,VARIANT
*,jsexcept_t
*,VARIANT
*);
143 HRESULT
to_int32(script_ctx_t
*,VARIANT
*,jsexcept_t
*,INT
*);
144 HRESULT
to_string(script_ctx_t
*,VARIANT
*,jsexcept_t
*,BSTR
*);
145 HRESULT
to_object(exec_ctx_t
*,VARIANT
*,IDispatch
**);
147 typedef struct named_item_t
{
151 struct named_item_t
*next
;
154 struct _script_ctx_t
{
158 exec_ctx_t
*exec_ctx
;
159 named_item_t
*named_items
;
164 DispatchEx
*script_disp
;
166 DispatchEx
*array_constr
;
167 DispatchEx
*bool_constr
;
168 DispatchEx
*number_constr
;
169 DispatchEx
*object_constr
;
170 DispatchEx
*regexp_constr
;
171 DispatchEx
*string_constr
;
174 void script_release(script_ctx_t
*);
176 static inline void script_addref(script_ctx_t
*ctx
)
181 HRESULT
init_global(script_ctx_t
*);
183 HRESULT
create_array_constr(script_ctx_t
*,DispatchEx
**);
184 HRESULT
create_bool_constr(script_ctx_t
*,DispatchEx
**);
185 HRESULT
create_number_constr(script_ctx_t
*,DispatchEx
**);
186 HRESULT
create_object_constr(script_ctx_t
*,DispatchEx
**);
187 HRESULT
create_regexp_constr(script_ctx_t
*,DispatchEx
**);
188 HRESULT
create_string_constr(script_ctx_t
*,DispatchEx
**);
195 HRESULT
regexp_match(DispatchEx
*,const WCHAR
*,DWORD
,BOOL
,match_result_t
**,DWORD
*);
197 static inline VARIANT
*get_arg(DISPPARAMS
*dp
, DWORD i
)
199 return dp
->rgvarg
+ dp
->cArgs
-i
-1;
202 static inline DWORD
arg_cnt(const DISPPARAMS
*dp
)
204 return dp
->cArgs
- dp
->cNamedArgs
;
207 const char *debugstr_variant(const VARIANT
*);
209 HRESULT WINAPI
JScriptFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**);
211 extern LONG module_ref
;
213 static inline void lock_module(void)
215 InterlockedIncrement(&module_ref
);
218 static inline void unlock_module(void)
220 InterlockedDecrement(&module_ref
);
223 static inline void *heap_alloc(size_t len
)
225 return HeapAlloc(GetProcessHeap(), 0, len
);
228 static inline void *heap_alloc_zero(size_t len
)
230 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
233 static inline void *heap_realloc(void *mem
, size_t len
)
235 return HeapReAlloc(GetProcessHeap(), 0, mem
, len
);
238 static inline BOOL
heap_free(void *mem
)
240 return HeapFree(GetProcessHeap(), 0, mem
);
243 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
250 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
251 ret
= heap_alloc(size
);
252 memcpy(ret
, str
, size
);
258 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))