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