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