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