[JSCRIPT] Sync with Wine Staging 1.9.16. CORE-11866
[reactos.git] / reactos / dll / win32 / jscript / jscript.h
1 /*
2 * Copyright 2008-2009 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 #ifndef _WINE_JSCRIPT_H
20 #define _WINE_JSCRIPT_H
21
22 #include <wine/config.h>
23 #include <wine/port.h>
24
25 #include <assert.h>
26 #include <stdarg.h>
27
28 #define WIN32_NO_STATUS
29 #define _INC_WINDOWS
30 #define COM_NO_WINDOWS_H
31
32 #define COBJMACROS
33
34 #include <windef.h>
35 #include <winbase.h>
36 #include <objbase.h>
37 #include <oleauto.h>
38 #include <dispex.h>
39 #include <activscp.h>
40 #include <objsafe.h>
41
42 #include <wine/debug.h>
43 #include <wine/list.h>
44 #include <wine/unicode.h>
45
46 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
47
48 #include "resource.h"
49
50 typedef struct _jsval_t jsval_t;
51 typedef struct _jsstr_t jsstr_t;
52 typedef struct _script_ctx_t script_ctx_t;
53 typedef struct _dispex_prop_t dispex_prop_t;
54
55 typedef struct {
56 void **blocks;
57 DWORD block_cnt;
58 DWORD last_block;
59 DWORD offset;
60 BOOL mark;
61 struct list custom_blocks;
62 } heap_pool_t;
63
64 void heap_pool_init(heap_pool_t*) DECLSPEC_HIDDEN;
65 void *heap_pool_alloc(heap_pool_t*,DWORD) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN;
66 void *heap_pool_grow(heap_pool_t*,void*,DWORD,DWORD) DECLSPEC_HIDDEN;
67 void heap_pool_clear(heap_pool_t*) DECLSPEC_HIDDEN;
68 void heap_pool_free(heap_pool_t*) DECLSPEC_HIDDEN;
69 heap_pool_t *heap_pool_mark(heap_pool_t*) DECLSPEC_HIDDEN;
70
71 static inline void *heap_alloc(size_t len)
72 {
73 return HeapAlloc(GetProcessHeap(), 0, len);
74 }
75
76 static inline void *heap_alloc_zero(size_t len)
77 {
78 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
79 }
80
81 static inline void *heap_realloc(void *mem, size_t len)
82 {
83 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
84 }
85
86 static inline BOOL heap_free(void *mem)
87 {
88 return HeapFree(GetProcessHeap(), 0, mem);
89 }
90
91 static inline LPWSTR heap_strdupW(LPCWSTR str)
92 {
93 LPWSTR ret = NULL;
94
95 if(str) {
96 DWORD size;
97
98 size = (strlenW(str)+1)*sizeof(WCHAR);
99 ret = heap_alloc(size);
100 if(ret)
101 memcpy(ret, str, size);
102 }
103
104 return ret;
105 }
106
107 typedef struct jsdisp_t jsdisp_t;
108
109 extern HINSTANCE jscript_hinstance DECLSPEC_HIDDEN;
110
111 #define PROPF_ARGMASK 0x00ff
112 #define PROPF_METHOD 0x0100
113 #define PROPF_ENUM 0x0200
114 #define PROPF_CONSTR 0x0400
115 #define PROPF_CONST 0x0800
116 #define PROPF_DONTDELETE 0x1000
117
118 /*
119 * This is our internal dispatch flag informing calee that it's called directly from interpreter.
120 * If calee is executed as interpreted function, we may let already running interpreter to take
121 * of execution.
122 */
123 #define DISPATCH_JSCRIPT_CALLEREXECSSOURCE 0x8000
124 #define DISPATCH_JSCRIPT_INTERNAL_MASK DISPATCH_JSCRIPT_CALLEREXECSSOURCE
125
126 /* NOTE: Keep in sync with names in Object.toString implementation */
127 typedef enum {
128 JSCLASS_NONE,
129 JSCLASS_ARRAY,
130 JSCLASS_BOOLEAN,
131 JSCLASS_DATE,
132 JSCLASS_ERROR,
133 JSCLASS_FUNCTION,
134 JSCLASS_GLOBAL,
135 JSCLASS_MATH,
136 JSCLASS_NUMBER,
137 JSCLASS_OBJECT,
138 JSCLASS_REGEXP,
139 JSCLASS_STRING,
140 JSCLASS_ARGUMENTS,
141 JSCLASS_VBARRAY,
142 JSCLASS_JSON
143 } jsclass_t;
144
145 jsdisp_t *iface_to_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
146
147 typedef struct {
148 union {
149 IDispatch *disp;
150 IDispatchEx *dispex;
151 jsdisp_t *jsdisp;
152 } u;
153 DWORD flags;
154 } vdisp_t;
155
156 #define VDISP_DISPEX 0x0001
157 #define VDISP_JSDISP 0x0002
158
159 static inline void vdisp_release(vdisp_t *vdisp)
160 {
161 IDispatch_Release(vdisp->u.disp);
162 }
163
164 static inline BOOL is_jsdisp(vdisp_t *vdisp)
165 {
166 return (vdisp->flags & VDISP_JSDISP) != 0;
167 }
168
169 static inline BOOL is_dispex(vdisp_t *vdisp)
170 {
171 return (vdisp->flags & VDISP_DISPEX) != 0;
172 }
173
174 static inline void set_jsdisp(vdisp_t *vdisp, jsdisp_t *jsdisp)
175 {
176 vdisp->u.jsdisp = jsdisp;
177 vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
178 IDispatch_AddRef(vdisp->u.disp);
179 }
180
181 static inline void set_disp(vdisp_t *vdisp, IDispatch *disp)
182 {
183 IDispatchEx *dispex;
184 jsdisp_t *jsdisp;
185 HRESULT hres;
186
187 jsdisp = iface_to_jsdisp(disp);
188 if(jsdisp) {
189 vdisp->u.jsdisp = jsdisp;
190 vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
191 return;
192 }
193
194 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
195 if(SUCCEEDED(hres)) {
196 vdisp->u.dispex = dispex;
197 vdisp->flags = VDISP_DISPEX;
198 return;
199 }
200
201 IDispatch_AddRef(disp);
202 vdisp->u.disp = disp;
203 vdisp->flags = 0;
204 }
205
206 static inline jsdisp_t *get_jsdisp(vdisp_t *vdisp)
207 {
208 return is_jsdisp(vdisp) ? vdisp->u.jsdisp : NULL;
209 }
210
211 typedef HRESULT (*builtin_invoke_t)(script_ctx_t*,vdisp_t*,WORD,unsigned,jsval_t*,jsval_t*);
212 typedef HRESULT (*builtin_getter_t)(script_ctx_t*,jsdisp_t*,jsval_t*);
213 typedef HRESULT (*builtin_setter_t)(script_ctx_t*,jsdisp_t*,jsval_t);
214
215 HRESULT builtin_set_const(script_ctx_t*,jsdisp_t*,jsval_t) DECLSPEC_HIDDEN;
216
217 typedef struct {
218 const WCHAR *name;
219 builtin_invoke_t invoke;
220 DWORD flags;
221 builtin_getter_t getter;
222 builtin_setter_t setter;
223 } builtin_prop_t;
224
225 typedef struct {
226 jsclass_t class;
227 builtin_prop_t value_prop;
228 DWORD props_cnt;
229 const builtin_prop_t *props;
230 void (*destructor)(jsdisp_t*);
231 void (*on_put)(jsdisp_t*,const WCHAR*);
232 unsigned (*idx_length)(jsdisp_t*);
233 HRESULT (*idx_get)(jsdisp_t*,unsigned,jsval_t*);
234 HRESULT (*idx_put)(jsdisp_t*,unsigned,jsval_t);
235 } builtin_info_t;
236
237 struct jsdisp_t {
238 IDispatchEx IDispatchEx_iface;
239
240 LONG ref;
241
242 DWORD buf_size;
243 DWORD prop_cnt;
244 dispex_prop_t *props;
245 script_ctx_t *ctx;
246
247 jsdisp_t *prototype;
248
249 const builtin_info_t *builtin_info;
250 };
251
252 static inline IDispatch *to_disp(jsdisp_t *jsdisp)
253 {
254 return (IDispatch*)&jsdisp->IDispatchEx_iface;
255 }
256
257 jsdisp_t *as_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
258 jsdisp_t *to_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
259 void jsdisp_free(jsdisp_t*) DECLSPEC_HIDDEN;
260
261 #ifndef TRACE_REFCNT
262
263 /*
264 * We do a lot of refcount calls during script execution, so having an inline
265 * version is a nice perf win. Define TRACE_REFCNT macro when debugging
266 * refcount bugs to have traces. Also, since jsdisp_t is not thread safe anyways,
267 * there is no point in using atomic operations.
268 */
269 static inline jsdisp_t *jsdisp_addref(jsdisp_t *jsdisp)
270 {
271 jsdisp->ref++;
272 return jsdisp;
273 }
274
275 static inline void jsdisp_release(jsdisp_t *jsdisp)
276 {
277 if(!--jsdisp->ref)
278 jsdisp_free(jsdisp);
279 }
280
281 #else
282
283 jsdisp_t *jsdisp_addref(jsdisp_t*) DECLSPEC_HIDDEN;
284 void jsdisp_release(jsdisp_t*) DECLSPEC_HIDDEN;
285
286 #endif
287
288 HRESULT create_dispex(script_ctx_t*,const builtin_info_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
289 HRESULT init_dispex(jsdisp_t*,script_ctx_t*,const builtin_info_t*,jsdisp_t*) DECLSPEC_HIDDEN;
290 HRESULT init_dispex_from_constr(jsdisp_t*,script_ctx_t*,const builtin_info_t*,jsdisp_t*) DECLSPEC_HIDDEN;
291
292 HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
293 HRESULT disp_call_value(script_ctx_t*,IDispatch*,IDispatch*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
294 HRESULT jsdisp_call_value(jsdisp_t*,IDispatch*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
295 HRESULT jsdisp_call(jsdisp_t*,DISPID,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
296 HRESULT jsdisp_call_name(jsdisp_t*,const WCHAR*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
297 HRESULT disp_propget(script_ctx_t*,IDispatch*,DISPID,jsval_t*) DECLSPEC_HIDDEN;
298 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,jsval_t) DECLSPEC_HIDDEN;
299 HRESULT jsdisp_propget(jsdisp_t*,DISPID,jsval_t*) DECLSPEC_HIDDEN;
300 HRESULT jsdisp_propput(jsdisp_t*,const WCHAR*,DWORD,jsval_t) DECLSPEC_HIDDEN;
301 HRESULT jsdisp_propput_name(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
302 HRESULT jsdisp_propput_const(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
303 HRESULT jsdisp_propput_dontenum(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
304 HRESULT jsdisp_propput_idx(jsdisp_t*,DWORD,jsval_t) DECLSPEC_HIDDEN;
305 HRESULT jsdisp_propget_name(jsdisp_t*,LPCWSTR,jsval_t*) DECLSPEC_HIDDEN;
306 HRESULT jsdisp_get_idx(jsdisp_t*,DWORD,jsval_t*) DECLSPEC_HIDDEN;
307 HRESULT jsdisp_get_id(jsdisp_t*,const WCHAR*,DWORD,DISPID*) DECLSPEC_HIDDEN;
308 HRESULT disp_delete(IDispatch*,DISPID,BOOL*) DECLSPEC_HIDDEN;
309 HRESULT disp_delete_name(script_ctx_t*,IDispatch*,jsstr_t*,BOOL*) DECLSPEC_HIDDEN;
310 HRESULT jsdisp_delete_idx(jsdisp_t*,DWORD) DECLSPEC_HIDDEN;
311 HRESULT jsdisp_is_own_prop(jsdisp_t*,const WCHAR*,BOOL*) DECLSPEC_HIDDEN;
312 HRESULT jsdisp_is_enumerable(jsdisp_t*,const WCHAR*,BOOL*) DECLSPEC_HIDDEN;
313
314 HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD,
315 jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
316 HRESULT create_builtin_constructor(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD,
317 jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
318 HRESULT Function_invoke(jsdisp_t*,IDispatch*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
319
320 HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
321 HRESULT Function_get_value(script_ctx_t*,jsdisp_t*,jsval_t*) DECLSPEC_HIDDEN;
322 #define DEFAULT_FUNCTION_VALUE {NULL, Function_value,0, Function_get_value}
323
324 HRESULT throw_eval_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
325 HRESULT throw_generic_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
326 HRESULT throw_range_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
327 HRESULT throw_reference_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
328 HRESULT throw_regexp_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
329 HRESULT throw_syntax_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
330 HRESULT throw_type_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
331 HRESULT throw_uri_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
332
333 HRESULT create_object(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
334 HRESULT create_math(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
335 HRESULT create_array(script_ctx_t*,DWORD,jsdisp_t**) DECLSPEC_HIDDEN;
336 HRESULT create_regexp(script_ctx_t*,jsstr_t*,DWORD,jsdisp_t**) DECLSPEC_HIDDEN;
337 HRESULT create_regexp_var(script_ctx_t*,jsval_t,jsval_t*,jsdisp_t**) DECLSPEC_HIDDEN;
338 HRESULT create_string(script_ctx_t*,jsstr_t*,jsdisp_t**) DECLSPEC_HIDDEN;
339 HRESULT create_bool(script_ctx_t*,BOOL,jsdisp_t**) DECLSPEC_HIDDEN;
340 HRESULT create_number(script_ctx_t*,double,jsdisp_t**) DECLSPEC_HIDDEN;
341 HRESULT create_vbarray(script_ctx_t*,SAFEARRAY*,jsdisp_t**) DECLSPEC_HIDDEN;
342 HRESULT create_json(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
343
344 typedef enum {
345 NO_HINT,
346 HINT_STRING,
347 HINT_NUMBER
348 } hint_t;
349
350 HRESULT to_primitive(script_ctx_t*,jsval_t,jsval_t*, hint_t) DECLSPEC_HIDDEN;
351 HRESULT to_boolean(jsval_t,BOOL*) DECLSPEC_HIDDEN;
352 HRESULT to_number(script_ctx_t*,jsval_t,double*) DECLSPEC_HIDDEN;
353 HRESULT to_integer(script_ctx_t*,jsval_t,double*) DECLSPEC_HIDDEN;
354 HRESULT to_int32(script_ctx_t*,jsval_t,INT*) DECLSPEC_HIDDEN;
355 HRESULT to_uint32(script_ctx_t*,jsval_t,UINT32*) DECLSPEC_HIDDEN;
356 HRESULT to_string(script_ctx_t*,jsval_t,jsstr_t**) DECLSPEC_HIDDEN;
357 HRESULT to_flat_string(script_ctx_t*,jsval_t,jsstr_t**,const WCHAR**) DECLSPEC_HIDDEN;
358 HRESULT to_object(script_ctx_t*,jsval_t,IDispatch**) DECLSPEC_HIDDEN;
359
360 HRESULT variant_change_type(script_ctx_t*,VARIANT*,VARIANT*,VARTYPE) DECLSPEC_HIDDEN;
361
362 HRESULT decode_source(WCHAR*) DECLSPEC_HIDDEN;
363
364 HRESULT double_to_string(double,jsstr_t**) DECLSPEC_HIDDEN;
365 BOOL is_finite(double) DECLSPEC_HIDDEN;
366
367 typedef struct named_item_t {
368 IDispatch *disp;
369 DWORD flags;
370 LPWSTR name;
371
372 struct named_item_t *next;
373 } named_item_t;
374
375 typedef struct _cc_var_t cc_var_t;
376
377 typedef struct {
378 cc_var_t *vars;
379 } cc_ctx_t;
380
381 void release_cc(cc_ctx_t*) DECLSPEC_HIDDEN;
382
383 typedef struct {
384 IServiceProvider IServiceProvider_iface;
385
386 LONG ref;
387
388 script_ctx_t *ctx;
389 } JSCaller;
390
391 #include "jsval.h"
392
393 typedef struct {
394 EXCEPINFO ei;
395 jsval_t val;
396 } jsexcept_t;
397
398 typedef struct {
399 unsigned index;
400 unsigned length;
401 } match_result_t;
402
403 struct _script_ctx_t {
404 LONG ref;
405
406 SCRIPTSTATE state;
407 IActiveScript *active_script;
408
409 struct _call_frame_t *call_ctx;
410 named_item_t *named_items;
411 IActiveScriptSite *site;
412 IInternetHostSecurityManager *secmgr;
413 DWORD safeopt;
414 DWORD version;
415 LCID lcid;
416 cc_ctx_t *cc;
417 JSCaller *jscaller;
418 jsexcept_t ei;
419
420 heap_pool_t tmp_heap;
421
422 IDispatch *host_global;
423
424 jsval_t *stack;
425 unsigned stack_size;
426 unsigned stack_top;
427
428 jsstr_t *last_match;
429 match_result_t match_parens[9];
430 DWORD last_match_index;
431 DWORD last_match_length;
432
433 jsdisp_t *global;
434 jsdisp_t *function_constr;
435 jsdisp_t *array_constr;
436 jsdisp_t *bool_constr;
437 jsdisp_t *date_constr;
438 jsdisp_t *error_constr;
439 jsdisp_t *eval_error_constr;
440 jsdisp_t *range_error_constr;
441 jsdisp_t *reference_error_constr;
442 jsdisp_t *regexp_error_constr;
443 jsdisp_t *syntax_error_constr;
444 jsdisp_t *type_error_constr;
445 jsdisp_t *uri_error_constr;
446 jsdisp_t *number_constr;
447 jsdisp_t *object_constr;
448 jsdisp_t *regexp_constr;
449 jsdisp_t *string_constr;
450 jsdisp_t *vbarray_constr;
451 };
452
453 void script_release(script_ctx_t*) DECLSPEC_HIDDEN;
454 void clear_ei(script_ctx_t*) DECLSPEC_HIDDEN;
455
456 static inline void script_addref(script_ctx_t *ctx)
457 {
458 ctx->ref++;
459 }
460
461 HRESULT init_global(script_ctx_t*) DECLSPEC_HIDDEN;
462 HRESULT init_function_constr(script_ctx_t*,jsdisp_t*) DECLSPEC_HIDDEN;
463 HRESULT create_object_prototype(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
464
465 HRESULT create_activex_constr(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
466 HRESULT create_array_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
467 HRESULT create_bool_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
468 HRESULT create_date_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
469 HRESULT init_error_constr(script_ctx_t*,jsdisp_t*) DECLSPEC_HIDDEN;
470 HRESULT create_number_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
471 HRESULT create_object_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
472 HRESULT create_regexp_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
473 HRESULT create_string_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
474 HRESULT create_vbarray_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
475
476 IUnknown *create_ax_site(script_ctx_t*) DECLSPEC_HIDDEN;
477 HRESULT create_jscaller(script_ctx_t*) DECLSPEC_HIDDEN;
478
479 #define REM_CHECK_GLOBAL 0x0001
480 #define REM_RESET_INDEX 0x0002
481 #define REM_NO_CTX_UPDATE 0x0004
482 #define REM_ALLOC_RESULT 0x0008
483 #define REM_NO_PARENS 0x0010
484 struct match_state_t;
485 HRESULT regexp_match_next(script_ctx_t*,jsdisp_t*,DWORD,jsstr_t*,struct match_state_t**) DECLSPEC_HIDDEN;
486 HRESULT parse_regexp_flags(const WCHAR*,DWORD,DWORD*) DECLSPEC_HIDDEN;
487 HRESULT regexp_string_match(script_ctx_t*,jsdisp_t*,jsstr_t*,jsval_t*) DECLSPEC_HIDDEN;
488
489 BOOL bool_obj_value(jsdisp_t*) DECLSPEC_HIDDEN;
490 unsigned array_get_length(jsdisp_t*) DECLSPEC_HIDDEN;
491
492 HRESULT JSGlobal_eval(script_ctx_t*,vdisp_t*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
493
494 static inline BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
495 {
496 return jsdisp->builtin_info->class == class;
497 }
498
499 static inline BOOL is_vclass(vdisp_t *vdisp, jsclass_t class)
500 {
501 return is_jsdisp(vdisp) && is_class(vdisp->u.jsdisp, class);
502 }
503
504 #ifndef INT32_MIN
505 #define INT32_MIN (-2147483647-1)
506 #endif
507
508 #ifndef INT32_MAX
509 #define INT32_MAX (2147483647)
510 #endif
511
512 static inline BOOL is_int32(double d)
513 {
514 return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
515 }
516
517 static inline DWORD make_grfdex(script_ctx_t *ctx, DWORD flags)
518 {
519 return (ctx->version << 28) | flags;
520 }
521
522 #define FACILITY_JSCRIPT 10
523
524 #define MAKE_JSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_JSCRIPT, code)
525
526 #define JS_E_TO_PRIMITIVE MAKE_JSERROR(IDS_TO_PRIMITIVE)
527 #define JS_E_INVALIDARG MAKE_JSERROR(IDS_INVALID_CALL_ARG)
528 #define JS_E_SUBSCRIPT_OUT_OF_RANGE MAKE_JSERROR(IDS_SUBSCRIPT_OUT_OF_RANGE)
529 #define JS_E_OBJECT_REQUIRED MAKE_JSERROR(IDS_OBJECT_REQUIRED)
530 #define JS_E_CANNOT_CREATE_OBJ MAKE_JSERROR(IDS_CREATE_OBJ_ERROR)
531 #define JS_E_INVALID_PROPERTY MAKE_JSERROR(IDS_NO_PROPERTY)
532 #define JS_E_INVALID_ACTION MAKE_JSERROR(IDS_UNSUPPORTED_ACTION)
533 #define JS_E_MISSING_ARG MAKE_JSERROR(IDS_ARG_NOT_OPT)
534 #define JS_E_SYNTAX MAKE_JSERROR(IDS_SYNTAX_ERROR)
535 #define JS_E_MISSING_SEMICOLON MAKE_JSERROR(IDS_SEMICOLON)
536 #define JS_E_MISSING_LBRACKET MAKE_JSERROR(IDS_LBRACKET)
537 #define JS_E_MISSING_RBRACKET MAKE_JSERROR(IDS_RBRACKET)
538 #define JS_E_EXPECTED_IDENTIFIER MAKE_JSERROR(IDS_EXPECTED_IDENTIFIER)
539 #define JS_E_EXPECTED_ASSIGN MAKE_JSERROR(IDS_EXPECTED_ASSIGN)
540 #define JS_E_INVALID_CHAR MAKE_JSERROR(IDS_INVALID_CHAR)
541 #define JS_E_UNTERMINATED_STRING MAKE_JSERROR(IDS_UNTERMINATED_STR)
542 #define JS_E_MISPLACED_RETURN MAKE_JSERROR(IDS_MISPLACED_RETURN)
543 #define JS_E_INVALID_BREAK MAKE_JSERROR(IDS_INVALID_BREAK)
544 #define JS_E_INVALID_CONTINUE MAKE_JSERROR(IDS_INVALID_CONTINUE)
545 #define JS_E_LABEL_REDEFINED MAKE_JSERROR(IDS_LABEL_REDEFINED)
546 #define JS_E_LABEL_NOT_FOUND MAKE_JSERROR(IDS_LABEL_NOT_FOUND)
547 #define JS_E_EXPECTED_CCEND MAKE_JSERROR(IDS_EXPECTED_CCEND)
548 #define JS_E_DISABLED_CC MAKE_JSERROR(IDS_DISABLED_CC)
549 #define JS_E_EXPECTED_AT MAKE_JSERROR(IDS_EXPECTED_AT)
550 #define JS_E_FUNCTION_EXPECTED MAKE_JSERROR(IDS_NOT_FUNC)
551 #define JS_E_DATE_EXPECTED MAKE_JSERROR(IDS_NOT_DATE)
552 #define JS_E_NUMBER_EXPECTED MAKE_JSERROR(IDS_NOT_NUM)
553 #define JS_E_OBJECT_EXPECTED MAKE_JSERROR(IDS_OBJECT_EXPECTED)
554 #define JS_E_ILLEGAL_ASSIGN MAKE_JSERROR(IDS_ILLEGAL_ASSIGN)
555 #define JS_E_UNDEFINED_VARIABLE MAKE_JSERROR(IDS_UNDEFINED)
556 #define JS_E_BOOLEAN_EXPECTED MAKE_JSERROR(IDS_NOT_BOOL)
557 #define JS_E_VBARRAY_EXPECTED MAKE_JSERROR(IDS_NOT_VBARRAY)
558 #define JS_E_INVALID_DELETE MAKE_JSERROR(IDS_INVALID_DELETE)
559 #define JS_E_JSCRIPT_EXPECTED MAKE_JSERROR(IDS_JSCRIPT_EXPECTED)
560 #define JS_E_REGEXP_SYNTAX MAKE_JSERROR(IDS_REGEXP_SYNTAX_ERROR)
561 #define JS_E_INVALID_URI_CODING MAKE_JSERROR(IDS_URI_INVALID_CODING)
562 #define JS_E_INVALID_URI_CHAR MAKE_JSERROR(IDS_URI_INVALID_CHAR)
563 #define JS_E_FRACTION_DIGITS_OUT_OF_RANGE MAKE_JSERROR(IDS_FRACTION_DIGITS_OUT_OF_RANGE)
564 #define JS_E_PRECISION_OUT_OF_RANGE MAKE_JSERROR(IDS_PRECISION_OUT_OF_RANGE)
565 #define JS_E_INVALID_LENGTH MAKE_JSERROR(IDS_INVALID_LENGTH)
566 #define JS_E_ARRAY_EXPECTED MAKE_JSERROR(IDS_ARRAY_EXPECTED)
567
568 static inline BOOL is_jscript_error(HRESULT hres)
569 {
570 return HRESULT_FACILITY(hres) == FACILITY_JSCRIPT;
571 }
572
573 const char *debugstr_jsval(const jsval_t) DECLSPEC_HIDDEN;
574
575 HRESULT create_jscript_object(BOOL,REFIID,void**) DECLSPEC_HIDDEN;
576
577 extern LONG module_ref DECLSPEC_HIDDEN;
578
579 static inline void lock_module(void)
580 {
581 InterlockedIncrement(&module_ref);
582 }
583
584 static inline void unlock_module(void)
585 {
586 InterlockedDecrement(&module_ref);
587 }
588
589 #include "engine.h"
590 #include "parser.h"
591 #include "regexp.h"
592
593 #endif /* _WINE_JSCRIPT_H */