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
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
30 static const WCHAR NaNW
[] = {'N','a','N',0};
31 static const WCHAR InfinityW
[] = {'I','n','f','i','n','i','t','y',0};
32 static const WCHAR ArrayW
[] = {'A','r','r','a','y',0};
33 static const WCHAR BooleanW
[] = {'B','o','o','l','e','a','n',0};
34 static const WCHAR DateW
[] = {'D','a','t','e',0};
35 static const WCHAR ErrorW
[] = {'E','r','r','o','r',0};
36 static const WCHAR EvalErrorW
[] = {'E','v','a','l','E','r','r','o','r',0};
37 static const WCHAR RangeErrorW
[] = {'R','a','n','g','e','E','r','r','o','r',0};
38 static const WCHAR ReferenceErrorW
[] = {'R','e','f','e','r','e','n','c','e','E','r','r','o','r',0};
39 static const WCHAR SyntaxErrorW
[] = {'S','y','n','t','a','x','E','r','r','o','r',0};
40 static const WCHAR TypeErrorW
[] = {'T','y','p','e','E','r','r','o','r',0};
41 static const WCHAR URIErrorW
[] = {'U','R','I','E','r','r','o','r',0};
42 static const WCHAR FunctionW
[] = {'F','u','n','c','t','i','o','n',0};
43 static const WCHAR NumberW
[] = {'N','u','m','b','e','r',0};
44 static const WCHAR ObjectW
[] = {'O','b','j','e','c','t',0};
45 static const WCHAR StringW
[] = {'S','t','r','i','n','g',0};
46 static const WCHAR RegExpW
[] = {'R','e','g','E','x','p',0};
47 static const WCHAR RegExpErrorW
[] = {'R','e','g','E','x','p','E','r','r','o','r',0};
48 static const WCHAR ActiveXObjectW
[] = {'A','c','t','i','v','e','X','O','b','j','e','c','t',0};
49 static const WCHAR VBArrayW
[] = {'V','B','A','r','r','a','y',0};
50 static const WCHAR EnumeratorW
[] = {'E','n','u','m','e','r','a','t','o','r',0};
51 static const WCHAR MathW
[] = {'M','a','t','h',0};
52 static const WCHAR JSONW
[] = {'J','S','O','N',0};
54 static const WCHAR undefinedW
[] = {'u','n','d','e','f','i','n','e','d',0};
56 static int uri_char_table
[] = {
57 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 00-0f */
58 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 10-1f */
59 0,2,0,0,1,0,1,2,2,2,2,1,1,2,2,1, /* 20-2f */
60 2,2,2,2,2,2,2,2,2,2,1,1,0,1,0,1, /* 30-3f */
61 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 40-4f */
62 2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,2, /* 50-5f */
63 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 60-6f */
64 2,2,2,2,2,2,2,2,2,2,2,0,0,0,2,0, /* 70-7f */
70 static inline BOOL
is_uri_reserved(WCHAR c
)
72 return c
< 128 && uri_char_table
[c
] == 1;
75 static inline BOOL
is_uri_unescaped(WCHAR c
)
77 return c
< 128 && uri_char_table
[c
] == 2;
80 /* Check that the character is one of the 69 non-blank characters as defined by ECMA-262 B.2.1 */
81 static inline BOOL
is_ecma_nonblank(const WCHAR c
)
83 return ((c
>= 'A' && c
<= 'Z') || (c
>= 'a' && c
<= 'z') || (c
>= '0' && c
<= '9') ||
84 c
== '@' || c
== '*' || c
== '_' || c
== '+' || c
== '-' || c
== '.' || c
== '/');
87 static WCHAR
int_to_char(int i
)
94 static HRESULT
JSGlobal_escape(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
97 jsstr_t
*ret_str
, *str
;
98 const WCHAR
*ptr
, *buf
;
107 *r
= jsval_string(jsstr_undefined());
111 hres
= to_flat_string(ctx
, argv
[0], &str
, &buf
);
115 for(ptr
= buf
; *ptr
; ptr
++) {
118 else if(is_ecma_nonblank(*ptr
))
124 ret_str
= jsstr_alloc_buf(len
, &ret
);
127 return E_OUTOFMEMORY
;
131 for(ptr
= buf
; *ptr
; ptr
++) {
135 ret
[len
++] = int_to_char(*ptr
>> 12);
136 ret
[len
++] = int_to_char((*ptr
>> 8) & 0xf);
137 ret
[len
++] = int_to_char((*ptr
>> 4) & 0xf);
138 ret
[len
++] = int_to_char(*ptr
& 0xf);
140 else if(is_ecma_nonblank(*ptr
))
144 ret
[len
++] = int_to_char(*ptr
>> 4);
145 ret
[len
++] = int_to_char(*ptr
& 0xf);
152 *r
= jsval_string(ret_str
);
154 jsstr_release(ret_str
);
158 /* ECMA-262 3rd Edition 15.1.2.1 */
159 HRESULT
JSGlobal_eval(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
162 call_frame_t
*frame
= ctx
->call_ctx
;
163 DWORD exec_flags
= EXEC_EVAL
;
172 *r
= jsval_undefined();
176 if(!is_string(argv
[0])) {
178 return jsval_copy(argv
[0], r
);
182 src
= jsstr_flatten(get_string(argv
[0]));
184 return E_OUTOFMEMORY
;
186 TRACE("parsing %s\n", debugstr_jsval(argv
[0]));
187 hres
= compile_script(ctx
, src
, 0, 0, NULL
, NULL
, TRUE
, FALSE
, frame
? frame
->bytecode
->named_item
: NULL
, &code
);
189 WARN("parse (%s) failed: %08x\n", debugstr_jsval(argv
[0]), hres
);
193 if(!frame
|| (frame
->flags
& EXEC_GLOBAL
))
194 exec_flags
|= EXEC_GLOBAL
;
195 if(flags
& DISPATCH_JSCRIPT_CALLEREXECSSOURCE
)
196 exec_flags
|= EXEC_RETURN_TO_INTERP
;
197 hres
= exec_source(ctx
, exec_flags
, code
, &code
->global_code
, frame
? frame
->scope
: NULL
,
198 frame
? frame
->this_obj
: NULL
, NULL
, 0, NULL
, r
);
199 release_bytecode(code
);
203 static HRESULT
JSGlobal_isNaN(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
213 hres
= to_number(ctx
, argv
[0], &n
);
222 *r
= jsval_bool(ret
);
226 static HRESULT
JSGlobal_isFinite(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
237 hres
= to_number(ctx
, argv
[0], &n
);
245 *r
= jsval_bool(ret
);
249 static INT
char_to_int(WCHAR c
)
251 if('0' <= c
&& c
<= '9')
253 if('a' <= c
&& c
<= 'z')
255 if('A' <= c
&& c
<= 'Z')
260 static HRESULT
JSGlobal_parseInt(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
263 BOOL neg
= FALSE
, empty
= TRUE
;
272 *r
= jsval_number(NAN
);
277 hres
= to_int32(ctx
, argv
[1], &radix
);
281 if(radix
&& (radix
< 2 || radix
> 36)) {
282 WARN("radix %d out of range\n", radix
);
284 *r
= jsval_number(NAN
);
289 hres
= to_flat_string(ctx
, argv
[0], &str
, &ptr
);
293 while(iswspace(*ptr
))
308 if(ptr
[1] == 'x' || ptr
[1] == 'X') {
319 }else if(radix
== 16 && *ptr
== '0' && (ptr
[1] == 'x' || ptr
[1] == 'X')) {
323 i
= char_to_int(*ptr
++);
327 i
= char_to_int(*ptr
++);
339 *r
= jsval_number(ret
);
343 static HRESULT
JSGlobal_parseFloat(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
350 BOOL ret_nan
= TRUE
, positive
= TRUE
;
355 *r
= jsval_number(NAN
);
359 TRACE("%s\n", debugstr_jsval(argv
[0]));
361 hres
= to_flat_string(ctx
, argv
[0], &val_str
, &str
);
365 while(iswspace(*str
)) str
++;
369 else if(*str
== '-') {
377 while(is_digit(*str
)) {
378 hlp
= d
*10 + *(str
++) - '0';
379 if(d
>MAXLONGLONG
/10 || hlp
<0) {
386 while(is_digit(*str
)) {
391 if(*str
== '.') str
++;
396 while(is_digit(*str
)) {
397 hlp
= d
*10 + *(str
++) - '0';
398 if(d
>MAXLONGLONG
/10 || hlp
<0)
404 while(is_digit(*str
))
407 if(*str
&& !ret_nan
&& (*str
=='e' || *str
=='E')) {
413 else if(*str
== '-') {
418 while(is_digit(*str
)) {
419 if(e
>INT_MAX
/10 || (e
= e
*10 + *str
++ - '0')<0)
424 if(exp
<0 && e
<0 && exp
+e
>0) exp
= INT_MIN
;
425 else if(exp
>0 && e
>0 && exp
+e
<0) exp
= INT_MAX
;
429 jsstr_release(val_str
);
433 *r
= jsval_number(NAN
);
440 *r
= jsval_number(exp
>0 ? d
*pow(10, exp
) : d
/pow(10, -exp
));
444 static inline int hex_to_int(const WCHAR wch
) {
445 if(towupper(wch
)>='A' && towupper(wch
)<='F') return towupper(wch
)-'A'+10;
446 if(is_digit(wch
)) return wch
-'0';
450 static HRESULT
JSGlobal_unescape(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
453 jsstr_t
*ret_str
, *str
;
454 const WCHAR
*ptr
, *buf
;
463 *r
= jsval_string(jsstr_undefined());
467 hres
= to_flat_string(ctx
, argv
[0], &str
, &buf
);
471 for(ptr
= buf
; *ptr
; ptr
++) {
473 if(hex_to_int(*(ptr
+1))!=-1 && hex_to_int(*(ptr
+2))!=-1)
475 else if(*(ptr
+1)=='u' && hex_to_int(*(ptr
+2))!=-1 && hex_to_int(*(ptr
+3))!=-1
476 && hex_to_int(*(ptr
+4))!=-1 && hex_to_int(*(ptr
+5))!=-1)
483 ret_str
= jsstr_alloc_buf(len
, &ret
);
486 return E_OUTOFMEMORY
;
490 for(ptr
= buf
; *ptr
; ptr
++) {
492 if(hex_to_int(*(ptr
+1))!=-1 && hex_to_int(*(ptr
+2))!=-1) {
493 ret
[len
] = (hex_to_int(*(ptr
+1))<<4) + hex_to_int(*(ptr
+2));
496 else if(*(ptr
+1)=='u' && hex_to_int(*(ptr
+2))!=-1 && hex_to_int(*(ptr
+3))!=-1
497 && hex_to_int(*(ptr
+4))!=-1 && hex_to_int(*(ptr
+5))!=-1) {
498 ret
[len
] = (hex_to_int(*(ptr
+2))<<12) + (hex_to_int(*(ptr
+3))<<8)
499 + (hex_to_int(*(ptr
+4))<<4) + hex_to_int(*(ptr
+5));
514 *r
= jsval_string(ret_str
);
516 jsstr_release(ret_str
);
520 static HRESULT
JSGlobal_GetObject(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
527 static HRESULT
JSGlobal_ScriptEngine(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
530 static const WCHAR JScriptW
[] = {'J','S','c','r','i','p','t',0};
537 ret
= jsstr_alloc(JScriptW
);
539 return E_OUTOFMEMORY
;
541 *r
= jsval_string(ret
);
547 static HRESULT
JSGlobal_ScriptEngineMajorVersion(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
553 *r
= jsval_number(JSCRIPT_MAJOR_VERSION
);
557 static HRESULT
JSGlobal_ScriptEngineMinorVersion(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
563 *r
= jsval_number(JSCRIPT_MINOR_VERSION
);
567 static HRESULT
JSGlobal_ScriptEngineBuildVersion(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
573 *r
= jsval_number(JSCRIPT_BUILD_VERSION
);
577 static HRESULT
JSGlobal_CollectGarbage(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
586 static HRESULT
JSGlobal_encodeURI(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
589 const WCHAR
*ptr
, *uri
;
600 *r
= jsval_string(jsstr_undefined());
604 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
608 for(ptr
= uri
; *ptr
; ptr
++) {
609 if(is_uri_unescaped(*ptr
) || is_uri_reserved(*ptr
) || *ptr
== '#') {
612 i
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, NULL
, 0, NULL
, NULL
)*3;
615 return JS_E_INVALID_URI_CHAR
;
622 ret
= jsstr_alloc_buf(len
, &rptr
);
625 return E_OUTOFMEMORY
;
628 for(ptr
= uri
; *ptr
; ptr
++) {
629 if(is_uri_unescaped(*ptr
) || is_uri_reserved(*ptr
) || *ptr
== '#') {
632 len
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, buf
, sizeof(buf
), NULL
, NULL
);
633 for(i
=0; i
<len
; i
++) {
635 *rptr
++ = int_to_char((BYTE
)buf
[i
] >> 4);
636 *rptr
++ = int_to_char(buf
[i
] & 0x0f);
641 TRACE("%s -> %s\n", debugstr_jsstr(str
), debugstr_jsstr(ret
));
645 *r
= jsval_string(ret
);
651 static HRESULT
JSGlobal_decodeURI(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
654 const WCHAR
*ptr
, *uri
;
655 jsstr_t
*str
, *ret_str
;
667 *r
= jsval_string(jsstr_undefined());
671 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
675 for(ptr
= uri
; *ptr
; ptr
++) {
681 if(ptr
[i
*3]!='%' || hex_to_int(ptr
[i
*3+1])==-1 || (val
=hex_to_int(ptr
[i
*3+2]))==-1)
683 val
+= hex_to_int(ptr
[i
*3+1])<<4;
686 res
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, buf
, i
+1, &out
, 1);
693 return JS_E_INVALID_URI_CODING
;
701 ret_str
= jsstr_alloc_buf(len
, &ret
);
704 return E_OUTOFMEMORY
;
707 for(ptr
= uri
; *ptr
; ptr
++) {
712 if(ptr
[i
*3]!='%' || hex_to_int(ptr
[i
*3+1])==-1 || (val
=hex_to_int(ptr
[i
*3+2]))==-1)
714 val
+= hex_to_int(ptr
[i
*3+1])<<4;
717 res
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, buf
, i
+1, ret
, 1);
727 TRACE("%s -> %s\n", debugstr_jsstr(str
), debugstr_jsstr(ret_str
));
731 *r
= jsval_string(ret_str
);
733 jsstr_release(ret_str
);
737 static HRESULT
JSGlobal_encodeURIComponent(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
740 jsstr_t
*str
, *ret_str
;
742 const WCHAR
*ptr
, *uri
;
743 DWORD len
= 0, size
, i
;
751 *r
= jsval_string(jsstr_undefined());
755 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
759 for(ptr
= uri
; *ptr
; ptr
++) {
760 if(is_uri_unescaped(*ptr
))
763 size
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, NULL
, 0, NULL
, NULL
);
766 return JS_E_INVALID_URI_CHAR
;
772 ret_str
= jsstr_alloc_buf(len
, &ret
);
775 return E_OUTOFMEMORY
;
778 for(ptr
= uri
; *ptr
; ptr
++) {
779 if(is_uri_unescaped(*ptr
)) {
782 size
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, buf
, sizeof(buf
), NULL
, NULL
);
783 for(i
=0; i
<size
; i
++) {
785 *ret
++ = int_to_char((BYTE
)buf
[i
] >> 4);
786 *ret
++ = int_to_char(buf
[i
] & 0x0f);
794 *r
= jsval_string(ret_str
);
796 jsstr_release(ret_str
);
800 /* ECMA-262 3rd Edition 15.1.3.2 */
801 static HRESULT
JSGlobal_decodeURIComponent(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
804 const WCHAR
*ptr
, *uri
;
814 *r
= jsval_string(jsstr_undefined());
818 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
826 unsigned char mask
= 0x80;
827 int i
, size
, num_bytes
= 0;
828 if(hex_to_int(*(ptr
+1)) < 0 || hex_to_int(*(ptr
+2)) < 0) {
829 FIXME("Throw URIError: Invalid hex sequence\n");
833 octets
[0] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
835 while(octets
[0] & mask
) {
839 if(num_bytes
== 1 || num_bytes
> 4) {
840 FIXME("Throw URIError: Invalid initial UTF character\n");
844 for(i
= 1; i
< num_bytes
; ++i
) {
846 FIXME("Throw URIError: Incomplete UTF sequence\n");
850 if(hex_to_int(*(ptr
+1)) < 0 || hex_to_int(*(ptr
+2)) < 0) {
851 FIXME("Throw URIError: Invalid hex sequence\n");
855 octets
[i
] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
858 size
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, octets
,
859 num_bytes
? num_bytes
: 1, NULL
, 0);
861 FIXME("Throw URIError: Invalid UTF sequence\n");
872 ret
= jsstr_alloc_buf(len
, &out_ptr
);
875 return E_OUTOFMEMORY
;
882 unsigned char mask
= 0x80;
883 int i
, size
, num_bytes
= 0;
884 octets
[0] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
886 while(octets
[0] & mask
) {
890 for(i
= 1; i
< num_bytes
; ++i
) {
891 octets
[i
] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
894 size
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, octets
,
895 num_bytes
? num_bytes
: 1, out_ptr
, len
);
907 *r
= jsval_string(ret
);
913 static const builtin_prop_t JSGlobal_props
[] = {
914 {L
"CollectGarbage", JSGlobal_CollectGarbage
, PROPF_METHOD
},
915 {L
"GetObject", JSGlobal_GetObject
, PROPF_METHOD
|2},
916 {L
"ScriptEngine", JSGlobal_ScriptEngine
, PROPF_METHOD
},
917 {L
"ScriptEngineBuildVersion", JSGlobal_ScriptEngineBuildVersion
, PROPF_METHOD
},
918 {L
"ScriptEngineMajorVersion", JSGlobal_ScriptEngineMajorVersion
, PROPF_METHOD
},
919 {L
"ScriptEngineMinorVersion", JSGlobal_ScriptEngineMinorVersion
, PROPF_METHOD
},
920 {L
"decodeURI", JSGlobal_decodeURI
, PROPF_METHOD
|1},
921 {L
"decodeURIComponent", JSGlobal_decodeURIComponent
, PROPF_METHOD
|1},
922 {L
"encodeURI", JSGlobal_encodeURI
, PROPF_METHOD
|1},
923 {L
"encodeURIComponent", JSGlobal_encodeURIComponent
, PROPF_METHOD
|1},
924 {L
"escape", JSGlobal_escape
, PROPF_METHOD
|1},
925 {L
"eval", JSGlobal_eval
, PROPF_METHOD
|1},
926 {L
"isFinite", JSGlobal_isFinite
, PROPF_METHOD
|1},
927 {L
"isNaN", JSGlobal_isNaN
, PROPF_METHOD
|1},
928 {L
"parseFloat", JSGlobal_parseFloat
, PROPF_METHOD
|1},
929 {L
"parseInt", JSGlobal_parseInt
, PROPF_METHOD
|2},
930 {L
"unescape", JSGlobal_unescape
, PROPF_METHOD
|1}
933 static const builtin_info_t JSGlobal_info
= {
936 ARRAY_SIZE(JSGlobal_props
),
942 static HRESULT
init_constructors(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
)
946 hres
= init_function_constr(ctx
, object_prototype
);
950 hres
= jsdisp_define_data_property(ctx
->global
, FunctionW
, PROPF_WRITABLE
,
951 jsval_obj(ctx
->function_constr
));
955 hres
= create_object_constr(ctx
, object_prototype
, &ctx
->object_constr
);
959 hres
= jsdisp_define_data_property(ctx
->global
, ObjectW
, PROPF_WRITABLE
,
960 jsval_obj(ctx
->object_constr
));
964 hres
= create_array_constr(ctx
, object_prototype
, &ctx
->array_constr
);
968 hres
= jsdisp_define_data_property(ctx
->global
, ArrayW
, PROPF_WRITABLE
,
969 jsval_obj(ctx
->array_constr
));
973 hres
= create_bool_constr(ctx
, object_prototype
, &ctx
->bool_constr
);
977 hres
= jsdisp_define_data_property(ctx
->global
, BooleanW
, PROPF_WRITABLE
,
978 jsval_obj(ctx
->bool_constr
));
982 hres
= create_date_constr(ctx
, object_prototype
, &ctx
->date_constr
);
986 hres
= jsdisp_define_data_property(ctx
->global
, DateW
, PROPF_WRITABLE
,
987 jsval_obj(ctx
->date_constr
));
991 hres
= create_enumerator_constr(ctx
, object_prototype
, &ctx
->enumerator_constr
);
995 hres
= jsdisp_define_data_property(ctx
->global
, EnumeratorW
, PROPF_WRITABLE
,
996 jsval_obj(ctx
->enumerator_constr
));
1000 hres
= init_error_constr(ctx
, object_prototype
);
1004 hres
= jsdisp_define_data_property(ctx
->global
, ErrorW
, PROPF_WRITABLE
,
1005 jsval_obj(ctx
->error_constr
));
1009 hres
= jsdisp_define_data_property(ctx
->global
, EvalErrorW
, PROPF_WRITABLE
,
1010 jsval_obj(ctx
->eval_error_constr
));
1014 hres
= jsdisp_define_data_property(ctx
->global
, RangeErrorW
, PROPF_WRITABLE
,
1015 jsval_obj(ctx
->range_error_constr
));
1019 hres
= jsdisp_define_data_property(ctx
->global
, ReferenceErrorW
, PROPF_WRITABLE
,
1020 jsval_obj(ctx
->reference_error_constr
));
1024 hres
= jsdisp_define_data_property(ctx
->global
, RegExpErrorW
, PROPF_WRITABLE
,
1025 jsval_obj(ctx
->regexp_error_constr
));
1029 hres
= jsdisp_define_data_property(ctx
->global
, SyntaxErrorW
, PROPF_WRITABLE
,
1030 jsval_obj(ctx
->syntax_error_constr
));
1034 hres
= jsdisp_define_data_property(ctx
->global
, TypeErrorW
, PROPF_WRITABLE
,
1035 jsval_obj(ctx
->type_error_constr
));
1039 hres
= jsdisp_define_data_property(ctx
->global
, URIErrorW
, PROPF_WRITABLE
,
1040 jsval_obj(ctx
->uri_error_constr
));
1044 hres
= create_number_constr(ctx
, object_prototype
, &ctx
->number_constr
);
1048 hres
= jsdisp_define_data_property(ctx
->global
, NumberW
, PROPF_WRITABLE
,
1049 jsval_obj(ctx
->number_constr
));
1053 hres
= create_regexp_constr(ctx
, object_prototype
, &ctx
->regexp_constr
);
1057 hres
= jsdisp_define_data_property(ctx
->global
, RegExpW
, PROPF_WRITABLE
,
1058 jsval_obj(ctx
->regexp_constr
));
1062 hres
= create_string_constr(ctx
, object_prototype
, &ctx
->string_constr
);
1066 hres
= jsdisp_define_data_property(ctx
->global
, StringW
, PROPF_WRITABLE
,
1067 jsval_obj(ctx
->string_constr
));
1071 hres
= create_vbarray_constr(ctx
, object_prototype
, &ctx
->vbarray_constr
);
1075 hres
= jsdisp_define_data_property(ctx
->global
, VBArrayW
, PROPF_WRITABLE
,
1076 jsval_obj(ctx
->vbarray_constr
));
1083 HRESULT
init_global(script_ctx_t
*ctx
)
1085 unsigned const_flags
= ctx
->version
>= SCRIPTLANGUAGEVERSION_ES5
? 0 : PROPF_WRITABLE
;
1086 jsdisp_t
*math
, *object_prototype
, *constr
;
1092 hres
= create_dispex(ctx
, &JSGlobal_info
, NULL
, &ctx
->global
);
1096 hres
= create_object_prototype(ctx
, &object_prototype
);
1100 hres
= init_constructors(ctx
, object_prototype
);
1101 jsdisp_release(object_prototype
);
1105 hres
= create_math(ctx
, &math
);
1109 hres
= jsdisp_define_data_property(ctx
->global
, MathW
, PROPF_WRITABLE
, jsval_obj(math
));
1110 jsdisp_release(math
);
1114 if(ctx
->version
>= 2) {
1117 hres
= create_json(ctx
, &json
);
1121 hres
= jsdisp_define_data_property(ctx
->global
, JSONW
, PROPF_WRITABLE
, jsval_obj(json
));
1122 jsdisp_release(json
);
1127 hres
= create_activex_constr(ctx
, &constr
);
1131 hres
= jsdisp_define_data_property(ctx
->global
, ActiveXObjectW
, PROPF_WRITABLE
,
1133 jsdisp_release(constr
);
1137 hres
= jsdisp_define_data_property(ctx
->global
, undefinedW
, const_flags
, jsval_undefined());
1141 hres
= jsdisp_define_data_property(ctx
->global
, NaNW
, const_flags
, jsval_number(NAN
));
1145 hres
= jsdisp_define_data_property(ctx
->global
, InfinityW
, const_flags
, jsval_number(INFINITY
));