2 * Copyright 2008 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
20 #include "wine/port.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
32 #define LONGLONG_MAX (((LONGLONG)0x7fffffff<<32)|0xffffffff)
34 static const WCHAR NaNW[] = {'N','a','N',0};
35 static const WCHAR InfinityW[] = {'I','n','f','i','n','i','t','y',0};
36 static const WCHAR ArrayW[] = {'A','r','r','a','y',0};
37 static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0};
38 static const WCHAR DateW[] = {'D','a','t','e',0};
39 static const WCHAR ErrorW[] = {'E','r','r','o','r',0};
40 static const WCHAR EvalErrorW[] = {'E','v','a','l','E','r','r','o','r',0};
41 static const WCHAR RangeErrorW[] = {'R','a','n','g','e','E','r','r','o','r',0};
42 static const WCHAR ReferenceErrorW[] = {'R','e','f','e','r','e','n','c','e','E','r','r','o','r',0};
43 static const WCHAR SyntaxErrorW[] = {'S','y','n','t','a','x','E','r','r','o','r',0};
44 static const WCHAR TypeErrorW[] = {'T','y','p','e','E','r','r','o','r',0};
45 static const WCHAR URIErrorW[] = {'U','R','I','E','r','r','o','r',0};
46 static const WCHAR FunctionW[] = {'F','u','n','c','t','i','o','n',0};
47 static const WCHAR NumberW[] = {'N','u','m','b','e','r',0};
48 static const WCHAR ObjectW[] = {'O','b','j','e','c','t',0};
49 static const WCHAR StringW[] = {'S','t','r','i','n','g',0};
50 static const WCHAR RegExpW[] = {'R','e','g','E','x','p',0};
51 static const WCHAR ActiveXObjectW[] = {'A','c','t','i','v','e','X','O','b','j','e','c','t',0};
52 static const WCHAR VBArrayW[] = {'V','B','A','r','r','a','y',0};
53 static const WCHAR EnumeratorW[] = {'E','n','u','m','e','r','a','t','o','r',0};
54 static const WCHAR escapeW[] = {'e','s','c','a','p','e',0};
55 static const WCHAR evalW[] = {'e','v','a','l',0};
56 static const WCHAR isNaNW[] = {'i','s','N','a','N',0};
57 static const WCHAR isFiniteW[] = {'i','s','F','i','n','i','t','e',0};
58 static const WCHAR parseIntW[] = {'p','a','r','s','e','I','n','t',0};
59 static const WCHAR parseFloatW[] = {'p','a','r','s','e','F','l','o','a','t',0};
60 static const WCHAR unescapeW[] = {'u','n','e','s','c','a','p','e',0};
61 static const WCHAR _GetObjectW[] = {'G','e','t','O','b','j','e','c','t',0};
62 static const WCHAR ScriptEngineW[] = {'S','c','r','i','p','t','E','n','g','i','n','e',0};
63 static const WCHAR ScriptEngineMajorVersionW[] =
64 {'S','c','r','i','p','t','E','n','g','i','n','e','M','a','j','o','r','V','e','r','s','i','o','n',0};
65 static const WCHAR ScriptEngineMinorVersionW[] =
66 {'S','c','r','i','p','t','E','n','g','i','n','e','M','i','n','o','r','V','e','r','s','i','o','n',0};
67 static const WCHAR ScriptEngineBuildVersionW[] =
68 {'S','c','r','i','p','t','E','n','g','i','n','e','B','u','i','l','d','V','e','r','s','i','o','n',0};
69 static const WCHAR CollectGarbageW[] = {'C','o','l','l','e','c','t','G','a','r','b','a','g','e',0};
70 static const WCHAR MathW[] = {'M','a','t','h',0};
71 static const WCHAR encodeURIW[] = {'e','n','c','o','d','e','U','R','I',0};
73 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
75 static int uri_char_table[] = {
76 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 00-0f */
77 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 10-1f */
78 0,2,0,0,1,0,1,2,2,2,2,1,1,2,2,1, /* 20-2f */
79 2,2,2,2,2,2,2,2,2,2,1,1,0,1,0,1, /* 30-3f */
80 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 40-4f */
81 2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,2, /* 50-5f */
82 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 60-6f */
83 2,2,2,2,2,2,2,2,2,2,2,0,0,0,2,0, /* 70-7f */
89 static inline BOOL is_uri_reserved(WCHAR c)
91 return c < 128 && uri_char_table[c] == 1;
94 static inline BOOL is_uri_unescaped(WCHAR c)
96 return c < 128 && uri_char_table[c] == 2;
99 static WCHAR int_to_char(int i)
106 static HRESULT constructor_call(DispatchEx *constr, WORD flags, DISPPARAMS *dp,
107 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
109 if(flags != DISPATCH_PROPERTYGET)
110 return jsdisp_call_value(constr, flags, dp, retv, ei, sp);
112 V_VT(retv) = VT_DISPATCH;
113 V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(constr);
114 IDispatchEx_AddRef(_IDispatchEx_(constr));
118 static HRESULT JSGlobal_NaN(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
119 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
124 case DISPATCH_PROPERTYGET:
129 FIXME("unimplemented flags %x\n", flags);
136 static HRESULT JSGlobal_Infinity(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
137 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
142 case DISPATCH_PROPERTYGET:
143 num_set_inf(retv, TRUE);
147 FIXME("unimplemented flags %x\n", flags);
154 static HRESULT JSGlobal_Array(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
155 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
159 return constructor_call(ctx->array_constr, flags, dp, retv, ei, sp);
162 static HRESULT JSGlobal_Boolean(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
163 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
167 return constructor_call(ctx->bool_constr, flags, dp, retv, ei, sp);
170 static HRESULT JSGlobal_Date(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
171 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
175 return constructor_call(ctx->date_constr, flags, dp, retv, ei, sp);
178 static HRESULT JSGlobal_Error(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
179 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
183 return constructor_call(ctx->error_constr, flags, dp, retv, ei, sp);
186 static HRESULT JSGlobal_EvalError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
187 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
191 return constructor_call(ctx->eval_error_constr, flags, dp, retv, ei, sp);
194 static HRESULT JSGlobal_RangeError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
195 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
199 return constructor_call(ctx->range_error_constr, flags, dp, retv, ei, sp);
202 static HRESULT JSGlobal_ReferenceError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
203 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
207 return constructor_call(ctx->reference_error_constr, flags, dp, retv, ei, sp);
210 static HRESULT JSGlobal_SyntaxError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
211 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
215 return constructor_call(ctx->syntax_error_constr, flags, dp, retv, ei, sp);
218 static HRESULT JSGlobal_TypeError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
219 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
223 return constructor_call(ctx->type_error_constr, flags, dp, retv, ei, sp);
226 static HRESULT JSGlobal_URIError(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
227 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
231 return constructor_call(ctx->uri_error_constr, flags, dp, retv, ei, sp);
234 static HRESULT JSGlobal_Function(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
235 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
239 return constructor_call(ctx->function_constr, flags, dp, retv, ei, sp);
242 static HRESULT JSGlobal_Number(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
243 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
247 return constructor_call(ctx->number_constr, flags, dp, retv, ei, sp);
250 static HRESULT JSGlobal_Object(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
251 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
255 return constructor_call(ctx->object_constr, flags, dp, retv, ei, sp);
258 static HRESULT JSGlobal_String(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
259 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
263 return constructor_call(ctx->string_constr, flags, dp, retv, ei, sp);
266 static HRESULT JSGlobal_RegExp(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
267 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
271 return constructor_call(ctx->regexp_constr, flags, dp, retv, ei, sp);
274 static HRESULT JSGlobal_ActiveXObject(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
275 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
279 return constructor_call(ctx->activex_constr, flags, dp, retv, ei, sp);
282 static HRESULT JSGlobal_VBArray(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
283 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
289 static HRESULT JSGlobal_Enumerator(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
290 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
296 static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
297 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
303 /* ECMA-262 3rd Edition 15.1.2.1 */
304 static HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
305 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
307 parser_ctx_t *parser_ctx;
315 V_VT(retv) = VT_EMPTY;
319 arg = get_arg(dp, 0);
320 if(V_VT(arg) != VT_BSTR) {
322 V_VT(retv) = VT_EMPTY;
323 return VariantCopy(retv, arg);
329 FIXME("No active exec_ctx\n");
333 TRACE("parsing %s\n", debugstr_w(V_BSTR(arg)));
334 hres = script_parse(ctx, V_BSTR(arg), NULL, &parser_ctx);
336 WARN("parse (%s) failed: %08x\n", debugstr_w(V_BSTR(arg)), hres);
337 return throw_syntax_error(ctx, ei, hres, NULL);
340 hres = exec_source(ctx->exec_ctx, parser_ctx, parser_ctx->source, ei, retv);
341 parser_release(parser_ctx);
346 static HRESULT JSGlobal_isNaN(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
347 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
349 VARIANT_BOOL ret = VARIANT_FALSE;
356 hres = to_number(ctx, get_arg(dp,0), ei, &num);
360 if(V_VT(&num) == VT_R8 && isnan(V_R8(&num)))
367 V_VT(retv) = VT_BOOL;
373 static HRESULT JSGlobal_isFinite(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
374 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
376 VARIANT_BOOL ret = VARIANT_FALSE;
384 hres = to_number(ctx, get_arg(dp,0), ei, &num);
388 if(V_VT(&num) != VT_R8 || (!isinf(V_R8(&num)) && !isnan(V_R8(&num))))
393 V_VT(retv) = VT_BOOL;
399 static INT char_to_int(WCHAR c)
401 if('0' <= c && c <= '9')
403 if('a' <= c && c <= 'z')
405 if('A' <= c && c <= 'Z')
410 static HRESULT JSGlobal_parseInt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
411 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
421 if(retv) num_set_nan(retv);
425 if(arg_cnt(dp) >= 2) {
426 hres = to_int32(ctx, get_arg(dp, 1), ei, &radix);
432 }else if(radix < 2 || radix > 36) {
433 WARN("radix %d out of range\n", radix);
438 hres = to_string(ctx, get_arg(dp, 0), ei, &str);
442 for(ptr = str; isspaceW(*ptr); ptr++);
454 if(*ptr == 'x' || *ptr == 'X') {
461 i = char_to_int(*ptr++);
474 num_set_val(retv, ret);
478 static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
479 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
486 BOOL ret_nan = TRUE, positive = TRUE;
495 arg = get_arg(dp, 0);
496 hres = to_string(ctx, arg, ei, &val_str);
501 length = SysStringLen(val_str);
503 while(isspaceW(*str)) str++;
507 else if(*str == '-') {
515 while(isdigitW(*str)) {
516 hlp = d*10 + *(str++) - '0';
517 if(d>LONGLONG_MAX/10 || hlp<0) {
524 while(isdigitW(*str)) {
529 if(*str == '.') str++;
534 while(isdigitW(*str)) {
535 hlp = d*10 + *(str++) - '0';
536 if(d>LONGLONG_MAX/10 || hlp<0)
542 while(isdigitW(*str))
545 if(*str && !ret_nan && (*str=='e' || *str=='E')) {
551 else if(*str == '-') {
556 while(isdigitW(*str)) {
557 if(e>INT_MAX/10 || (e = e*10 + *str++ - '0')<0)
562 if(exp<0 && e<0 && exp+e>0) exp = INT_MIN;
563 else if(exp>0 && e>0 && exp+e<0) exp = INT_MAX;
567 SysFreeString(val_str);
576 V_R8(retv) = (double)(positive?d:-d)*pow(10, exp);
580 static inline int hex_to_int(const WCHAR wch) {
581 if(toupperW(wch)>='A' && toupperW(wch)<='F') return toupperW(wch)-'A'+10;
582 if(isdigitW(wch)) return wch-'0';
586 static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
587 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
598 ret = SysAllocString(undefinedW);
600 return E_OUTOFMEMORY;
602 V_VT(retv) = VT_BSTR;
609 hres = to_string(ctx, get_arg(dp, 0), ei, &str);
613 for(ptr=str; *ptr; ptr++) {
615 if(hex_to_int(*(ptr+1))!=-1 && hex_to_int(*(ptr+2))!=-1)
617 else if(*(ptr+1)=='u' && hex_to_int(*(ptr+2))!=-1 && hex_to_int(*(ptr+3))!=-1
618 && hex_to_int(*(ptr+4))!=-1 && hex_to_int(*(ptr+5))!=-1)
625 ret = SysAllocStringLen(NULL, len);
627 return E_OUTOFMEMORY;
630 for(ptr=str; *ptr; ptr++) {
632 if(hex_to_int(*(ptr+1))!=-1 && hex_to_int(*(ptr+2))!=-1) {
633 ret[len] = (hex_to_int(*(ptr+1))<<4) + hex_to_int(*(ptr+2));
636 else if(*(ptr+1)=='u' && hex_to_int(*(ptr+2))!=-1 && hex_to_int(*(ptr+3))!=-1
637 && hex_to_int(*(ptr+4))!=-1 && hex_to_int(*(ptr+5))!=-1) {
638 ret[len] = (hex_to_int(*(ptr+2))<<12) + (hex_to_int(*(ptr+3))<<8)
639 + (hex_to_int(*(ptr+4))<<4) + hex_to_int(*(ptr+5));
652 V_VT(retv) = VT_BSTR;
661 static HRESULT JSGlobal_GetObject(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
662 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
668 static HRESULT JSGlobal_ScriptEngine(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
669 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
675 static HRESULT JSGlobal_ScriptEngineMajorVersion(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
676 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
682 static HRESULT JSGlobal_ScriptEngineMinorVersion(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
683 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
689 static HRESULT JSGlobal_ScriptEngineBuildVersion(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
690 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
696 static HRESULT JSGlobal_CollectGarbage(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
697 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
703 static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
704 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
717 ret = SysAllocString(undefinedW);
719 return E_OUTOFMEMORY;
721 V_VT(retv) = VT_BSTR;
728 hres = to_string(ctx, get_arg(dp,0), ei, &str);
732 for(ptr = str; *ptr; ptr++) {
733 if(is_uri_unescaped(*ptr) || is_uri_reserved(*ptr) || *ptr == '#') {
736 i = WideCharToMultiByte(CP_UTF8, 0, ptr, 1, NULL, 0, NULL, NULL)*3;
738 FIXME("throw URIError\n");
746 rptr = ret = SysAllocStringLen(NULL, len);
748 return E_OUTOFMEMORY;
750 for(ptr = str; *ptr; ptr++) {
751 if(is_uri_unescaped(*ptr) || is_uri_reserved(*ptr) || *ptr == '#') {
754 len = WideCharToMultiByte(CP_UTF8, 0, ptr, 1, buf, sizeof(buf), NULL, NULL);
755 for(i=0; i<len; i++) {
757 *rptr++ = int_to_char((BYTE)buf[i] >> 4);
758 *rptr++ = int_to_char(buf[i] & 0x0f);
763 TRACE("%s -> %s\n", debugstr_w(str), debugstr_w(ret));
765 V_VT(retv) = VT_BSTR;
773 static const builtin_prop_t JSGlobal_props[] = {
774 {ActiveXObjectW, JSGlobal_ActiveXObject, PROPF_CONSTR},
775 {ArrayW, JSGlobal_Array, PROPF_CONSTR},
776 {BooleanW, JSGlobal_Boolean, PROPF_CONSTR},
777 {CollectGarbageW, JSGlobal_CollectGarbage, PROPF_METHOD},
778 {DateW, JSGlobal_Date, PROPF_CONSTR},
779 {EnumeratorW, JSGlobal_Enumerator, PROPF_METHOD},
780 {ErrorW, JSGlobal_Error, PROPF_CONSTR},
781 {EvalErrorW, JSGlobal_EvalError, PROPF_CONSTR},
782 {FunctionW, JSGlobal_Function, PROPF_CONSTR},
783 {_GetObjectW, JSGlobal_GetObject, PROPF_METHOD},
784 {InfinityW, JSGlobal_Infinity, 0},
785 /* {MathW, JSGlobal_Math, 0}, */
786 {NaNW, JSGlobal_NaN, 0},
787 {NumberW, JSGlobal_Number, PROPF_CONSTR},
788 {ObjectW, JSGlobal_Object, PROPF_CONSTR},
789 {RangeErrorW, JSGlobal_RangeError, PROPF_CONSTR},
790 {ReferenceErrorW, JSGlobal_ReferenceError, PROPF_CONSTR},
791 {RegExpW, JSGlobal_RegExp, PROPF_CONSTR},
792 {ScriptEngineW, JSGlobal_ScriptEngine, PROPF_METHOD},
793 {ScriptEngineBuildVersionW, JSGlobal_ScriptEngineBuildVersion, PROPF_METHOD},
794 {ScriptEngineMajorVersionW, JSGlobal_ScriptEngineMajorVersion, PROPF_METHOD},
795 {ScriptEngineMinorVersionW, JSGlobal_ScriptEngineMinorVersion, PROPF_METHOD},
796 {StringW, JSGlobal_String, PROPF_CONSTR},
797 {SyntaxErrorW, JSGlobal_SyntaxError, PROPF_CONSTR},
798 {TypeErrorW, JSGlobal_TypeError, PROPF_CONSTR},
799 {URIErrorW, JSGlobal_URIError, PROPF_CONSTR},
800 {VBArrayW, JSGlobal_VBArray, PROPF_METHOD},
801 {encodeURIW, JSGlobal_encodeURI, PROPF_METHOD},
802 {escapeW, JSGlobal_escape, PROPF_METHOD},
803 {evalW, JSGlobal_eval, PROPF_METHOD|1},
804 {isFiniteW, JSGlobal_isFinite, PROPF_METHOD},
805 {isNaNW, JSGlobal_isNaN, PROPF_METHOD},
806 {parseFloatW, JSGlobal_parseFloat, PROPF_METHOD},
807 {parseIntW, JSGlobal_parseInt, PROPF_METHOD|2},
808 {unescapeW, JSGlobal_unescape, PROPF_METHOD}
811 static const builtin_info_t JSGlobal_info = {
814 sizeof(JSGlobal_props)/sizeof(*JSGlobal_props),
820 static HRESULT init_constructors(script_ctx_t *ctx, DispatchEx *object_prototype)
824 hres = init_function_constr(ctx, object_prototype);
828 hres = create_object_constr(ctx, object_prototype, &ctx->object_constr);
832 hres = create_activex_constr(ctx, &ctx->activex_constr);
836 hres = create_array_constr(ctx, object_prototype, &ctx->array_constr);
840 hres = create_bool_constr(ctx, object_prototype, &ctx->bool_constr);
844 hres = create_date_constr(ctx, object_prototype, &ctx->date_constr);
848 hres = init_error_constr(ctx, object_prototype);
852 hres = create_number_constr(ctx, object_prototype, &ctx->number_constr);
856 hres = create_regexp_constr(ctx, object_prototype, &ctx->regexp_constr);
860 hres = create_string_constr(ctx, object_prototype, &ctx->string_constr);
867 HRESULT init_global(script_ctx_t *ctx)
869 DispatchEx *math, *object_prototype;
876 hres = create_object_prototype(ctx, &object_prototype);
880 hres = init_constructors(ctx, object_prototype);
881 jsdisp_release(object_prototype);
885 hres = create_dispex(ctx, &JSGlobal_info, NULL, &ctx->global);
889 hres = create_math(ctx, &math);
893 V_VT(&var) = VT_DISPATCH;
894 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(math);
895 hres = jsdisp_propput_name(ctx->global, MathW, &var, NULL/*FIXME*/, NULL/*FIXME*/);
896 jsdisp_release(math);