~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/jscript/jscript.h

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Copyright 2008 Jacek Caban for CodeWeavers
  3  *
  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.
  8  *
  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.
 13  *
 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
 17  */
 18 
 19 #include <stdarg.h>
 20 #include <stdio.h>
 21 
 22 #define COBJMACROS
 23 
 24 #include "windef.h"
 25 #include "winbase.h"
 26 #include "winuser.h"
 27 #include "ole2.h"
 28 #include "dispex.h"
 29 #include "activscp.h"
 30 
 31 #include "wine/unicode.h"
 32 #include "wine/list.h"
 33 
 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;
 37 
 38 typedef struct {
 39     EXCEPINFO ei;
 40     VARIANT var;
 41 } jsexcept_t;
 42 
 43 typedef struct {
 44     void **blocks;
 45     DWORD block_cnt;
 46     DWORD last_block;
 47     DWORD offset;
 48     BOOL mark;
 49     struct list custom_blocks;
 50 } jsheap_t;
 51 
 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*);
 58 
 59 typedef struct DispatchEx DispatchEx;
 60 
 61 #define PROPF_ARGMASK 0x00ff
 62 #define PROPF_METHOD  0x0100
 63 #define PROPF_ENUM    0x0200
 64 #define PROPF_CONSTR  0x0400
 65 
 66 typedef enum {
 67     JSCLASS_NONE,
 68     JSCLASS_ARRAY,
 69     JSCLASS_BOOLEAN,
 70     JSCLASS_DATE,
 71     JSCLASS_FUNCTION,
 72     JSCLASS_GLOBAL,
 73     JSCLASS_MATH,
 74     JSCLASS_NUMBER,
 75     JSCLASS_OBJECT,
 76     JSCLASS_REGEXP,
 77     JSCLASS_STRING
 78 } jsclass_t;
 79 
 80 typedef HRESULT (*builtin_invoke_t)(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
 81 
 82 typedef struct {
 83     const WCHAR *name;
 84     builtin_invoke_t invoke;
 85     DWORD flags;
 86 } builtin_prop_t;
 87 
 88 typedef struct {
 89     jsclass_t class;
 90     builtin_prop_t value_prop;
 91     DWORD props_cnt;
 92     const builtin_prop_t *props;
 93     void (*destructor)(DispatchEx*);
 94     void (*on_put)(DispatchEx*,const WCHAR*);
 95 } builtin_info_t;
 96 
 97 struct DispatchEx {
 98     const IDispatchExVtbl  *lpIDispatchExVtbl;
 99 
100     LONG ref;
101 
102     DWORD buf_size;
103     DWORD prop_cnt;
104     dispex_prop_t *props;
105     script_ctx_t *ctx;
106 
107     DispatchEx *prototype;
108 
109     const builtin_info_t *builtin_info;
110 };
111 
112 #define _IDispatchEx_(x) ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
113 
114 static inline void jsdisp_release(DispatchEx *jsdisp)
115 {
116     IDispatchEx_Release(_IDispatchEx_(jsdisp));
117 }
118 
119 HRESULT create_dispex(script_ctx_t*,const builtin_info_t*,DispatchEx*,DispatchEx**);
120 HRESULT init_dispex(DispatchEx*,script_ctx_t*,const builtin_info_t*,DispatchEx*);
121 HRESULT init_dispex_from_constr(DispatchEx*,script_ctx_t*,const builtin_info_t*,DispatchEx*);
122 DispatchEx *iface_to_jsdisp(IUnknown*);
123 
124 HRESULT disp_call(IDispatch*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
125 HRESULT jsdisp_call_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
126 HRESULT disp_propget(IDispatch*,DISPID,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
127 HRESULT disp_propput(IDispatch*,DISPID,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
128 HRESULT jsdisp_propget(DispatchEx*,DISPID,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
129 HRESULT jsdisp_propput_name(DispatchEx*,const WCHAR*,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
130 HRESULT jsdisp_propput_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
131 HRESULT jsdisp_propget_name(DispatchEx*,LPCWSTR,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
132 HRESULT jsdisp_propget_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
133 HRESULT jsdisp_get_id(DispatchEx*,const WCHAR*,DWORD,DISPID*);
134 
135 HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,DWORD,DispatchEx*,DispatchEx**);
136 
137 HRESULT create_object(script_ctx_t*,DispatchEx*,DispatchEx**);
138 HRESULT create_math(script_ctx_t*,DispatchEx**);
139 HRESULT create_array(script_ctx_t*,DWORD,DispatchEx**);
140 HRESULT create_regexp_str(script_ctx_t*,const WCHAR*,DWORD,const WCHAR*,DWORD,DispatchEx**);
141 HRESULT create_string(script_ctx_t*,const WCHAR*,DWORD,DispatchEx**);
142 HRESULT create_bool(script_ctx_t*,VARIANT_BOOL,DispatchEx**);
143 HRESULT create_number(script_ctx_t*,VARIANT*,DispatchEx**);
144 
145 HRESULT to_primitive(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*);
146 HRESULT to_boolean(VARIANT*,VARIANT_BOOL*);
147 HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*);
148 HRESULT to_integer(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*);
149 HRESULT to_int32(script_ctx_t*,VARIANT*,jsexcept_t*,INT*);
150 HRESULT to_uint32(script_ctx_t*,VARIANT*,jsexcept_t*,DWORD*);
151 HRESULT to_string(script_ctx_t*,VARIANT*,jsexcept_t*,BSTR*);
152 HRESULT to_object(exec_ctx_t*,VARIANT*,IDispatch**);
153 
154 typedef struct named_item_t {
155     IDispatch *disp;
156     DWORD flags;
157 
158     struct named_item_t *next;
159 } named_item_t;
160 
161 struct _script_ctx_t {
162     LONG ref;
163 
164     SCRIPTSTATE state;
165     exec_ctx_t *exec_ctx;
166     named_item_t *named_items;
167     LCID lcid;
168 
169     jsheap_t tmp_heap;
170 
171     DispatchEx *script_disp;
172     DispatchEx *global;
173     DispatchEx *function_constr;
174     DispatchEx *array_constr;
175     DispatchEx *bool_constr;
176     DispatchEx *date_constr;
177     DispatchEx *number_constr;
178     DispatchEx *object_constr;
179     DispatchEx *regexp_constr;
180     DispatchEx *string_constr;
181 };
182 
183 void script_release(script_ctx_t*);
184 
185 static inline void script_addref(script_ctx_t *ctx)
186 {
187     ctx->ref++;
188 }
189 
190 HRESULT init_global(script_ctx_t*);
191 HRESULT init_function_constr(script_ctx_t*);
192 
193 HRESULT create_array_constr(script_ctx_t*,DispatchEx**);
194 HRESULT create_bool_constr(script_ctx_t*,DispatchEx**);
195 HRESULT create_date_constr(script_ctx_t*,DispatchEx**);
196 HRESULT create_number_constr(script_ctx_t*,DispatchEx**);
197 HRESULT create_object_constr(script_ctx_t*,DispatchEx**);
198 HRESULT create_regexp_constr(script_ctx_t*,DispatchEx**);
199 HRESULT create_string_constr(script_ctx_t*,DispatchEx**);
200 
201 typedef struct {
202     const WCHAR *str;
203     DWORD len;
204 } match_result_t;
205 
206 HRESULT regexp_match_next(DispatchEx*,BOOL,const WCHAR*,DWORD,const WCHAR**,match_result_t**,
207         DWORD*,DWORD*,match_result_t*);
208 HRESULT regexp_match(DispatchEx*,const WCHAR*,DWORD,BOOL,match_result_t**,DWORD*);
209 
210 static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
211 {
212     return dp->rgvarg + dp->cArgs-i-1;
213 }
214 
215 static inline DWORD arg_cnt(const DISPPARAMS *dp)
216 {
217     return dp->cArgs - dp->cNamedArgs;
218 }
219 
220 static inline BOOL is_class(DispatchEx *jsdisp, jsclass_t class)
221 {
222     return jsdisp->builtin_info->class == class;
223 }
224 
225 static inline BOOL is_num_vt(enum VARENUM vt)
226 {
227     return vt == VT_I4 || vt == VT_R8;
228 }
229 
230 static inline DOUBLE num_val(const VARIANT *v)
231 {
232     return V_VT(v) == VT_I4 ? V_I4(v) : V_R8(v);
233 }
234 
235 static inline void num_set_val(VARIANT *v, DOUBLE d)
236 {
237     if(d == (DOUBLE)(INT)d) {
238         V_VT(v) = VT_I4;
239         V_I4(v) = d;
240     }else {
241         V_VT(v) = VT_R8;
242         V_R8(v) = d;
243     }
244 }
245 
246 static inline void num_set_nan(VARIANT *v)
247 {
248     V_VT(v) = VT_R8;
249 #ifdef NAN
250     V_R8(v) = NAN;
251 #else
252     V_UI8(v) = (ULONGLONG)0x7ff80000<<32;
253 #endif
254 }
255 
256 static inline void num_set_inf(VARIANT *v, BOOL positive)
257 {
258     V_VT(v) = VT_R8;
259 #ifdef INFINITY
260     V_R8(v) = positive ? INFINITY : -INFINITY;
261 #else
262     V_UI8(v) = (ULONGLONG)0x7ff00000<<32;
263     if(!positive)
264         V_R8(v) = -V_R8(v);
265 #endif
266 }
267 
268 const char *debugstr_variant(const VARIANT*);
269 
270 HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
271 
272 extern LONG module_ref;
273 
274 static inline void lock_module(void)
275 {
276     InterlockedIncrement(&module_ref);
277 }
278 
279 static inline void unlock_module(void)
280 {
281     InterlockedDecrement(&module_ref);
282 }
283 
284 static inline void *heap_alloc(size_t len)
285 {
286     return HeapAlloc(GetProcessHeap(), 0, len);
287 }
288 
289 static inline void *heap_alloc_zero(size_t len)
290 {
291     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
292 }
293 
294 static inline void *heap_realloc(void *mem, size_t len)
295 {
296     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
297 }
298 
299 static inline BOOL heap_free(void *mem)
300 {
301     return HeapFree(GetProcessHeap(), 0, mem);
302 }
303 
304 static inline LPWSTR heap_strdupW(LPCWSTR str)
305 {
306     LPWSTR ret = NULL;
307 
308     if(str) {
309         DWORD size;
310 
311         size = (strlenW(str)+1)*sizeof(WCHAR);
312         ret = heap_alloc(size);
313         memcpy(ret, str, size);
314     }
315 
316     return ret;
317 }
318 
319 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
320 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.