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