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