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
81 typedef HRESULT (*builtin_invoke_t
)(DispatchEx
*,LCID
,WORD
,DISPPARAMS
*,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
85 builtin_invoke_t invoke
;
91 builtin_prop_t value_prop
;
93 const builtin_prop_t
*props
;
94 void (*destructor
)(DispatchEx
*);
95 void (*on_put
)(DispatchEx
*,const WCHAR
*);
99 const IDispatchExVtbl
*lpIDispatchExVtbl
;
105 dispex_prop_t
*props
;
108 DispatchEx
*prototype
;
110 const builtin_info_t
*builtin_info
;
113 #define _IDispatchEx_(x) ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
115 static inline void jsdisp_release(DispatchEx
*jsdisp
)
117 IDispatchEx_Release(_IDispatchEx_(jsdisp
));
120 HRESULT
create_dispex(script_ctx_t
*,const builtin_info_t
*,DispatchEx
*,DispatchEx
**);
121 HRESULT
init_dispex(DispatchEx
*,script_ctx_t
*,const builtin_info_t
*,DispatchEx
*);
122 HRESULT
init_dispex_from_constr(DispatchEx
*,script_ctx_t
*,const builtin_info_t
*,DispatchEx
*);
123 DispatchEx
*iface_to_jsdisp(IUnknown
*);
125 HRESULT
disp_call(IDispatch
*,DISPID
,LCID
,WORD
,DISPPARAMS
*,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
126 HRESULT
jsdisp_call_value(DispatchEx
*,LCID
,WORD
,DISPPARAMS
*,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
127 HRESULT
jsdisp_call(DispatchEx
*,DISPID
,LCID
,WORD
,DISPPARAMS
*,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
128 HRESULT
disp_propget(IDispatch
*,DISPID
,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
129 HRESULT
disp_propput(IDispatch
*,DISPID
,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
130 HRESULT
jsdisp_propget(DispatchEx
*,DISPID
,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
131 HRESULT
jsdisp_propput_name(DispatchEx
*,const WCHAR
*,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
132 HRESULT
jsdisp_propput_idx(DispatchEx
*,DWORD
,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
133 HRESULT
jsdisp_propget_name(DispatchEx
*,LPCWSTR
,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
134 HRESULT
jsdisp_propget_idx(DispatchEx
*,DWORD
,LCID
,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
135 HRESULT
jsdisp_get_id(DispatchEx
*,const WCHAR
*,DWORD
,DISPID
*);
136 HRESULT
jsdisp_delete_idx(DispatchEx
*,DWORD
);
138 HRESULT
create_builtin_function(script_ctx_t
*,builtin_invoke_t
,const builtin_info_t
*,DWORD
,
139 DispatchEx
*,DispatchEx
**);
140 HRESULT
Function_value(DispatchEx
*,LCID
,WORD
,DISPPARAMS
*,VARIANT
*,jsexcept_t
*,IServiceProvider
*);
143 HRESULT
create_object(script_ctx_t
*,DispatchEx
*,DispatchEx
**);
144 HRESULT
create_math(script_ctx_t
*,DispatchEx
**);
145 HRESULT
create_array(script_ctx_t
*,DWORD
,DispatchEx
**);
146 HRESULT
create_regexp_str(script_ctx_t
*,const WCHAR
*,DWORD
,const WCHAR
*,DWORD
,DispatchEx
**);
147 HRESULT
create_string(script_ctx_t
*,const WCHAR
*,DWORD
,DispatchEx
**);
148 HRESULT
create_bool(script_ctx_t
*,VARIANT_BOOL
,DispatchEx
**);
149 HRESULT
create_number(script_ctx_t
*,VARIANT
*,DispatchEx
**);
157 HRESULT
to_primitive(script_ctx_t
*,VARIANT
*,jsexcept_t
*,VARIANT
*, hint_t
);
158 HRESULT
to_boolean(VARIANT
*,VARIANT_BOOL
*);
159 HRESULT
to_number(script_ctx_t
*,VARIANT
*,jsexcept_t
*,VARIANT
*);
160 HRESULT
to_integer(script_ctx_t
*,VARIANT
*,jsexcept_t
*,VARIANT
*);
161 HRESULT
to_int32(script_ctx_t
*,VARIANT
*,jsexcept_t
*,INT
*);
162 HRESULT
to_uint32(script_ctx_t
*,VARIANT
*,jsexcept_t
*,DWORD
*);
163 HRESULT
to_string(script_ctx_t
*,VARIANT
*,jsexcept_t
*,BSTR
*);
164 HRESULT
to_object(exec_ctx_t
*,VARIANT
*,IDispatch
**);
166 typedef struct named_item_t
{
171 struct named_item_t
*next
;
174 struct _script_ctx_t
{
178 exec_ctx_t
*exec_ctx
;
179 named_item_t
*named_items
;
180 IActiveScriptSite
*site
;
185 DispatchEx
*script_disp
;
187 DispatchEx
*function_constr
;
188 DispatchEx
*array_constr
;
189 DispatchEx
*bool_constr
;
190 DispatchEx
*date_constr
;
191 DispatchEx
*number_constr
;
192 DispatchEx
*object_constr
;
193 DispatchEx
*regexp_constr
;
194 DispatchEx
*string_constr
;
197 void script_release(script_ctx_t
*);
199 static inline void script_addref(script_ctx_t
*ctx
)
204 HRESULT
init_global(script_ctx_t
*);
205 HRESULT
init_function_constr(script_ctx_t
*,DispatchEx
*);
206 HRESULT
create_object_prototype(script_ctx_t
*,DispatchEx
**);
208 HRESULT
create_array_constr(script_ctx_t
*,DispatchEx
**);
209 HRESULT
create_bool_constr(script_ctx_t
*,DispatchEx
**);
210 HRESULT
create_date_constr(script_ctx_t
*,DispatchEx
**);
211 HRESULT
create_number_constr(script_ctx_t
*,DispatchEx
**);
212 HRESULT
create_object_constr(script_ctx_t
*,DispatchEx
*,DispatchEx
**);
213 HRESULT
create_regexp_constr(script_ctx_t
*,DispatchEx
**);
214 HRESULT
create_string_constr(script_ctx_t
*,DispatchEx
**);
221 HRESULT
regexp_match_next(DispatchEx
*,BOOL
,const WCHAR
*,DWORD
,const WCHAR
**,match_result_t
**,
222 DWORD
*,DWORD
*,match_result_t
*);
223 HRESULT
regexp_match(DispatchEx
*,const WCHAR
*,DWORD
,BOOL
,match_result_t
**,DWORD
*);
225 static inline VARIANT
*get_arg(DISPPARAMS
*dp
, DWORD i
)
227 return dp
->rgvarg
+ dp
->cArgs
-i
-1;
230 static inline DWORD
arg_cnt(const DISPPARAMS
*dp
)
232 return dp
->cArgs
- dp
->cNamedArgs
;
235 static inline BOOL
is_class(DispatchEx
*jsdisp
, jsclass_t
class)
237 return jsdisp
->builtin_info
->class == class;
240 static inline BOOL
is_num_vt(enum VARENUM vt
)
242 return vt
== VT_I4
|| vt
== VT_R8
;
245 static inline DOUBLE
num_val(const VARIANT
*v
)
247 return V_VT(v
) == VT_I4
? V_I4(v
) : V_R8(v
);
250 static inline void num_set_val(VARIANT
*v
, DOUBLE d
)
252 if(d
== (DOUBLE
)(INT
)d
) {
261 static inline void num_set_nan(VARIANT
*v
)
267 V_UI8(v
) = (ULONGLONG
)0x7ff80000<<32;
271 static inline DOUBLE
ret_nan()
278 static inline void num_set_inf(VARIANT
*v
, BOOL positive
)
282 V_R8(v
) = positive
? INFINITY
: -INFINITY
;
284 V_UI8(v
) = (ULONGLONG
)0x7ff00000<<32;
290 const char *debugstr_variant(const VARIANT
*);
292 HRESULT WINAPI
JScriptFactory_CreateInstance(IClassFactory
*,IUnknown
*,REFIID
,void**);
294 extern LONG module_ref
;
296 static inline void lock_module(void)
298 InterlockedIncrement(&module_ref
);
301 static inline void unlock_module(void)
303 InterlockedDecrement(&module_ref
);
306 static inline void *heap_alloc(size_t len
)
308 return HeapAlloc(GetProcessHeap(), 0, len
);
311 static inline void *heap_alloc_zero(size_t len
)
313 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
316 static inline void *heap_realloc(void *mem
, size_t len
)
318 return HeapReAlloc(GetProcessHeap(), 0, mem
, len
);
321 static inline BOOL
heap_free(void *mem
)
323 return HeapFree(GetProcessHeap(), 0, mem
);
326 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
333 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
334 ret
= heap_alloc(size
);
335 memcpy(ret
, str
, size
);
341 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))