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
,
558 static HRESULT
JSGlobal_encodeURI(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
561 const WCHAR
*ptr
, *uri
;
572 *r
= jsval_string(jsstr_undefined());
576 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
580 for(ptr
= uri
; *ptr
; ptr
++) {
581 if(is_uri_unescaped(*ptr
) || is_uri_reserved(*ptr
) || *ptr
== '#') {
584 i
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, NULL
, 0, NULL
, NULL
)*3;
587 return JS_E_INVALID_URI_CHAR
;
594 ret
= jsstr_alloc_buf(len
, &rptr
);
597 return E_OUTOFMEMORY
;
600 for(ptr
= uri
; *ptr
; ptr
++) {
601 if(is_uri_unescaped(*ptr
) || is_uri_reserved(*ptr
) || *ptr
== '#') {
604 len
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, buf
, sizeof(buf
), NULL
, NULL
);
605 for(i
=0; i
<len
; i
++) {
607 *rptr
++ = int_to_char((BYTE
)buf
[i
] >> 4);
608 *rptr
++ = int_to_char(buf
[i
] & 0x0f);
613 TRACE("%s -> %s\n", debugstr_jsstr(str
), debugstr_jsstr(ret
));
617 *r
= jsval_string(ret
);
623 static HRESULT
JSGlobal_decodeURI(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
626 const WCHAR
*ptr
, *uri
;
627 jsstr_t
*str
, *ret_str
;
639 *r
= jsval_string(jsstr_undefined());
643 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
647 for(ptr
= uri
; *ptr
; ptr
++) {
653 if(ptr
[i
*3]!='%' || hex_to_int(ptr
[i
*3+1])==-1 || (val
=hex_to_int(ptr
[i
*3+2]))==-1)
655 val
+= hex_to_int(ptr
[i
*3+1])<<4;
658 res
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, buf
, i
+1, &out
, 1);
665 return JS_E_INVALID_URI_CODING
;
673 ret_str
= jsstr_alloc_buf(len
, &ret
);
676 return E_OUTOFMEMORY
;
679 for(ptr
= uri
; *ptr
; ptr
++) {
684 if(ptr
[i
*3]!='%' || hex_to_int(ptr
[i
*3+1])==-1 || (val
=hex_to_int(ptr
[i
*3+2]))==-1)
686 val
+= hex_to_int(ptr
[i
*3+1])<<4;
689 res
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, buf
, i
+1, ret
, 1);
699 TRACE("%s -> %s\n", debugstr_jsstr(str
), debugstr_jsstr(ret_str
));
703 *r
= jsval_string(ret_str
);
705 jsstr_release(ret_str
);
709 static HRESULT
JSGlobal_encodeURIComponent(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
712 jsstr_t
*str
, *ret_str
;
714 const WCHAR
*ptr
, *uri
;
715 DWORD len
= 0, size
, i
;
723 *r
= jsval_string(jsstr_undefined());
727 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
731 for(ptr
= uri
; *ptr
; ptr
++) {
732 if(is_uri_unescaped(*ptr
))
735 size
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, NULL
, 0, NULL
, NULL
);
738 return JS_E_INVALID_URI_CHAR
;
744 ret_str
= jsstr_alloc_buf(len
, &ret
);
747 return E_OUTOFMEMORY
;
750 for(ptr
= uri
; *ptr
; ptr
++) {
751 if(is_uri_unescaped(*ptr
)) {
754 size
= WideCharToMultiByte(CP_UTF8
, WC_ERR_INVALID_CHARS
, ptr
, 1, buf
, sizeof(buf
), NULL
, NULL
);
755 for(i
=0; i
<size
; i
++) {
757 *ret
++ = int_to_char((BYTE
)buf
[i
] >> 4);
758 *ret
++ = int_to_char(buf
[i
] & 0x0f);
766 *r
= jsval_string(ret_str
);
768 jsstr_release(ret_str
);
772 /* ECMA-262 3rd Edition 15.1.3.2 */
773 static HRESULT
JSGlobal_decodeURIComponent(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
776 const WCHAR
*ptr
, *uri
;
786 *r
= jsval_string(jsstr_undefined());
790 hres
= to_flat_string(ctx
, argv
[0], &str
, &uri
);
798 unsigned char mask
= 0x80;
799 int i
, size
, num_bytes
= 0;
800 if(hex_to_int(*(ptr
+1)) < 0 || hex_to_int(*(ptr
+2)) < 0) {
801 FIXME("Throw URIError: Invalid hex sequence\n");
805 octets
[0] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
807 while(octets
[0] & mask
) {
811 if(num_bytes
== 1 || num_bytes
> 4) {
812 FIXME("Throw URIError: Invalid initial UTF character\n");
816 for(i
= 1; i
< num_bytes
; ++i
) {
818 FIXME("Throw URIError: Incomplete UTF sequence\n");
822 if(hex_to_int(*(ptr
+1)) < 0 || hex_to_int(*(ptr
+2)) < 0) {
823 FIXME("Throw URIError: Invalid hex sequence\n");
827 octets
[i
] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
830 size
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, octets
,
831 num_bytes
? num_bytes
: 1, NULL
, 0);
833 FIXME("Throw URIError: Invalid UTF sequence\n");
844 ret
= jsstr_alloc_buf(len
, &out_ptr
);
847 return E_OUTOFMEMORY
;
854 unsigned char mask
= 0x80;
855 int i
, size
, num_bytes
= 0;
856 octets
[0] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
858 while(octets
[0] & mask
) {
862 for(i
= 1; i
< num_bytes
; ++i
) {
863 octets
[i
] = (hex_to_int(*(ptr
+1)) << 4) + hex_to_int(*(ptr
+2));
866 size
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, octets
,
867 num_bytes
? num_bytes
: 1, out_ptr
, len
);
879 *r
= jsval_string(ret
);
885 static const builtin_prop_t JSGlobal_props
[] = {
886 {L
"CollectGarbage", JSGlobal_CollectGarbage
, PROPF_METHOD
},
887 {L
"GetObject", JSGlobal_GetObject
, PROPF_METHOD
|2},
888 {L
"ScriptEngine", JSGlobal_ScriptEngine
, PROPF_METHOD
},
889 {L
"ScriptEngineBuildVersion", JSGlobal_ScriptEngineBuildVersion
, PROPF_METHOD
},
890 {L
"ScriptEngineMajorVersion", JSGlobal_ScriptEngineMajorVersion
, PROPF_METHOD
},
891 {L
"ScriptEngineMinorVersion", JSGlobal_ScriptEngineMinorVersion
, PROPF_METHOD
},
892 {L
"decodeURI", JSGlobal_decodeURI
, PROPF_METHOD
|1},
893 {L
"decodeURIComponent", JSGlobal_decodeURIComponent
, PROPF_METHOD
|1},
894 {L
"encodeURI", JSGlobal_encodeURI
, PROPF_METHOD
|1},
895 {L
"encodeURIComponent", JSGlobal_encodeURIComponent
, PROPF_METHOD
|1},
896 {L
"escape", JSGlobal_escape
, PROPF_METHOD
|1},
897 {L
"eval", JSGlobal_eval
, PROPF_METHOD
|1},
898 {L
"isFinite", JSGlobal_isFinite
, PROPF_METHOD
|1},
899 {L
"isNaN", JSGlobal_isNaN
, PROPF_METHOD
|1},
900 {L
"parseFloat", JSGlobal_parseFloat
, PROPF_METHOD
|1},
901 {L
"parseInt", JSGlobal_parseInt
, PROPF_METHOD
|2},
902 {L
"unescape", JSGlobal_unescape
, PROPF_METHOD
|1}
905 static const builtin_info_t JSGlobal_info
= {
908 ARRAY_SIZE(JSGlobal_props
),
914 static HRESULT
init_object_prototype_accessors(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
)
916 property_desc_t desc
;
919 /* __proto__ is an actual accessor on native, despite being a builtin */
920 if(ctx
->version
>= SCRIPTLANGUAGEVERSION_ES6
) {
921 desc
.flags
= PROPF_CONFIGURABLE
;
922 desc
.mask
= PROPF_CONFIGURABLE
| PROPF_ENUMERABLE
;
923 desc
.explicit_getter
= desc
.explicit_setter
= TRUE
;
924 desc
.explicit_value
= FALSE
;
926 hres
= create_builtin_function(ctx
, Object_get_proto_
, NULL
, NULL
, PROPF_METHOD
, NULL
, &desc
.getter
);
927 if(SUCCEEDED(hres
)) {
928 hres
= create_builtin_function(ctx
, Object_set_proto_
, NULL
, NULL
, PROPF_METHOD
|1, NULL
, &desc
.setter
);
929 if(SUCCEEDED(hres
)) {
930 hres
= jsdisp_define_property(object_prototype
, L
"__proto__", &desc
);
931 jsdisp_release(desc
.setter
);
933 jsdisp_release(desc
.getter
);
939 static HRESULT
init_constructors(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
)
943 hres
= init_function_constr(ctx
, object_prototype
);
947 hres
= jsdisp_define_data_property(ctx
->global
, L
"Function", PROPF_WRITABLE
,
948 jsval_obj(ctx
->function_constr
));
952 hres
= create_object_constr(ctx
, object_prototype
, &ctx
->object_constr
);
956 hres
= jsdisp_define_data_property(ctx
->global
, L
"Object", PROPF_WRITABLE
,
957 jsval_obj(ctx
->object_constr
));
961 hres
= create_array_constr(ctx
, object_prototype
, &ctx
->array_constr
);
965 hres
= jsdisp_define_data_property(ctx
->global
, L
"Array", PROPF_WRITABLE
,
966 jsval_obj(ctx
->array_constr
));
970 hres
= create_bool_constr(ctx
, object_prototype
, &ctx
->bool_constr
);
974 hres
= jsdisp_define_data_property(ctx
->global
, L
"Boolean", PROPF_WRITABLE
,
975 jsval_obj(ctx
->bool_constr
));
979 hres
= create_date_constr(ctx
, object_prototype
, &ctx
->date_constr
);
983 hres
= jsdisp_define_data_property(ctx
->global
, L
"Date", PROPF_WRITABLE
,
984 jsval_obj(ctx
->date_constr
));
988 hres
= create_enumerator_constr(ctx
, object_prototype
, &ctx
->enumerator_constr
);
992 hres
= jsdisp_define_data_property(ctx
->global
, L
"Enumerator", PROPF_WRITABLE
,
993 jsval_obj(ctx
->enumerator_constr
));
997 hres
= init_error_constr(ctx
, object_prototype
);
1001 hres
= jsdisp_define_data_property(ctx
->global
, L
"Error", PROPF_WRITABLE
,
1002 jsval_obj(ctx
->error_constr
));
1006 hres
= jsdisp_define_data_property(ctx
->global
, L
"EvalError", PROPF_WRITABLE
,
1007 jsval_obj(ctx
->eval_error_constr
));
1011 hres
= jsdisp_define_data_property(ctx
->global
, L
"RangeError", PROPF_WRITABLE
,
1012 jsval_obj(ctx
->range_error_constr
));
1016 hres
= jsdisp_define_data_property(ctx
->global
, L
"ReferenceError", PROPF_WRITABLE
,
1017 jsval_obj(ctx
->reference_error_constr
));
1021 hres
= jsdisp_define_data_property(ctx
->global
, L
"RegExpError", PROPF_WRITABLE
,
1022 jsval_obj(ctx
->regexp_error_constr
));
1026 hres
= jsdisp_define_data_property(ctx
->global
, L
"SyntaxError", PROPF_WRITABLE
,
1027 jsval_obj(ctx
->syntax_error_constr
));
1031 hres
= jsdisp_define_data_property(ctx
->global
, L
"TypeError", PROPF_WRITABLE
,
1032 jsval_obj(ctx
->type_error_constr
));
1036 hres
= jsdisp_define_data_property(ctx
->global
, L
"URIError", PROPF_WRITABLE
,
1037 jsval_obj(ctx
->uri_error_constr
));
1041 hres
= create_number_constr(ctx
, object_prototype
, &ctx
->number_constr
);
1045 hres
= jsdisp_define_data_property(ctx
->global
, L
"Number", PROPF_WRITABLE
,
1046 jsval_obj(ctx
->number_constr
));
1050 hres
= create_regexp_constr(ctx
, object_prototype
, &ctx
->regexp_constr
);
1054 hres
= jsdisp_define_data_property(ctx
->global
, L
"RegExp", PROPF_WRITABLE
,
1055 jsval_obj(ctx
->regexp_constr
));
1059 hres
= create_string_constr(ctx
, object_prototype
, &ctx
->string_constr
);
1063 hres
= jsdisp_define_data_property(ctx
->global
, L
"String", PROPF_WRITABLE
,
1064 jsval_obj(ctx
->string_constr
));
1068 hres
= create_vbarray_constr(ctx
, object_prototype
, &ctx
->vbarray_constr
);
1072 hres
= jsdisp_define_data_property(ctx
->global
, L
"VBArray", PROPF_WRITABLE
,
1073 jsval_obj(ctx
->vbarray_constr
));
1080 HRESULT
init_global(script_ctx_t
*ctx
)
1082 unsigned const_flags
= ctx
->version
>= SCRIPTLANGUAGEVERSION_ES5
? 0 : PROPF_WRITABLE
;
1083 jsdisp_t
*math
, *constr
;
1089 hres
= create_dispex(ctx
, &JSGlobal_info
, NULL
, &ctx
->global
);
1093 hres
= create_object_prototype(ctx
, &ctx
->object_prototype
);
1097 hres
= init_constructors(ctx
, ctx
->object_prototype
);
1101 hres
= init_object_prototype_accessors(ctx
, ctx
->object_prototype
);
1105 hres
= create_math(ctx
, &math
);
1109 hres
= jsdisp_define_data_property(ctx
->global
, L
"Math", 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
, L
"JSON", PROPF_WRITABLE
, jsval_obj(json
));
1122 jsdisp_release(json
);
1127 hres
= create_activex_constr(ctx
, &constr
);
1131 hres
= jsdisp_define_data_property(ctx
->global
, L
"ActiveXObject", PROPF_WRITABLE
,
1133 jsdisp_release(constr
);
1137 hres
= jsdisp_define_data_property(ctx
->global
, L
"undefined", const_flags
, jsval_undefined());
1141 hres
= jsdisp_define_data_property(ctx
->global
, L
"NaN", const_flags
, jsval_number(NAN
));
1145 hres
= jsdisp_define_data_property(ctx
->global
, L
"Infinity", const_flags
, jsval_number(INFINITY
));
1149 return init_set_constructor(ctx
);