msvcrt: Add declaration for _sc[w]printf to header.
[wine.git] / dlls / jscript / jscript.h
blob214adb21df9d69bbeda2af6c4089bd71e4f62f09
1 /*
2 * Copyright 2008-2009 Jacek Caban for CodeWeavers
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.
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.
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
19 #include <stdarg.h>
20 #include <stdio.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28 #include "dispex.h"
29 #include "activscp.h"
31 #include "resource.h"
33 #include "wine/unicode.h"
34 #include "wine/list.h"
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;
41 typedef struct {
42 void **blocks;
43 DWORD block_cnt;
44 DWORD last_block;
45 DWORD offset;
46 BOOL mark;
47 struct list custom_blocks;
48 } jsheap_t;
50 void jsheap_init(jsheap_t*) DECLSPEC_HIDDEN;
51 void *jsheap_alloc(jsheap_t*,DWORD) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN;
52 void *jsheap_grow(jsheap_t*,void*,DWORD,DWORD) DECLSPEC_HIDDEN;
53 void jsheap_clear(jsheap_t*) DECLSPEC_HIDDEN;
54 void jsheap_free(jsheap_t*) DECLSPEC_HIDDEN;
55 jsheap_t *jsheap_mark(jsheap_t*) DECLSPEC_HIDDEN;
57 typedef struct jsdisp_t jsdisp_t;
59 extern HINSTANCE jscript_hinstance DECLSPEC_HIDDEN;
61 #define PROPF_ARGMASK 0x00ff
62 #define PROPF_METHOD 0x0100
63 #define PROPF_ENUM 0x0200
64 #define PROPF_CONSTR 0x0400
65 #define PROPF_CONST 0x0800
67 /* NOTE: Keep in sync with names in Object.toString implementation */
68 typedef enum {
69 JSCLASS_NONE,
70 JSCLASS_ARRAY,
71 JSCLASS_BOOLEAN,
72 JSCLASS_DATE,
73 JSCLASS_ERROR,
74 JSCLASS_FUNCTION,
75 JSCLASS_GLOBAL,
76 JSCLASS_MATH,
77 JSCLASS_NUMBER,
78 JSCLASS_OBJECT,
79 JSCLASS_REGEXP,
80 JSCLASS_STRING,
81 JSCLASS_ARGUMENTS,
82 JSCLASS_VBARRAY
83 } jsclass_t;
85 jsdisp_t *iface_to_jsdisp(IUnknown*) DECLSPEC_HIDDEN;
87 typedef struct {
88 union {
89 IDispatch *disp;
90 IDispatchEx *dispex;
91 jsdisp_t *jsdisp;
92 } u;
93 DWORD flags;
94 } vdisp_t;
96 #define VDISP_DISPEX 0x0001
97 #define VDISP_JSDISP 0x0002
99 static inline void vdisp_release(vdisp_t *vdisp)
101 IDispatch_Release(vdisp->u.disp);
104 static inline BOOL is_jsdisp(vdisp_t *vdisp)
106 return (vdisp->flags & VDISP_JSDISP) != 0;
109 static inline BOOL is_dispex(vdisp_t *vdisp)
111 return (vdisp->flags & VDISP_DISPEX) != 0;
114 static inline void set_jsdisp(vdisp_t *vdisp, jsdisp_t *jsdisp)
116 vdisp->u.jsdisp = jsdisp;
117 vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
118 IDispatch_AddRef(vdisp->u.disp);
121 static inline void set_disp(vdisp_t *vdisp, IDispatch *disp)
123 IDispatchEx *dispex;
124 jsdisp_t *jsdisp;
125 HRESULT hres;
127 jsdisp = iface_to_jsdisp((IUnknown*)disp);
128 if(jsdisp) {
129 vdisp->u.jsdisp = jsdisp;
130 vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
131 return;
134 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
135 if(SUCCEEDED(hres)) {
136 vdisp->u.dispex = dispex;
137 vdisp->flags = VDISP_DISPEX;
138 return;
141 IDispatch_AddRef(disp);
142 vdisp->u.disp = disp;
143 vdisp->flags = 0;
146 static inline jsdisp_t *get_jsdisp(vdisp_t *vdisp)
148 return is_jsdisp(vdisp) ? vdisp->u.jsdisp : NULL;
151 typedef HRESULT (*builtin_invoke_t)(script_ctx_t*,vdisp_t*,WORD,unsigned,jsval_t*,jsval_t*);
153 typedef struct {
154 const WCHAR *name;
155 builtin_invoke_t invoke;
156 DWORD flags;
157 } builtin_prop_t;
159 typedef struct {
160 jsclass_t class;
161 builtin_prop_t value_prop;
162 DWORD props_cnt;
163 const builtin_prop_t *props;
164 void (*destructor)(jsdisp_t*);
165 void (*on_put)(jsdisp_t*,const WCHAR*);
166 } builtin_info_t;
168 struct jsdisp_t {
169 IDispatchEx IDispatchEx_iface;
171 LONG ref;
173 DWORD buf_size;
174 DWORD prop_cnt;
175 dispex_prop_t *props;
176 script_ctx_t *ctx;
178 jsdisp_t *prototype;
180 const builtin_info_t *builtin_info;
183 static inline IDispatch *to_disp(jsdisp_t *jsdisp)
185 return (IDispatch*)&jsdisp->IDispatchEx_iface;
188 jsdisp_t *as_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
189 jsdisp_t *to_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
191 static inline jsdisp_t *jsdisp_addref(jsdisp_t *jsdisp)
193 IDispatchEx_AddRef(&jsdisp->IDispatchEx_iface);
194 return jsdisp;
197 static inline void jsdisp_release(jsdisp_t *jsdisp)
199 IDispatchEx_Release(&jsdisp->IDispatchEx_iface);
202 HRESULT create_dispex(script_ctx_t*,const builtin_info_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
203 HRESULT init_dispex(jsdisp_t*,script_ctx_t*,const builtin_info_t*,jsdisp_t*) DECLSPEC_HIDDEN;
204 HRESULT init_dispex_from_constr(jsdisp_t*,script_ctx_t*,const builtin_info_t*,jsdisp_t*) DECLSPEC_HIDDEN;
206 HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
207 HRESULT disp_call_value(script_ctx_t*,IDispatch*,IDispatch*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
208 HRESULT jsdisp_call_value(jsdisp_t*,IDispatch*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
209 HRESULT jsdisp_call(jsdisp_t*,DISPID,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
210 HRESULT jsdisp_call_name(jsdisp_t*,const WCHAR*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
211 HRESULT disp_propget(script_ctx_t*,IDispatch*,DISPID,jsval_t*) DECLSPEC_HIDDEN;
212 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,jsval_t) DECLSPEC_HIDDEN;
213 HRESULT jsdisp_propget(jsdisp_t*,DISPID,jsval_t*) DECLSPEC_HIDDEN;
214 HRESULT jsdisp_propput_name(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
215 HRESULT jsdisp_propput_const(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
216 HRESULT jsdisp_propput_dontenum(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
217 HRESULT jsdisp_propput_idx(jsdisp_t*,DWORD,jsval_t) DECLSPEC_HIDDEN;
218 HRESULT jsdisp_propget_name(jsdisp_t*,LPCWSTR,jsval_t*) DECLSPEC_HIDDEN;
219 HRESULT jsdisp_get_idx(jsdisp_t*,DWORD,jsval_t*) DECLSPEC_HIDDEN;
220 HRESULT jsdisp_get_id(jsdisp_t*,const WCHAR*,DWORD,DISPID*) DECLSPEC_HIDDEN;
221 HRESULT jsdisp_delete_idx(jsdisp_t*,DWORD) DECLSPEC_HIDDEN;
222 HRESULT jsdisp_is_own_prop(jsdisp_t*,BSTR,BOOL*) DECLSPEC_HIDDEN;
224 HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD,
225 jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
226 HRESULT create_builtin_constructor(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD,
227 jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
228 HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
229 HRESULT Function_invoke(jsdisp_t*,IDispatch*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
231 HRESULT throw_eval_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
232 HRESULT throw_generic_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
233 HRESULT throw_range_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
234 HRESULT throw_reference_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
235 HRESULT throw_regexp_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
236 HRESULT throw_syntax_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
237 HRESULT throw_type_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
238 HRESULT throw_uri_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
240 HRESULT create_object(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
241 HRESULT create_math(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
242 HRESULT create_array(script_ctx_t*,DWORD,jsdisp_t**) DECLSPEC_HIDDEN;
243 HRESULT create_regexp(script_ctx_t*,const WCHAR *,int,DWORD,jsdisp_t**) DECLSPEC_HIDDEN;
244 HRESULT create_regexp_var(script_ctx_t*,jsval_t,jsval_t*,jsdisp_t**) DECLSPEC_HIDDEN;
245 HRESULT create_string(script_ctx_t*,const WCHAR*,DWORD,jsdisp_t**) DECLSPEC_HIDDEN;
246 HRESULT create_bool(script_ctx_t*,BOOL,jsdisp_t**) DECLSPEC_HIDDEN;
247 HRESULT create_number(script_ctx_t*,double,jsdisp_t**) DECLSPEC_HIDDEN;
248 HRESULT create_vbarray(script_ctx_t*,SAFEARRAY*,jsdisp_t**) DECLSPEC_HIDDEN;
250 typedef enum {
251 NO_HINT,
252 HINT_STRING,
253 HINT_NUMBER
254 } hint_t;
256 HRESULT to_primitive(script_ctx_t*,jsval_t,jsval_t*, hint_t) DECLSPEC_HIDDEN;
257 HRESULT to_boolean(jsval_t,BOOL*) DECLSPEC_HIDDEN;
258 HRESULT to_number(script_ctx_t*,jsval_t,double*) DECLSPEC_HIDDEN;
259 HRESULT to_integer(script_ctx_t*,jsval_t,double*) DECLSPEC_HIDDEN;
260 HRESULT to_int32(script_ctx_t*,jsval_t,INT*) DECLSPEC_HIDDEN;
261 HRESULT to_uint32(script_ctx_t*,jsval_t,DWORD*) DECLSPEC_HIDDEN;
262 HRESULT to_string(script_ctx_t*,jsval_t,BSTR*) DECLSPEC_HIDDEN;
263 HRESULT to_object(script_ctx_t*,jsval_t,IDispatch**) DECLSPEC_HIDDEN;
265 HRESULT variant_change_type(script_ctx_t*,VARIANT*,VARIANT*,VARTYPE) DECLSPEC_HIDDEN;
267 HRESULT decode_source(WCHAR*) DECLSPEC_HIDDEN;
269 HRESULT double_to_bstr(double,BSTR*) DECLSPEC_HIDDEN;
271 typedef struct named_item_t {
272 IDispatch *disp;
273 DWORD flags;
274 LPWSTR name;
276 struct named_item_t *next;
277 } named_item_t;
279 typedef struct _cc_var_t cc_var_t;
281 typedef struct {
282 cc_var_t *vars;
283 } cc_ctx_t;
285 void release_cc(cc_ctx_t*) DECLSPEC_HIDDEN;
287 typedef struct {
288 IServiceProvider IServiceProvider_iface;
290 LONG ref;
292 script_ctx_t *ctx;
293 } JSCaller;
295 #include "jsval.h"
297 typedef struct {
298 EXCEPINFO ei;
299 jsval_t val;
300 } jsexcept_t;
302 typedef struct {
303 const WCHAR *str;
304 DWORD len;
305 } match_result_t;
307 struct _script_ctx_t {
308 LONG ref;
310 SCRIPTSTATE state;
311 IActiveScript *active_script;
313 exec_ctx_t *exec_ctx;
314 named_item_t *named_items;
315 IActiveScriptSite *site;
316 IInternetHostSecurityManager *secmgr;
317 DWORD safeopt;
318 DWORD version;
319 LCID lcid;
320 cc_ctx_t *cc;
321 JSCaller *jscaller;
322 jsexcept_t ei;
324 jsheap_t tmp_heap;
326 IDispatch *host_global;
328 BSTR last_match;
329 match_result_t match_parens[9];
330 DWORD last_match_index;
331 DWORD last_match_length;
333 jsdisp_t *global;
334 jsdisp_t *function_constr;
335 jsdisp_t *activex_constr;
336 jsdisp_t *array_constr;
337 jsdisp_t *bool_constr;
338 jsdisp_t *date_constr;
339 jsdisp_t *error_constr;
340 jsdisp_t *eval_error_constr;
341 jsdisp_t *range_error_constr;
342 jsdisp_t *reference_error_constr;
343 jsdisp_t *regexp_error_constr;
344 jsdisp_t *syntax_error_constr;
345 jsdisp_t *type_error_constr;
346 jsdisp_t *uri_error_constr;
347 jsdisp_t *number_constr;
348 jsdisp_t *object_constr;
349 jsdisp_t *regexp_constr;
350 jsdisp_t *string_constr;
351 jsdisp_t *vbarray_constr;
354 void script_release(script_ctx_t*) DECLSPEC_HIDDEN;
355 void clear_ei(script_ctx_t*) DECLSPEC_HIDDEN;
357 static inline void script_addref(script_ctx_t *ctx)
359 ctx->ref++;
362 HRESULT init_global(script_ctx_t*) DECLSPEC_HIDDEN;
363 HRESULT init_function_constr(script_ctx_t*,jsdisp_t*) DECLSPEC_HIDDEN;
364 HRESULT create_object_prototype(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
366 HRESULT create_activex_constr(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
367 HRESULT create_array_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
368 HRESULT create_bool_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
369 HRESULT create_date_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
370 HRESULT init_error_constr(script_ctx_t*,jsdisp_t*) DECLSPEC_HIDDEN;
371 HRESULT create_number_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
372 HRESULT create_object_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
373 HRESULT create_regexp_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
374 HRESULT create_string_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
375 HRESULT create_vbarray_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
377 IUnknown *create_ax_site(script_ctx_t*) DECLSPEC_HIDDEN;
378 HRESULT create_jscaller(script_ctx_t*) DECLSPEC_HIDDEN;
380 #define REM_CHECK_GLOBAL 0x0001
381 #define REM_RESET_INDEX 0x0002
382 #define REM_NO_CTX_UPDATE 0x0004
383 HRESULT regexp_match_next(script_ctx_t*,jsdisp_t*,DWORD,const WCHAR*,DWORD,const WCHAR**,match_result_t**,
384 DWORD*,DWORD*,match_result_t*) DECLSPEC_HIDDEN;
385 HRESULT parse_regexp_flags(const WCHAR*,DWORD,DWORD*) DECLSPEC_HIDDEN;
386 HRESULT regexp_string_match(script_ctx_t*,jsdisp_t*,BSTR,jsval_t*) DECLSPEC_HIDDEN;
388 static inline BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
390 return jsdisp->builtin_info->class == class;
393 static inline BOOL is_vclass(vdisp_t *vdisp, jsclass_t class)
395 return is_jsdisp(vdisp) && is_class(vdisp->u.jsdisp, class);
398 #ifndef INT32_MIN
399 #define INT32_MIN (-2147483647-1)
400 #endif
402 #ifndef INT32_MAX
403 #define INT32_MAX (2147483647)
404 #endif
406 static inline BOOL is_int32(double d)
408 return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
411 static inline DWORD make_grfdex(script_ctx_t *ctx, DWORD flags)
413 return (ctx->version << 28) | flags;
416 #define FACILITY_JSCRIPT 10
418 #define MAKE_JSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_JSCRIPT, code)
420 #define JS_E_TO_PRIMITIVE MAKE_JSERROR(IDS_TO_PRIMITIVE)
421 #define JS_E_INVALIDARG MAKE_JSERROR(IDS_INVALID_CALL_ARG)
422 #define JS_E_SUBSCRIPT_OUT_OF_RANGE MAKE_JSERROR(IDS_SUBSCRIPT_OUT_OF_RANGE)
423 #define JS_E_OBJECT_REQUIRED MAKE_JSERROR(IDS_OBJECT_REQUIRED)
424 #define JS_E_CANNOT_CREATE_OBJ MAKE_JSERROR(IDS_CREATE_OBJ_ERROR)
425 #define JS_E_INVALID_PROPERTY MAKE_JSERROR(IDS_NO_PROPERTY)
426 #define JS_E_INVALID_ACTION MAKE_JSERROR(IDS_UNSUPPORTED_ACTION)
427 #define JS_E_MISSING_ARG MAKE_JSERROR(IDS_ARG_NOT_OPT)
428 #define JS_E_SYNTAX MAKE_JSERROR(IDS_SYNTAX_ERROR)
429 #define JS_E_MISSING_SEMICOLON MAKE_JSERROR(IDS_SEMICOLON)
430 #define JS_E_MISSING_LBRACKET MAKE_JSERROR(IDS_LBRACKET)
431 #define JS_E_MISSING_RBRACKET MAKE_JSERROR(IDS_RBRACKET)
432 #define JS_E_INVALID_CHAR MAKE_JSERROR(IDS_INVALID_CHAR)
433 #define JS_E_UNTERMINATED_STRING MAKE_JSERROR(IDS_UNTERMINATED_STR)
434 #define JS_E_INVALID_BREAK MAKE_JSERROR(IDS_INVALID_BREAK)
435 #define JS_E_INVALID_CONTINUE MAKE_JSERROR(IDS_INVALID_CONTINUE)
436 #define JS_E_LABEL_REDEFINED MAKE_JSERROR(IDS_LABEL_REDEFINED)
437 #define JS_E_LABEL_NOT_FOUND MAKE_JSERROR(IDS_LABEL_NOT_FOUND)
438 #define JS_E_DISABLED_CC MAKE_JSERROR(IDS_DISABLED_CC)
439 #define JS_E_FUNCTION_EXPECTED MAKE_JSERROR(IDS_NOT_FUNC)
440 #define JS_E_DATE_EXPECTED MAKE_JSERROR(IDS_NOT_DATE)
441 #define JS_E_NUMBER_EXPECTED MAKE_JSERROR(IDS_NOT_NUM)
442 #define JS_E_OBJECT_EXPECTED MAKE_JSERROR(IDS_OBJECT_EXPECTED)
443 #define JS_E_ILLEGAL_ASSIGN MAKE_JSERROR(IDS_ILLEGAL_ASSIGN)
444 #define JS_E_UNDEFINED_VARIABLE MAKE_JSERROR(IDS_UNDEFINED)
445 #define JS_E_BOOLEAN_EXPECTED MAKE_JSERROR(IDS_NOT_BOOL)
446 #define JS_E_VBARRAY_EXPECTED MAKE_JSERROR(IDS_NOT_VBARRAY)
447 #define JS_E_INVALID_DELETE MAKE_JSERROR(IDS_INVALID_DELETE)
448 #define JS_E_JSCRIPT_EXPECTED MAKE_JSERROR(IDS_JSCRIPT_EXPECTED)
449 #define JS_E_REGEXP_SYNTAX MAKE_JSERROR(IDS_REGEXP_SYNTAX_ERROR)
450 #define JS_E_INVALID_URI_CODING MAKE_JSERROR(IDS_URI_INVALID_CODING)
451 #define JS_E_INVALID_URI_CHAR MAKE_JSERROR(IDS_URI_INVALID_CHAR)
452 #define JS_E_FRACTION_DIGITS_OUT_OF_RANGE MAKE_JSERROR(IDS_FRACTION_DIGITS_OUT_OF_RANGE)
453 #define JS_E_PRECISION_OUT_OF_RANGE MAKE_JSERROR(IDS_PRECISION_OUT_OF_RANGE)
454 #define JS_E_INVALID_LENGTH MAKE_JSERROR(IDS_INVALID_LENGTH)
455 #define JS_E_ARRAY_EXPECTED MAKE_JSERROR(IDS_ARRAY_EXPECTED)
457 static inline BOOL is_jscript_error(HRESULT hres)
459 return HRESULT_FACILITY(hres) == FACILITY_JSCRIPT;
462 const char *debugstr_variant(const VARIANT*) DECLSPEC_HIDDEN;
463 const char *debugstr_jsval(const jsval_t) DECLSPEC_HIDDEN;
465 HRESULT create_jscript_object(BOOL,REFIID,void**) DECLSPEC_HIDDEN;
467 extern LONG module_ref DECLSPEC_HIDDEN;
469 static inline void lock_module(void)
471 InterlockedIncrement(&module_ref);
474 static inline void unlock_module(void)
476 InterlockedDecrement(&module_ref);
479 static inline void *heap_alloc(size_t len)
481 return HeapAlloc(GetProcessHeap(), 0, len);
484 static inline void *heap_alloc_zero(size_t len)
486 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
489 static inline void *heap_realloc(void *mem, size_t len)
491 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
494 static inline BOOL heap_free(void *mem)
496 return HeapFree(GetProcessHeap(), 0, mem);
499 static inline LPWSTR heap_strdupW(LPCWSTR str)
501 LPWSTR ret = NULL;
503 if(str) {
504 DWORD size;
506 size = (strlenW(str)+1)*sizeof(WCHAR);
507 ret = heap_alloc(size);
508 memcpy(ret, str, size);
511 return ret;