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 int uri_char_table
[] = {
31 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 00-0f */
32 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 10-1f */
33 0,2,0,0,1,0,1,2,2,2,2,1,1,2,2,1, /* 20-2f */
34 2,2,2,2,2,2,2,2,2,2,1,1,0,1,0,1, /* 30-3f */
35 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 40-4f */
36 2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,2, /* 50-5f */
37 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 60-6f */
38 2,2,2,2,2,2,2,2,2,2,2,0,0,0,2,0, /* 70-7f */
44 static inline BOOL
is_uri_reserved(WCHAR c
)
46 return c
< 128 && uri_char_table
[c
] == 1;
49 static inline BOOL
is_uri_unescaped(WCHAR c
)
51 return c
< 128 && uri_char_table
[c
] == 2;
54 /* Check that the character is one of the 69 non-blank characters as defined by ECMA-262 B.2.1 */
55 static inline BOOL
is_ecma_nonblank(const WCHAR c
)
57 return ((c
>= 'A' && c
<= 'Z') || (c
>= 'a' && c
<= 'z') || (c
>= '0' && c
<= '9') ||
58 c
== '@' || c
== '*' || c
== '_' || c
== '+' || c
== '-' || c
== '.' || c
== '/');
61 static WCHAR
int_to_char(int i
)
68 static HRESULT
JSGlobal_escape(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
71 jsstr_t
*ret_str
, *str
;
72 const WCHAR
*ptr
, *buf
;
81 *r
= jsval_string(jsstr_undefined());
85 hres
= to_flat_string(ctx
, argv
[0], &str
, &buf
);
89 for(ptr
= buf
; *ptr
; ptr
++) {
92 else if(is_ecma_nonblank(*ptr
))
98 ret_str
= jsstr_alloc_buf(len
, &ret
);
101 return E_OUTOFMEMORY
;
105 for(ptr
= buf
; *ptr
; ptr
++) {
109 ret
[len
++] = int_to_char(*ptr
>> 12);
110 ret
[len
++] = int_to_char((*ptr
>> 8) & 0xf);
111 ret
[len
++] = int_to_char((*ptr
>> 4) & 0xf);
112 ret
[len
++] = int_to_char(*ptr
& 0xf);
114 else if(is_ecma_nonblank(*ptr
))
118 ret
[len
++] = int_to_char(*ptr
>> 4);
119 ret
[len
++] = int_to_char(*ptr
& 0xf);
126 *r
= jsval_string(ret_str
);
128 jsstr_release(ret_str
);
132 /* ECMA-262 3rd Edition 15.1.2.1 */
133 HRESULT
JSGlobal_eval(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
136 call_frame_t
*frame
= ctx
->call_ctx
;
137 DWORD exec_flags
= EXEC_EVAL
;
146 *r
= jsval_undefined();
150 if(!is_string(argv
[0])) {
152 return jsval_copy(argv
[0], r
);
156 src
= jsstr_flatten(get_string(argv
[0]));
158 return E_OUTOFMEMORY
;
160 TRACE("parsing %s\n", debugstr_jsval(argv
[0]));
161 hres
= compile_script(ctx
, src
, 0, 0, NULL
, NULL
, TRUE
, FALSE
, frame
? frame
->bytecode
->named_item
: NULL
, &code
);
163 WARN("parse (%s) failed: %08lx\n", debugstr_jsval(argv
[0]), hres
);
167 if(!frame
|| (frame
->flags
& EXEC_GLOBAL
))
168 exec_flags
|= EXEC_GLOBAL
;
169 if(flags
& DISPATCH_JSCRIPT_CALLEREXECSSOURCE
)
170 exec_flags
|= EXEC_RETURN_TO_INTERP
;
171 hres
= exec_source(ctx
, exec_flags
, code
, &code
->global_code
, frame
? frame
->scope
: NULL
,
172 frame
? frame
->this_obj
: NULL
, NULL
, 0, NULL
, r
);
173 release_bytecode(code
);
177 static HRESULT
JSGlobal_isNaN(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
187 hres
= to_number(ctx
, argv
[0], &n
);
196 *r
= jsval_bool(ret
);
200 static HRESULT
JSGlobal_isFinite(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
211 hres
= to_number(ctx
, argv
[0], &n
);
219 *r
= jsval_bool(ret
);
223 static INT
char_to_int(WCHAR c
)
225 if('0' <= c
&& c
<= '9')
227 if('a' <= c
&& c
<= 'z')
229 if('A' <= c
&& c
<= 'Z')
234 static HRESULT
JSGlobal_parseInt(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
237 BOOL neg
= FALSE
, empty
= TRUE
;
246 *r
= jsval_number(NAN
);
251 hres
= to_int32(ctx
, argv
[1], &radix
);
255 if(radix
&& (radix
< 2 || radix
> 36)) {
256 WARN("radix %d out of range\n", radix
);
258 *r
= jsval_number(NAN
);
263 hres
= to_flat_string(ctx
, argv
[0], &str
, &ptr
);
267 while(iswspace(*ptr
))
282 if(ptr
[1] == 'x' || ptr
[1] == 'X') {
293 }else if(radix
== 16 && *ptr
== '0' && (ptr
[1] == 'x' || ptr
[1] == 'X')) {
297 i
= char_to_int(*ptr
++);
301 i
= char_to_int(*ptr
++);
313 *r
= jsval_number(ret
);
317 static HRESULT
JSGlobal_parseFloat(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
324 BOOL ret_nan
= TRUE
, positive
= TRUE
;
329 *r
= jsval_number(NAN
);
333 TRACE("%s\n", debugstr_jsval(argv
[0]));
335 hres
= to_flat_string(ctx
, argv
[0], &val_str
, &str
);
339 while(iswspace(*str
)) str
++;
343 else if(*str
== '-') {
351 while(is_digit(*str
)) {
352 hlp
= d
*10 + *(str
++) - '0';
353 if(d
>MAXLONGLONG
/10 || hlp
<0) {
360 while(is_digit(*str
)) {
365 if(*str
== '.') str
++;
370 while(is_digit(*str
)) {
371 hlp
= d
*10 + *(str
++) - '0';
372 if(d
>MAXLONGLONG
/10 || hlp
<0)
378 while(is_digit(*str
))
381 if(*str
&& !ret_nan
&& (*str
=='e' || *str
=='E')) {
387 else if(*str
== '-') {
392 while(is_digit(*str
)) {
393 if(e
>INT_MAX
/10 || (e
= e
*10 + *str
++ - '0')<0)
398 if(exp
<0 && e
<0 && exp
+e
>0) exp
= INT_MIN
;
399 else if(exp
>0 && e
>0 && exp
+e
<0) exp
= INT_MAX
;
403 jsstr_release(val_str
);
407 *r
= jsval_number(NAN
);
414 *r
= jsval_number(exp
>0 ? d
*pow(10, exp
) : d
/pow(10, -exp
));
418 static inline int hex_to_int(const WCHAR wch
) {
419 if(towupper(wch
)>='A' && towupper(wch
)<='F') return towupper(wch
)-'A'+10;
420 if(is_digit(wch
)) return wch
-'0';
424 static HRESULT
JSGlobal_unescape(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
427 jsstr_t
*ret_str
, *str
;
428 const WCHAR
*ptr
, *buf
;
437 *r
= jsval_string(jsstr_undefined());
441 hres
= to_flat_string(ctx
, argv
[0], &str
, &buf
);
445 for(ptr
= buf
; *ptr
; ptr
++) {
447 if(hex_to_int(*(ptr
+1))!=-1 && hex_to_int(*(ptr
+2))!=-1)
449 else if(*(ptr
+1)=='u' && hex_to_int(*(ptr
+2))!=-1 && hex_to_int(*(ptr
+3))!=-1
450 && hex_to_int(*(ptr
+4))!=-1 && hex_to_int(*(ptr
+5))!=-1)
457 ret_str
= jsstr_alloc_buf(len
, &ret
);
460 return E_OUTOFMEMORY
;
464 for(ptr
= buf
; *ptr
; ptr
++) {
466 if(hex_to_int(*(ptr
+1))!=-1 && hex_to_int(*(ptr
+2))!=-1) {
467 ret
[len
] = (hex_to_int(*(ptr
+1))<<4) + hex_to_int(*(ptr
+2));
470 else if(*(ptr
+1)=='u' && hex_to_int(*(ptr
+2))!=-1 && hex_to_int(*(ptr
+3))!=-1
471 && hex_to_int(*(ptr
+4))!=-1 && hex_to_int(*(ptr
+5))!=-1) {
472 ret
[len
] = (hex_to_int(*(ptr
+2))<<12) + (hex_to_int(*(ptr
+3))<<8)
473 + (hex_to_int(*(ptr
+4))<<4) + hex_to_int(*(ptr
+5));
488 *r
= jsval_string(ret_str
);
490 jsstr_release(ret_str
);
494 static HRESULT
JSGlobal_GetObject(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
501 static HRESULT
JSGlobal_ScriptEngine(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
509 ret
= jsstr_alloc(L
"JScript");
511 return E_OUTOFMEMORY
;
513 *r
= jsval_string(ret
);
519 static HRESULT
JSGlobal_ScriptEngineMajorVersion(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
525 *r
= jsval_number(JSCRIPT_MAJOR_VERSION
);
529 static HRESULT
JSGlobal_ScriptEngineMinorVersion(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
535 *r
= jsval_number(JSCRIPT_MINOR_VERSION
);
539 static HRESULT
JSGlobal_ScriptEngineBuildVersion(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
545 *r
= jsval_number(JSCRIPT_BUILD_VERSION
);
549 static HRESULT
JSGlobal_CollectGarbage(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
555 static HRESULT
JSGlobal_encodeURI(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
558 const WCHAR
*ptr
, *uri
;
569 *r
= jsval_string(jsstr_undefined());
573 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
577 for(ptr
= uri
; *ptr
; ptr
++) {
578 if(is_uri_unescaped(*ptr
) || is_uri_reserved(*ptr
) || *ptr
== '#') {
581 i
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, NULL
, 0, NULL
, NULL
)*3;
584 return JS_E_INVALID_URI_CHAR
;
591 ret
= jsstr_alloc_buf(len
, &rptr
);
594 return E_OUTOFMEMORY
;
597 for(ptr
= uri
; *ptr
; ptr
++) {
598 if(is_uri_unescaped(*ptr
) || is_uri_reserved(*ptr
) || *ptr
== '#') {
601 len
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, buf
, sizeof(buf
), NULL
, NULL
);
602 for(i
=0; i
<len
; i
++) {
604 *rptr
++ = int_to_char((BYTE
)buf
[i
] >> 4);
605 *rptr
++ = int_to_char(buf
[i
] & 0x0f);
610 TRACE("%s -> %s\n", debugstr_jsstr(str
), debugstr_jsstr(ret
));
614 *r
= jsval_string(ret
);
620 static HRESULT
JSGlobal_decodeURI(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
623 const WCHAR
*ptr
, *uri
;
624 jsstr_t
*str
, *ret_str
;
636 *r
= jsval_string(jsstr_undefined());
640 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
644 for(ptr
= uri
; *ptr
; ptr
++) {
650 if(ptr
[i
*3]!='%' || hex_to_int(ptr
[i
*3+1])==-1 || (val
=hex_to_int(ptr
[i
*3+2]))==-1)
652 val
+= hex_to_int(ptr
[i
*3+1])<<4;
655 res
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, buf
, i
+1, &out
, 1);
662 return JS_E_INVALID_URI_CODING
;
670 ret_str
= jsstr_alloc_buf(len
, &ret
);
673 return E_OUTOFMEMORY
;
676 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, ret
, 1);
696 TRACE("%s -> %s\n", debugstr_jsstr(str
), debugstr_jsstr(ret_str
));
700 *r
= jsval_string(ret_str
);
702 jsstr_release(ret_str
);
706 static HRESULT
JSGlobal_encodeURIComponent(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
709 jsstr_t
*str
, *ret_str
;
711 const WCHAR
*ptr
, *uri
;
712 DWORD len
= 0, size
, i
;
720 *r
= jsval_string(jsstr_undefined());
724 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
728 for(ptr
= uri
; *ptr
; ptr
++) {
729 if(is_uri_unescaped(*ptr
))
732 size
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, NULL
, 0, NULL
, NULL
);
735 return JS_E_INVALID_URI_CHAR
;
741 ret_str
= jsstr_alloc_buf(len
, &ret
);
744 return E_OUTOFMEMORY
;
747 for(ptr
= uri
; *ptr
; ptr
++) {
748 if(is_uri_unescaped(*ptr
)) {
751 size
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, buf
, sizeof(buf
), NULL
, NULL
);
752 for(i
=0; i
<size
; i
++) {
754 *ret
++ = int_to_char((BYTE
)buf
[i
] >> 4);
755 *ret
++ = int_to_char(buf
[i
] & 0x0f);
763 *r
= jsval_string(ret_str
);
765 jsstr_release(ret_str
);
769 /* ECMA-262 3rd Edition 15.1.3.2 */
770 static HRESULT
JSGlobal_decodeURIComponent(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
773 const WCHAR
*ptr
, *uri
;
783 *r
= jsval_string(jsstr_undefined());
787 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
795 unsigned char mask
= 0x80;
796 int i
, size
, num_bytes
= 0;
797 if(hex_to_int(*(ptr
+1)) < 0 || hex_to_int(*(ptr
+2)) < 0) {
798 FIXME("Throw URIError: Invalid hex sequence\n");
802 octets
[0] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
804 while(octets
[0] & mask
) {
808 if(num_bytes
== 1 || num_bytes
> 4) {
809 FIXME("Throw URIError: Invalid initial UTF character\n");
813 for(i
= 1; i
< num_bytes
; ++i
) {
815 FIXME("Throw URIError: Incomplete UTF sequence\n");
819 if(hex_to_int(*(ptr
+1)) < 0 || hex_to_int(*(ptr
+2)) < 0) {
820 FIXME("Throw URIError: Invalid hex sequence\n");
824 octets
[i
] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
827 size
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, octets
,
828 num_bytes
? num_bytes
: 1, NULL
, 0);
830 FIXME("Throw URIError: Invalid UTF sequence\n");
841 ret
= jsstr_alloc_buf(len
, &out_ptr
);
844 return E_OUTOFMEMORY
;
851 unsigned char mask
= 0x80;
852 int i
, size
, num_bytes
= 0;
853 octets
[0] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
855 while(octets
[0] & mask
) {
859 for(i
= 1; i
< num_bytes
; ++i
) {
860 octets
[i
] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
863 size
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, octets
,
864 num_bytes
? num_bytes
: 1, out_ptr
, len
);
876 *r
= jsval_string(ret
);
882 static const builtin_prop_t JSGlobal_props
[] = {
883 {L
"CollectGarbage", JSGlobal_CollectGarbage
, PROPF_METHOD
},
884 {L
"GetObject", JSGlobal_GetObject
, PROPF_METHOD
|2},
885 {L
"ScriptEngine", JSGlobal_ScriptEngine
, PROPF_METHOD
},
886 {L
"ScriptEngineBuildVersion", JSGlobal_ScriptEngineBuildVersion
, PROPF_METHOD
},
887 {L
"ScriptEngineMajorVersion", JSGlobal_ScriptEngineMajorVersion
, PROPF_METHOD
},
888 {L
"ScriptEngineMinorVersion", JSGlobal_ScriptEngineMinorVersion
, PROPF_METHOD
},
889 {L
"decodeURI", JSGlobal_decodeURI
, PROPF_METHOD
|1},
890 {L
"decodeURIComponent", JSGlobal_decodeURIComponent
, PROPF_METHOD
|1},
891 {L
"encodeURI", JSGlobal_encodeURI
, PROPF_METHOD
|1},
892 {L
"encodeURIComponent", JSGlobal_encodeURIComponent
, PROPF_METHOD
|1},
893 {L
"escape", JSGlobal_escape
, PROPF_METHOD
|1},
894 {L
"eval", JSGlobal_eval
, PROPF_METHOD
|1},
895 {L
"isFinite", JSGlobal_isFinite
, PROPF_METHOD
|1},
896 {L
"isNaN", JSGlobal_isNaN
, PROPF_METHOD
|1},
897 {L
"parseFloat", JSGlobal_parseFloat
, PROPF_METHOD
|1},
898 {L
"parseInt", JSGlobal_parseInt
, PROPF_METHOD
|2},
899 {L
"unescape", JSGlobal_unescape
, PROPF_METHOD
|1}
902 static const builtin_info_t JSGlobal_info
= {
905 ARRAY_SIZE(JSGlobal_props
),
911 static HRESULT
init_object_prototype_accessors(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
)
913 property_desc_t desc
;
916 /* __proto__ is an actual accessor on native, despite being a builtin */
917 if(ctx
->version
>= SCRIPTLANGUAGEVERSION_ES6
) {
918 desc
.flags
= PROPF_CONFIGURABLE
;
919 desc
.mask
= PROPF_CONFIGURABLE
| PROPF_ENUMERABLE
;
920 desc
.explicit_getter
= desc
.explicit_setter
= TRUE
;
921 desc
.explicit_value
= FALSE
;
923 hres
= create_builtin_function(ctx
, Object_get_proto_
, NULL
, NULL
, PROPF_METHOD
, NULL
, &desc
.getter
);
924 if(SUCCEEDED(hres
)) {
925 hres
= create_builtin_function(ctx
, Object_set_proto_
, NULL
, NULL
, PROPF_METHOD
|1, NULL
, &desc
.setter
);
926 if(SUCCEEDED(hres
)) {
927 hres
= jsdisp_define_property(object_prototype
, L
"__proto__", &desc
);
928 jsdisp_release(desc
.setter
);
930 jsdisp_release(desc
.getter
);
936 static HRESULT
init_constructors(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
)
940 hres
= init_function_constr(ctx
, object_prototype
);
944 hres
= jsdisp_define_data_property(ctx
->global
, L
"Function", PROPF_WRITABLE
,
945 jsval_obj(ctx
->function_constr
));
949 hres
= create_object_constr(ctx
, object_prototype
, &ctx
->object_constr
);
953 hres
= jsdisp_define_data_property(ctx
->global
, L
"Object", PROPF_WRITABLE
,
954 jsval_obj(ctx
->object_constr
));
958 hres
= create_array_constr(ctx
, object_prototype
, &ctx
->array_constr
);
962 hres
= jsdisp_define_data_property(ctx
->global
, L
"Array", PROPF_WRITABLE
,
963 jsval_obj(ctx
->array_constr
));
967 hres
= create_bool_constr(ctx
, object_prototype
, &ctx
->bool_constr
);
971 hres
= jsdisp_define_data_property(ctx
->global
, L
"Boolean", PROPF_WRITABLE
,
972 jsval_obj(ctx
->bool_constr
));
976 hres
= create_date_constr(ctx
, object_prototype
, &ctx
->date_constr
);
980 hres
= jsdisp_define_data_property(ctx
->global
, L
"Date", PROPF_WRITABLE
,
981 jsval_obj(ctx
->date_constr
));
985 hres
= create_enumerator_constr(ctx
, object_prototype
, &ctx
->enumerator_constr
);
989 hres
= jsdisp_define_data_property(ctx
->global
, L
"Enumerator", PROPF_WRITABLE
,
990 jsval_obj(ctx
->enumerator_constr
));
994 hres
= init_error_constr(ctx
, object_prototype
);
998 hres
= jsdisp_define_data_property(ctx
->global
, L
"Error", PROPF_WRITABLE
,
999 jsval_obj(ctx
->error_constr
));
1003 hres
= jsdisp_define_data_property(ctx
->global
, L
"EvalError", PROPF_WRITABLE
,
1004 jsval_obj(ctx
->eval_error_constr
));
1008 hres
= jsdisp_define_data_property(ctx
->global
, L
"RangeError", PROPF_WRITABLE
,
1009 jsval_obj(ctx
->range_error_constr
));
1013 hres
= jsdisp_define_data_property(ctx
->global
, L
"ReferenceError", PROPF_WRITABLE
,
1014 jsval_obj(ctx
->reference_error_constr
));
1018 hres
= jsdisp_define_data_property(ctx
->global
, L
"RegExpError", PROPF_WRITABLE
,
1019 jsval_obj(ctx
->regexp_error_constr
));
1023 hres
= jsdisp_define_data_property(ctx
->global
, L
"SyntaxError", PROPF_WRITABLE
,
1024 jsval_obj(ctx
->syntax_error_constr
));
1028 hres
= jsdisp_define_data_property(ctx
->global
, L
"TypeError", PROPF_WRITABLE
,
1029 jsval_obj(ctx
->type_error_constr
));
1033 hres
= jsdisp_define_data_property(ctx
->global
, L
"URIError", PROPF_WRITABLE
,
1034 jsval_obj(ctx
->uri_error_constr
));
1038 hres
= create_number_constr(ctx
, object_prototype
, &ctx
->number_constr
);
1042 hres
= jsdisp_define_data_property(ctx
->global
, L
"Number", PROPF_WRITABLE
,
1043 jsval_obj(ctx
->number_constr
));
1047 hres
= create_regexp_constr(ctx
, object_prototype
, &ctx
->regexp_constr
);
1051 hres
= jsdisp_define_data_property(ctx
->global
, L
"RegExp", PROPF_WRITABLE
,
1052 jsval_obj(ctx
->regexp_constr
));
1056 hres
= create_string_constr(ctx
, object_prototype
, &ctx
->string_constr
);
1060 hres
= jsdisp_define_data_property(ctx
->global
, L
"String", PROPF_WRITABLE
,
1061 jsval_obj(ctx
->string_constr
));
1065 hres
= create_vbarray_constr(ctx
, object_prototype
, &ctx
->vbarray_constr
);
1069 hres
= jsdisp_define_data_property(ctx
->global
, L
"VBArray", PROPF_WRITABLE
,
1070 jsval_obj(ctx
->vbarray_constr
));
1077 HRESULT
init_global(script_ctx_t
*ctx
)
1079 unsigned const_flags
= ctx
->version
>= SCRIPTLANGUAGEVERSION_ES5
? 0 : PROPF_WRITABLE
;
1080 jsdisp_t
*math
, *constr
;
1086 hres
= create_dispex(ctx
, &JSGlobal_info
, NULL
, &ctx
->global
);
1090 hres
= create_object_prototype(ctx
, &ctx
->object_prototype
);
1094 hres
= init_constructors(ctx
, ctx
->object_prototype
);
1098 hres
= init_object_prototype_accessors(ctx
, ctx
->object_prototype
);
1102 hres
= create_math(ctx
, &math
);
1106 hres
= jsdisp_define_data_property(ctx
->global
, L
"Math", PROPF_WRITABLE
, jsval_obj(math
));
1107 jsdisp_release(math
);
1111 if(ctx
->version
>= 2) {
1114 hres
= create_json(ctx
, &json
);
1118 hres
= jsdisp_define_data_property(ctx
->global
, L
"JSON", PROPF_WRITABLE
, jsval_obj(json
));
1119 jsdisp_release(json
);
1124 hres
= create_activex_constr(ctx
, &constr
);
1128 hres
= jsdisp_define_data_property(ctx
->global
, L
"ActiveXObject", PROPF_WRITABLE
,
1130 jsdisp_release(constr
);
1134 hres
= jsdisp_define_data_property(ctx
->global
, L
"undefined", const_flags
, jsval_undefined());
1138 hres
= jsdisp_define_data_property(ctx
->global
, L
"NaN", const_flags
, jsval_number(NAN
));
1142 hres
= jsdisp_define_data_property(ctx
->global
, L
"Infinity", const_flags
, jsval_number(INFINITY
));
1146 return init_set_constructor(ctx
);