xref: /reactos/dll/win32/jscript/jscript.h (revision d5399189)
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 typedef struct _property_desc_t property_desc_t;
56 
57 typedef struct {
58     void **blocks;
59     DWORD block_cnt;
60     DWORD last_block;
61     DWORD offset;
62     BOOL mark;
63     struct list custom_blocks;
64 } heap_pool_t;
65 
66 void heap_pool_init(heap_pool_t*) DECLSPEC_HIDDEN;
67 void *heap_pool_alloc(heap_pool_t*,DWORD) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN;
68 void *heap_pool_grow(heap_pool_t*,void*,DWORD,DWORD) DECLSPEC_HIDDEN;
69 void heap_pool_clear(heap_pool_t*) DECLSPEC_HIDDEN;
70 void heap_pool_free(heap_pool_t*) DECLSPEC_HIDDEN;
71 heap_pool_t *heap_pool_mark(heap_pool_t*) DECLSPEC_HIDDEN;
72 
73 static inline LPWSTR heap_strdupW(LPCWSTR str)
74 {
75     LPWSTR ret = NULL;
76 
77     if(str) {
78         DWORD size;
79 
80         size = (strlenW(str)+1)*sizeof(WCHAR);
81         ret = heap_alloc(size);
82         if(ret)
83             memcpy(ret, str, size);
84     }
85 
86     return ret;
87 }
88 
89 typedef struct jsdisp_t jsdisp_t;
90 
91 extern HINSTANCE jscript_hinstance DECLSPEC_HIDDEN;
92 
93 #define PROPF_ARGMASK       0x00ff
94 #define PROPF_METHOD        0x0100
95 #define PROPF_ENUMERABLE    0x0200
96 #define PROPF_CONSTR        0x0400
97 #define PROPF_WRITABLE      0x0800
98 #define PROPF_CONFIGURABLE  0x1000
99 
100 #define PROPF_VERSION_MASK  0x01ff0000
101 #define PROPF_VERSION_SHIFT 16
102 #define PROPF_HTML          (SCRIPTLANGUAGEVERSION_HTML << PROPF_VERSION_SHIFT)
103 #define PROPF_ES5           ((SCRIPTLANGUAGEVERSION_HTML|SCRIPTLANGUAGEVERSION_ES5) << PROPF_VERSION_SHIFT)
104 
105 /*
106  * This is our internal dispatch flag informing calee that it's called directly from interpreter.
107  * If calee is executed as interpreted function, we may let already running interpreter to take
108  * of execution.
109  */
110 #define DISPATCH_JSCRIPT_CALLEREXECSSOURCE  0x8000
111 #define DISPATCH_JSCRIPT_INTERNAL_MASK      DISPATCH_JSCRIPT_CALLEREXECSSOURCE
112 
113 /* NOTE: Keep in sync with names in Object.toString implementation */
114 typedef enum {
115     JSCLASS_NONE,
116     JSCLASS_ARRAY,
117     JSCLASS_BOOLEAN,
118     JSCLASS_DATE,
119     JSCLASS_ERROR,
120     JSCLASS_FUNCTION,
121     JSCLASS_GLOBAL,
122     JSCLASS_MATH,
123     JSCLASS_NUMBER,
124     JSCLASS_OBJECT,
125     JSCLASS_REGEXP,
126     JSCLASS_STRING,
127     JSCLASS_ARGUMENTS,
128     JSCLASS_VBARRAY,
129     JSCLASS_JSON
130 } jsclass_t;
131 
132 jsdisp_t *iface_to_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
133 
134 typedef struct {
135     union {
136         IDispatch *disp;
137         IDispatchEx *dispex;
138         jsdisp_t *jsdisp;
139     } u;
140     DWORD flags;
141 } vdisp_t;
142 
143 #define VDISP_DISPEX  0x0001
144 #define VDISP_JSDISP  0x0002
145 
146 static inline void vdisp_release(vdisp_t *vdisp)
147 {
148     IDispatch_Release(vdisp->u.disp);
149 }
150 
151 static inline BOOL is_jsdisp(vdisp_t *vdisp)
152 {
153     return (vdisp->flags & VDISP_JSDISP) != 0;
154 }
155 
156 static inline BOOL is_dispex(vdisp_t *vdisp)
157 {
158     return (vdisp->flags & VDISP_DISPEX) != 0;
159 }
160 
161 static inline void set_jsdisp(vdisp_t *vdisp, jsdisp_t *jsdisp)
162 {
163     vdisp->u.jsdisp = jsdisp;
164     vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
165     IDispatch_AddRef(vdisp->u.disp);
166 }
167 
168 static inline void set_disp(vdisp_t *vdisp, IDispatch *disp)
169 {
170     IDispatchEx *dispex;
171     jsdisp_t *jsdisp;
172     HRESULT hres;
173 
174     jsdisp = iface_to_jsdisp(disp);
175     if(jsdisp) {
176         vdisp->u.jsdisp = jsdisp;
177         vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
178         return;
179     }
180 
181     hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
182     if(SUCCEEDED(hres)) {
183         vdisp->u.dispex = dispex;
184         vdisp->flags = VDISP_DISPEX;
185         return;
186     }
187 
188     IDispatch_AddRef(disp);
189     vdisp->u.disp = disp;
190     vdisp->flags = 0;
191 }
192 
193 static inline jsdisp_t *get_jsdisp(vdisp_t *vdisp)
194 {
195     return is_jsdisp(vdisp) ? vdisp->u.jsdisp : NULL;
196 }
197 
198 typedef HRESULT (*builtin_invoke_t)(script_ctx_t*,vdisp_t*,WORD,unsigned,jsval_t*,jsval_t*);
199 typedef HRESULT (*builtin_getter_t)(script_ctx_t*,jsdisp_t*,jsval_t*);
200 typedef HRESULT (*builtin_setter_t)(script_ctx_t*,jsdisp_t*,jsval_t);
201 
202 HRESULT builtin_set_const(script_ctx_t*,jsdisp_t*,jsval_t) DECLSPEC_HIDDEN;
203 
204 typedef struct {
205     const WCHAR *name;
206     builtin_invoke_t invoke;
207     DWORD flags;
208     builtin_getter_t getter;
209     builtin_setter_t setter;
210 } builtin_prop_t;
211 
212 typedef struct {
213     jsclass_t class;
214     builtin_prop_t value_prop;
215     DWORD props_cnt;
216     const builtin_prop_t *props;
217     void (*destructor)(jsdisp_t*);
218     void (*on_put)(jsdisp_t*,const WCHAR*);
219     unsigned (*idx_length)(jsdisp_t*);
220     HRESULT (*idx_get)(jsdisp_t*,unsigned,jsval_t*);
221     HRESULT (*idx_put)(jsdisp_t*,unsigned,jsval_t);
222 } builtin_info_t;
223 
224 struct jsdisp_t {
225     IDispatchEx IDispatchEx_iface;
226 
227     LONG ref;
228 
229     DWORD buf_size;
230     DWORD prop_cnt;
231     dispex_prop_t *props;
232     script_ctx_t *ctx;
233 
234     jsdisp_t *prototype;
235 
236     const builtin_info_t *builtin_info;
237 };
238 
239 static inline IDispatch *to_disp(jsdisp_t *jsdisp)
240 {
241     return (IDispatch*)&jsdisp->IDispatchEx_iface;
242 }
243 
244 jsdisp_t *as_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
245 jsdisp_t *to_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
246 void jsdisp_free(jsdisp_t*) DECLSPEC_HIDDEN;
247 
248 #ifndef TRACE_REFCNT
249 
250 /*
251  * We do a lot of refcount calls during script execution, so having an inline
252  * version is a nice perf win. Define TRACE_REFCNT macro when debugging
253  * refcount bugs to have traces. Also, since jsdisp_t is not thread safe anyways,
254  * there is no point in using atomic operations.
255  */
256 static inline jsdisp_t *jsdisp_addref(jsdisp_t *jsdisp)
257 {
258     jsdisp->ref++;
259     return jsdisp;
260 }
261 
262 static inline void jsdisp_release(jsdisp_t *jsdisp)
263 {
264     if(!--jsdisp->ref)
265         jsdisp_free(jsdisp);
266 }
267 
268 #else
269 
270 jsdisp_t *jsdisp_addref(jsdisp_t*) DECLSPEC_HIDDEN;
271 void jsdisp_release(jsdisp_t*) DECLSPEC_HIDDEN;
272 
273 #endif
274 
275 HRESULT create_dispex(script_ctx_t*,const builtin_info_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
276 HRESULT init_dispex(jsdisp_t*,script_ctx_t*,const builtin_info_t*,jsdisp_t*) DECLSPEC_HIDDEN;
277 HRESULT init_dispex_from_constr(jsdisp_t*,script_ctx_t*,const builtin_info_t*,jsdisp_t*) DECLSPEC_HIDDEN;
278 
279 HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
280 HRESULT disp_call_value(script_ctx_t*,IDispatch*,IDispatch*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
281 HRESULT jsdisp_call_value(jsdisp_t*,IDispatch*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
282 HRESULT jsdisp_call(jsdisp_t*,DISPID,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
283 HRESULT jsdisp_call_name(jsdisp_t*,const WCHAR*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
284 HRESULT disp_propget(script_ctx_t*,IDispatch*,DISPID,jsval_t*) DECLSPEC_HIDDEN;
285 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,jsval_t) DECLSPEC_HIDDEN;
286 HRESULT jsdisp_propget(jsdisp_t*,DISPID,jsval_t*) DECLSPEC_HIDDEN;
287 HRESULT jsdisp_propput(jsdisp_t*,const WCHAR*,DWORD,jsval_t) DECLSPEC_HIDDEN;
288 HRESULT jsdisp_propput_name(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
289 HRESULT jsdisp_propput_idx(jsdisp_t*,DWORD,jsval_t) DECLSPEC_HIDDEN;
290 HRESULT jsdisp_propget_name(jsdisp_t*,LPCWSTR,jsval_t*) DECLSPEC_HIDDEN;
291 HRESULT jsdisp_get_idx(jsdisp_t*,DWORD,jsval_t*) DECLSPEC_HIDDEN;
292 HRESULT jsdisp_get_id(jsdisp_t*,const WCHAR*,DWORD,DISPID*) DECLSPEC_HIDDEN;
293 HRESULT disp_delete(IDispatch*,DISPID,BOOL*) DECLSPEC_HIDDEN;
294 HRESULT disp_delete_name(script_ctx_t*,IDispatch*,jsstr_t*,BOOL*) DECLSPEC_HIDDEN;
295 HRESULT jsdisp_delete_idx(jsdisp_t*,DWORD) DECLSPEC_HIDDEN;
296 HRESULT jsdisp_get_own_property(jsdisp_t*,const WCHAR*,BOOL,property_desc_t*) DECLSPEC_HIDDEN;
297 HRESULT jsdisp_define_property(jsdisp_t*,const WCHAR*,property_desc_t*) DECLSPEC_HIDDEN;
298 HRESULT jsdisp_define_data_property(jsdisp_t*,const WCHAR*,unsigned,jsval_t) 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 struct _property_desc_t {
382     unsigned flags;
383     unsigned mask;
384     BOOL explicit_value;
385     jsval_t value;
386     BOOL explicit_getter;
387     jsdisp_t *getter;
388     BOOL explicit_setter;
389     jsdisp_t *setter;
390 };
391 
392 typedef struct {
393     EXCEPINFO ei;
394     jsval_t val;
395 } jsexcept_t;
396 
397 typedef struct {
398     unsigned index;
399     unsigned length;
400 } match_result_t;
401 
402 struct _script_ctx_t {
403     LONG ref;
404 
405     SCRIPTSTATE state;
406     IActiveScript *active_script;
407 
408     struct _call_frame_t *call_ctx;
409     named_item_t *named_items;
410     IActiveScriptSite *site;
411     IInternetHostSecurityManager *secmgr;
412     DWORD safeopt;
413     DWORD version;
414     BOOL html_mode;
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 & 0xff) << 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 #define JS_E_NONCONFIGURABLE_REDEFINED MAKE_JSERROR(IDS_NONCONFIGURABLE_REDEFINED)
568 #define JS_E_NONWRITABLE_MODIFIED    MAKE_JSERROR(IDS_NONWRITABLE_MODIFIED)
569 #define JS_E_PROP_DESC_MISMATCH      MAKE_JSERROR(IDS_PROP_DESC_MISMATCH)
570 #define JS_E_INVALID_WRITABLE_PROP_DESC MAKE_JSERROR(IDS_INVALID_WRITABLE_PROP_DESC)
571 
572 static inline BOOL is_jscript_error(HRESULT hres)
573 {
574     return HRESULT_FACILITY(hres) == FACILITY_JSCRIPT;
575 }
576 
577 const char *debugstr_jsval(const jsval_t) DECLSPEC_HIDDEN;
578 
579 HRESULT create_jscript_object(BOOL,REFIID,void**) DECLSPEC_HIDDEN;
580 
581 extern LONG module_ref DECLSPEC_HIDDEN;
582 
583 static inline void lock_module(void)
584 {
585     InterlockedIncrement(&module_ref);
586 }
587 
588 static inline void unlock_module(void)
589 {
590     InterlockedDecrement(&module_ref);
591 }
592