ReactOS 0.4.17-dev-357-ga8f14ff
global.c
Go to the documentation of this file.
1/*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifdef __REACTOS__
20#include <wine/config.h>
21#include <wine/port.h>
22#endif
23
24#include <math.h>
25#include <limits.h>
26
27#include "jscript.h"
28#include "engine.h"
29
30#include "wine/debug.h"
31
33
34static int uri_char_table[] = {
35 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 00-0f */
36 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 10-1f */
37 0,2,0,0,1,0,1,2,2,2,2,1,1,2,2,1, /* 20-2f */
38 2,2,2,2,2,2,2,2,2,2,1,1,0,1,0,1, /* 30-3f */
39 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 40-4f */
40 2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,2, /* 50-5f */
41 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 60-6f */
42 2,2,2,2,2,2,2,2,2,2,2,0,0,0,2,0, /* 70-7f */
43};
44
45/* 1 - reserved */
46/* 2 - unescaped */
47
49{
50 return c < 128 && uri_char_table[c] == 1;
51}
52
54{
55 return c < 128 && uri_char_table[c] == 2;
56}
57
58/* Check that the character is one of the 69 non-blank characters as defined by ECMA-262 B.2.1 */
59static inline BOOL is_ecma_nonblank(const WCHAR c)
60{
61 return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
62 c == '@' || c == '*' || c == '_' || c == '+' || c == '-' || c == '.' || c == '/');
63}
64
65static WCHAR int_to_char(int i)
66{
67 if(i < 10)
68 return '0'+i;
69 return 'A'+i-10;
70}
71
73 jsval_t *r)
74{
75 jsstr_t *ret_str, *str;
76 const WCHAR *ptr, *buf;
77 DWORD len = 0;
78 WCHAR *ret;
80
81 TRACE("\n");
82
83 if(!argc) {
84 if(r)
86 return S_OK;
87 }
88
89 hres = to_flat_string(ctx, argv[0], &str, &buf);
90 if(FAILED(hres))
91 return hres;
92
93 for(ptr = buf; *ptr; ptr++) {
94 if(*ptr > 0xff)
95 len += 6;
96 else if(is_ecma_nonblank(*ptr))
97 len++;
98 else
99 len += 3;
100 }
101
102 ret_str = jsstr_alloc_buf(len, &ret);
103 if(!ret_str) {
105 return E_OUTOFMEMORY;
106 }
107
108 len = 0;
109 for(ptr = buf; *ptr; ptr++) {
110 if(*ptr > 0xff) {
111 ret[len++] = '%';
112 ret[len++] = 'u';
113 ret[len++] = int_to_char(*ptr >> 12);
114 ret[len++] = int_to_char((*ptr >> 8) & 0xf);
115 ret[len++] = int_to_char((*ptr >> 4) & 0xf);
116 ret[len++] = int_to_char(*ptr & 0xf);
117 }
118 else if(is_ecma_nonblank(*ptr))
119 ret[len++] = *ptr;
120 else {
121 ret[len++] = '%';
122 ret[len++] = int_to_char(*ptr >> 4);
123 ret[len++] = int_to_char(*ptr & 0xf);
124 }
125 }
126
128
129 if(r)
130 *r = jsval_string(ret_str);
131 else
132 jsstr_release(ret_str);
133 return S_OK;
134}
135
136/* ECMA-262 3rd Edition 15.1.2.1 */
138 jsval_t *r)
139{
140 DWORD exec_flags = EXEC_EVAL;
142 const WCHAR *src;
144
145 TRACE("\n");
146
147 if(!argc) {
148 if(r)
149 *r = jsval_undefined();
150 return S_OK;
151 }
152
153 if(!is_string(argv[0])) {
154 if(r)
155 return jsval_copy(argv[0], r);
156 return S_OK;
157 }
158
160 if(!src)
161 return E_OUTOFMEMORY;
162
163 TRACE("parsing %s\n", debugstr_jsval(argv[0]));
164 hres = compile_script(ctx, src, 0, 0, NULL, NULL, TRUE, FALSE, frame ? frame->bytecode->named_item : NULL, &code);
165 if(FAILED(hres)) {
166 WARN("parse (%s) failed: %08lx\n", debugstr_jsval(argv[0]), hres);
167 return hres;
168 }
169
170 if(!frame || (frame->flags & EXEC_GLOBAL))
171 exec_flags |= EXEC_GLOBAL;
173 exec_flags |= EXEC_RETURN_TO_INTERP;
174 hres = exec_source(ctx, exec_flags, code, &code->global_code, frame ? frame->scope : NULL,
175 frame ? frame->this_obj : NULL, NULL, 0, NULL, r);
177 return hres;
178}
179
181 jsval_t *r)
182{
183 return builtin_eval(ctx, ctx->version < SCRIPTLANGUAGEVERSION_ES5 ? ctx->call_ctx : NULL, flags, argc, argv, r);
184}
185
187 jsval_t *r)
188{
189 BOOL ret = TRUE;
190 double n;
192
193 TRACE("\n");
194
195 if(argc) {
196 hres = to_number(ctx, argv[0], &n);
197 if(FAILED(hres))
198 return hres;
199
200 if(!isnan(n))
201 ret = FALSE;
202 }
203
204 if(r)
205 *r = jsval_bool(ret);
206 return S_OK;
207}
208
210 jsval_t *r)
211{
212 BOOL ret = FALSE;
214
215 TRACE("\n");
216
217 if(argc) {
218 double n;
219
220 hres = to_number(ctx, argv[0], &n);
221 if(FAILED(hres))
222 return hres;
223
224 ret = isfinite(n);
225 }
226
227 if(r)
228 *r = jsval_bool(ret);
229 return S_OK;
230}
231
233{
234 if('0' <= c && c <= '9')
235 return c - '0';
236 if('a' <= c && c <= 'z')
237 return c - 'a' + 10;
238 if('A' <= c && c <= 'Z')
239 return c - 'A' + 10;
240 return 100;
241}
242
244 jsval_t *r)
245{
246 BOOL neg = FALSE, empty = TRUE;
247 const WCHAR *ptr;
248 DOUBLE ret = 0.0;
249 INT radix=0, i;
250 jsstr_t *str;
252
253 if(!argc) {
254 if(r)
255 *r = jsval_number(NAN);
256 return S_OK;
257 }
258
259 if(argc >= 2) {
260 hres = to_int32(ctx, argv[1], &radix);
261 if(FAILED(hres))
262 return hres;
263
264 if(radix && (radix < 2 || radix > 36)) {
265 WARN("radix %d out of range\n", radix);
266 if(r)
267 *r = jsval_number(NAN);
268 return S_OK;
269 }
270 }
271
272 hres = to_flat_string(ctx, argv[0], &str, &ptr);
273 if(FAILED(hres))
274 return hres;
275
276 while(iswspace(*ptr))
277 ptr++;
278
279 switch(*ptr) {
280 case '+':
281 ptr++;
282 break;
283 case '-':
284 neg = TRUE;
285 ptr++;
286 break;
287 }
288
289 if(!radix) {
290 if(*ptr == '0') {
291 if(ptr[1] == 'x' || ptr[1] == 'X') {
292 radix = 16;
293 ptr += 2;
294 }else {
295 radix = 8;
296 ptr++;
297 empty = FALSE;
298 }
299 }else {
300 radix = 10;
301 }
302 }else if(radix == 16 && *ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) {
303 ptr += 2;
304 }
305
306 i = char_to_int(*ptr++);
307 if(i < radix) {
308 do {
309 ret = ret*radix + i;
310 i = char_to_int(*ptr++);
311 }while(i < radix);
312 }else if(empty) {
313 ret = NAN;
314 }
315
317
318 if(neg)
319 ret = -ret;
320
321 if(r)
322 *r = jsval_number(ret);
323 return S_OK;
324}
325
327 jsval_t *r)
328{
329 LONGLONG d = 0, hlp;
330 jsstr_t *val_str;
331 int exp = 0;
332 const WCHAR *str;
335
336 if(!argc) {
337 if(r)
338 *r = jsval_number(NAN);
339 return S_OK;
340 }
341
342 TRACE("%s\n", debugstr_jsval(argv[0]));
343
344 hres = to_flat_string(ctx, argv[0], &val_str, &str);
345 if(FAILED(hres))
346 return hres;
347
348 while(iswspace(*str)) str++;
349
350 if(*str == '+')
351 str++;
352 else if(*str == '-') {
353 positive = FALSE;
354 str++;
355 }
356
357 if(is_digit(*str))
358 ret_nan = FALSE;
359
360 while(is_digit(*str)) {
361 hlp = d*10 + *(str++) - '0';
362 if(d>MAXLONGLONG/10 || hlp<0) {
363 exp++;
364 break;
365 }
366 else
367 d = hlp;
368 }
369 while(is_digit(*str)) {
370 exp++;
371 str++;
372 }
373
374 if(*str == '.') str++;
375
376 if(is_digit(*str))
377 ret_nan = FALSE;
378
379 while(is_digit(*str)) {
380 hlp = d*10 + *(str++) - '0';
381 if(d>MAXLONGLONG/10 || hlp<0)
382 break;
383
384 d = hlp;
385 exp--;
386 }
387 while(is_digit(*str))
388 str++;
389
390 if(*str && !ret_nan && (*str=='e' || *str=='E')) {
391 int sign = 1, e = 0;
392
393 str++;
394 if(*str == '+')
395 str++;
396 else if(*str == '-') {
397 sign = -1;
398 str++;
399 }
400
401 while(is_digit(*str)) {
402 if(e>INT_MAX/10 || (e = e*10 + *str++ - '0')<0)
403 e = INT_MAX;
404 }
405 e *= sign;
406
407 if(exp<0 && e<0 && exp+e>0) exp = INT_MIN;
408 else if(exp>0 && e>0 && exp+e<0) exp = INT_MAX;
409 else exp += e;
410 }
411
412 jsstr_release(val_str);
413
414 if(ret_nan) {
415 if(r)
416 *r = jsval_number(NAN);
417 return S_OK;
418 }
419
420 if(!positive)
421 d = -d;
422 if(r)
423 *r = jsval_number(exp>0 ? d*pow(10, exp) : d/pow(10, -exp));
424 return S_OK;
425}
426
427#ifdef __REACTOS__
428#ifdef __clang__
429static inline __attribute__((always_inline)) int hex_to_int(WCHAR wch) {
430#else
431static inline int hex_to_int(WCHAR wch) {
432#endif /* __clang__ */
433#else
434static inline int hex_to_int(const WCHAR wch) {
435#endif /* __REACTOS__ */
436 if(towupper(wch)>='A' && towupper(wch)<='F') return towupper(wch)-'A'+10;
437 if(is_digit(wch)) return wch-'0';
438 return -1;
439}
440
442 jsval_t *r)
443{
444 jsstr_t *ret_str, *str;
445 const WCHAR *ptr, *buf;
446 DWORD len = 0;
447 WCHAR *ret;
449
450 TRACE("\n");
451
452 if(!argc) {
453 if(r)
455 return S_OK;
456 }
457
458 hres = to_flat_string(ctx, argv[0], &str, &buf);
459 if(FAILED(hres))
460 return hres;
461
462 for(ptr = buf; *ptr; ptr++) {
463 if(*ptr == '%') {
464 if(hex_to_int(*(ptr+1))!=-1 && hex_to_int(*(ptr+2))!=-1)
465 ptr += 2;
466 else if(*(ptr+1)=='u' && hex_to_int(*(ptr+2))!=-1 && hex_to_int(*(ptr+3))!=-1
467 && hex_to_int(*(ptr+4))!=-1 && hex_to_int(*(ptr+5))!=-1)
468 ptr += 5;
469 }
470
471 len++;
472 }
473
474 ret_str = jsstr_alloc_buf(len, &ret);
475 if(!ret_str) {
477 return E_OUTOFMEMORY;
478 }
479
480 len = 0;
481 for(ptr = buf; *ptr; ptr++) {
482 if(*ptr == '%') {
483 if(hex_to_int(*(ptr+1))!=-1 && hex_to_int(*(ptr+2))!=-1) {
484 ret[len] = (hex_to_int(*(ptr+1))<<4) + hex_to_int(*(ptr+2));
485 ptr += 2;
486 }
487 else if(*(ptr+1)=='u' && hex_to_int(*(ptr+2))!=-1 && hex_to_int(*(ptr+3))!=-1
488 && hex_to_int(*(ptr+4))!=-1 && hex_to_int(*(ptr+5))!=-1) {
489 ret[len] = (hex_to_int(*(ptr+2))<<12) + (hex_to_int(*(ptr+3))<<8)
490 + (hex_to_int(*(ptr+4))<<4) + hex_to_int(*(ptr+5));
491 ptr += 5;
492 }
493 else
494 ret[len] = *ptr;
495 }
496 else
497 ret[len] = *ptr;
498
499 len++;
500 }
501
503
504 if(r)
505 *r = jsval_string(ret_str);
506 else
507 jsstr_release(ret_str);
508 return S_OK;
509}
510
512 jsval_t *r)
513{
514 FIXME("\n");
515 return E_NOTIMPL;
516}
517
519 jsval_t *r)
520{
521 TRACE("\n");
522
523 if(r) {
524 jsstr_t *ret;
525
526 ret = jsstr_alloc(L"JScript");
527 if(!ret)
528 return E_OUTOFMEMORY;
529
530 *r = jsval_string(ret);
531 }
532
533 return S_OK;
534}
535
537 jsval_t *r)
538{
539 TRACE("\n");
540
541 if(r)
543 return S_OK;
544}
545
547 jsval_t *r)
548{
549 TRACE("\n");
550
551 if(r)
553 return S_OK;
554}
555
557 jsval_t *r)
558{
559 TRACE("\n");
560
561 if(r)
563 return S_OK;
564}
565
567 jsval_t *r)
568{
569 return gc_run(ctx);
570}
571
573 jsval_t *r)
574{
575 const WCHAR *ptr, *uri;
576 jsstr_t *str, *ret;
577 DWORD len = 0, i;
578 char buf[4];
579 WCHAR *rptr;
581
582 TRACE("\n");
583
584 if(!argc) {
585 if(r)
587 return S_OK;
588 }
589
590 hres = to_flat_string(ctx, argv[0], &str, &uri);
591 if(FAILED(hres))
592 return hres;
593
594 for(ptr = uri; *ptr; ptr++) {
595 if(is_uri_unescaped(*ptr) || is_uri_reserved(*ptr) || *ptr == '#') {
596 len++;
597 }else {
599 if(!i) {
602 }
603
604 len += i;
605 }
606 }
607
608 ret = jsstr_alloc_buf(len, &rptr);
609 if(!ret) {
611 return E_OUTOFMEMORY;
612 }
613
614 for(ptr = uri; *ptr; ptr++) {
615 if(is_uri_unescaped(*ptr) || is_uri_reserved(*ptr) || *ptr == '#') {
616 *rptr++ = *ptr;
617 }else {
619 for(i=0; i<len; i++) {
620 *rptr++ = '%';
621 *rptr++ = int_to_char((BYTE)buf[i] >> 4);
622 *rptr++ = int_to_char(buf[i] & 0x0f);
623 }
624 }
625 }
626
627 TRACE("%s -> %s\n", debugstr_jsstr(str), debugstr_jsstr(ret));
629
630 if(r)
631 *r = jsval_string(ret);
632 else
634 return S_OK;
635}
636
638 jsval_t *r)
639{
640 const WCHAR *ptr, *uri;
641 jsstr_t *str, *ret_str;
642 unsigned len = 0;
643 int i, val, res;
644 WCHAR *ret;
645 char buf[4];
646 WCHAR out;
648
649 TRACE("\n");
650
651 if(!argc) {
652 if(r)
654 return S_OK;
655 }
656
657 hres = to_flat_string(ctx, argv[0], &str, &uri);
658 if(FAILED(hres))
659 return hres;
660
661 for(ptr = uri; *ptr; ptr++) {
662 if(*ptr != '%') {
663 len++;
664 }else {
665 res = 0;
666 for(i=0; i<4; i++) {
667 if(ptr[i*3]!='%' || hex_to_int(ptr[i*3+1])==-1 || (val=hex_to_int(ptr[i*3+2]))==-1)
668 break;
669 val += hex_to_int(ptr[i*3+1])<<4;
670 buf[i] = val;
671
673 if(res)
674 break;
675 }
676
677 if(!res) {
680 }
681
682 ptr += i*3+2;
683 len++;
684 }
685 }
686
687 ret_str = jsstr_alloc_buf(len, &ret);
688 if(!ret_str) {
690 return E_OUTOFMEMORY;
691 }
692
693 for(ptr = uri; *ptr; ptr++) {
694 if(*ptr != '%') {
695 *ret++ = *ptr;
696 }else {
697 for(i=0; i<4; i++) {
698 if(ptr[i*3]!='%' || hex_to_int(ptr[i*3+1])==-1 || (val=hex_to_int(ptr[i*3+2]))==-1)
699 break;
700 val += hex_to_int(ptr[i*3+1])<<4;
701 buf[i] = val;
702
704 if(res)
705 break;
706 }
707
708 ptr += i*3+2;
709 ret++;
710 }
711 }
712
713 TRACE("%s -> %s\n", debugstr_jsstr(str), debugstr_jsstr(ret_str));
715
716 if(r)
717 *r = jsval_string(ret_str);
718 else
719 jsstr_release(ret_str);
720 return S_OK;
721}
722
724 jsval_t *r)
725{
726 jsstr_t *str, *ret_str;
727 char buf[4];
728 const WCHAR *ptr, *uri;
729 DWORD len = 0, size, i;
730 WCHAR *ret;
732
733 TRACE("\n");
734
735 if(!argc) {
736 if(r)
738 return S_OK;
739 }
740
741 hres = to_flat_string(ctx, argv[0], &str, &uri);
742 if(FAILED(hres))
743 return hres;
744
745 for(ptr = uri; *ptr; ptr++) {
747 len++;
748 else {
750 if(!size) {
753 }
754 len += size*3;
755 }
756 }
757
758 ret_str = jsstr_alloc_buf(len, &ret);
759 if(!ret_str) {
761 return E_OUTOFMEMORY;
762 }
763
764 for(ptr = uri; *ptr; ptr++) {
765 if(is_uri_unescaped(*ptr)) {
766 *ret++ = *ptr;
767 }else {
769 for(i=0; i<size; i++) {
770 *ret++ = '%';
771 *ret++ = int_to_char((BYTE)buf[i] >> 4);
772 *ret++ = int_to_char(buf[i] & 0x0f);
773 }
774 }
775 }
776
778
779 if(r)
780 *r = jsval_string(ret_str);
781 else
782 jsstr_release(ret_str);
783 return S_OK;
784}
785
786/* ECMA-262 3rd Edition 15.1.3.2 */
788 jsval_t *r)
789{
790 const WCHAR *ptr, *uri;
791 jsstr_t *str, *ret;
792 WCHAR *out_ptr;
793 DWORD len = 0;
795
796 TRACE("\n");
797
798 if(!argc) {
799 if(r)
801 return S_OK;
802 }
803
804 hres = to_flat_string(ctx, argv[0], &str, &uri);
805 if(FAILED(hres))
806 return hres;
807
808 ptr = uri;
809 while(*ptr) {
810 if(*ptr == '%') {
811 char octets[4];
812 unsigned char mask = 0x80;
813 int i, size, num_bytes = 0;
814 if(hex_to_int(*(ptr+1)) < 0 || hex_to_int(*(ptr+2)) < 0) {
815 FIXME("Throw URIError: Invalid hex sequence\n");
817 return E_FAIL;
818 }
819 octets[0] = (hex_to_int(*(ptr+1)) << 4) + hex_to_int(*(ptr+2));
820 ptr += 3;
821 while(octets[0] & mask) {
822 mask = mask >> 1;
823 ++num_bytes;
824 }
825 if(num_bytes == 1 || num_bytes > 4) {
826 FIXME("Throw URIError: Invalid initial UTF character\n");
828 return E_FAIL;
829 }
830 for(i = 1; i < num_bytes; ++i) {
831 if(*ptr != '%'){
832 FIXME("Throw URIError: Incomplete UTF sequence\n");
834 return E_FAIL;
835 }
836 if(hex_to_int(*(ptr+1)) < 0 || hex_to_int(*(ptr+2)) < 0) {
837 FIXME("Throw URIError: Invalid hex sequence\n");
839 return E_FAIL;
840 }
841 octets[i] = (hex_to_int(*(ptr+1)) << 4) + hex_to_int(*(ptr+2));
842 ptr += 3;
843 }
845 num_bytes ? num_bytes : 1, NULL, 0);
846 if(size == 0) {
847 FIXME("Throw URIError: Invalid UTF sequence\n");
849 return E_FAIL;
850 }
851 len += size;
852 }else {
853 ++ptr;
854 ++len;
855 }
856 }
857
858 ret = jsstr_alloc_buf(len, &out_ptr);
859 if(!ret) {
861 return E_OUTOFMEMORY;
862 }
863
864 ptr = uri;
865 while(*ptr) {
866 if(*ptr == '%') {
867 char octets[4];
868 unsigned char mask = 0x80;
869 int i, size, num_bytes = 0;
870 octets[0] = (hex_to_int(*(ptr+1)) << 4) + hex_to_int(*(ptr+2));
871 ptr += 3;
872 while(octets[0] & mask) {
873 mask = mask >> 1;
874 ++num_bytes;
875 }
876 for(i = 1; i < num_bytes; ++i) {
877 octets[i] = (hex_to_int(*(ptr+1)) << 4) + hex_to_int(*(ptr+2));
878 ptr += 3;
879 }
881 num_bytes ? num_bytes : 1, out_ptr, len);
882 len -= size;
883 out_ptr += size;
884 }else {
885 *out_ptr++ = *ptr++;
886 --len;
887 }
888 }
889
891
892 if(r)
893 *r = jsval_string(ret);
894 else
896 return S_OK;
897}
898
900 {L"CollectGarbage", JSGlobal_CollectGarbage, PROPF_METHOD},
901 {L"GetObject", JSGlobal_GetObject, PROPF_METHOD|2},
902 {L"ScriptEngine", JSGlobal_ScriptEngine, PROPF_METHOD},
903 {L"ScriptEngineBuildVersion", JSGlobal_ScriptEngineBuildVersion, PROPF_METHOD},
904 {L"ScriptEngineMajorVersion", JSGlobal_ScriptEngineMajorVersion, PROPF_METHOD},
905 {L"ScriptEngineMinorVersion", JSGlobal_ScriptEngineMinorVersion, PROPF_METHOD},
906 {L"decodeURI", JSGlobal_decodeURI, PROPF_METHOD|1},
907 {L"decodeURIComponent", JSGlobal_decodeURIComponent, PROPF_METHOD|1},
908 {L"encodeURI", JSGlobal_encodeURI, PROPF_METHOD|1},
909 {L"encodeURIComponent", JSGlobal_encodeURIComponent, PROPF_METHOD|1},
910 {L"escape", JSGlobal_escape, PROPF_METHOD|1},
911 {L"eval", JSGlobal_eval, PROPF_METHOD|1},
912 {L"isFinite", JSGlobal_isFinite, PROPF_METHOD|1},
913 {L"isNaN", JSGlobal_isNaN, PROPF_METHOD|1},
914 {L"parseFloat", JSGlobal_parseFloat, PROPF_METHOD|1},
915 {L"parseInt", JSGlobal_parseInt, PROPF_METHOD|2},
916 {L"unescape", JSGlobal_unescape, PROPF_METHOD|1}
917};
918
921 .props_cnt = ARRAY_SIZE(JSGlobal_props),
922 .props = JSGlobal_props,
923};
924
926{
928 HRESULT hres = S_OK;
929
930 /* __proto__ is an actual accessor on native, despite being a builtin */
931 if(ctx->version >= SCRIPTLANGUAGEVERSION_ES6) {
932 desc.flags = PROPF_CONFIGURABLE;
934 desc.explicit_getter = desc.explicit_setter = TRUE;
935 desc.explicit_value = FALSE;
936
938 if(SUCCEEDED(hres)) {
940 if(SUCCEEDED(hres)) {
941 hres = jsdisp_define_property(object_prototype, L"__proto__", &desc);
942 jsdisp_release(desc.setter);
943 }
944 jsdisp_release(desc.getter);
945 }
946 }
947 return hres;
948}
949
951{
953
954 hres = init_function_constr(ctx, object_prototype);
955 if(FAILED(hres))
956 return hres;
957
959 jsval_obj(ctx->function_constr));
960 if(FAILED(hres))
961 return hres;
962
963 hres = create_object_constr(ctx, object_prototype, &ctx->object_constr);
964 if(FAILED(hres))
965 return hres;
966
968 jsval_obj(ctx->object_constr));
969 if(FAILED(hres))
970 return hres;
971
972 hres = create_array_constr(ctx, object_prototype, &ctx->array_constr);
973 if(FAILED(hres))
974 return hres;
975
977 jsval_obj(ctx->array_constr));
978 if(FAILED(hres))
979 return hres;
980
981 hres = create_bool_constr(ctx, object_prototype, &ctx->bool_constr);
982 if(FAILED(hres))
983 return hres;
984
986 jsval_obj(ctx->bool_constr));
987 if(FAILED(hres))
988 return hres;
989
990 hres = create_date_constr(ctx, object_prototype, &ctx->date_constr);
991 if(FAILED(hres))
992 return hres;
993
995 jsval_obj(ctx->date_constr));
996 if(FAILED(hres))
997 return hres;
998
999 hres = create_enumerator_constr(ctx, object_prototype, &ctx->enumerator_constr);
1000 if(FAILED(hres))
1001 return hres;
1002
1004 jsval_obj(ctx->enumerator_constr));
1005 if(FAILED(hres))
1006 return hres;
1007
1008 hres = init_error_constr(ctx, object_prototype);
1009 if(FAILED(hres))
1010 return hres;
1011
1013 jsval_obj(ctx->error_constr));
1014 if(FAILED(hres))
1015 return hres;
1016
1018 jsval_obj(ctx->eval_error_constr));
1019 if(FAILED(hres))
1020 return hres;
1021
1023 jsval_obj(ctx->range_error_constr));
1024 if(FAILED(hres))
1025 return hres;
1026
1028 jsval_obj(ctx->reference_error_constr));
1029 if(FAILED(hres))
1030 return hres;
1031
1033 jsval_obj(ctx->regexp_error_constr));
1034 if(FAILED(hres))
1035 return hres;
1036
1038 jsval_obj(ctx->syntax_error_constr));
1039 if(FAILED(hres))
1040 return hres;
1041
1043 jsval_obj(ctx->type_error_constr));
1044 if(FAILED(hres))
1045 return hres;
1046
1048 jsval_obj(ctx->uri_error_constr));
1049 if(FAILED(hres))
1050 return hres;
1051
1052 hres = create_number_constr(ctx, object_prototype, &ctx->number_constr);
1053 if(FAILED(hres))
1054 return hres;
1055
1057 jsval_obj(ctx->number_constr));
1058 if(FAILED(hres))
1059 return hres;
1060
1061 hres = create_regexp_constr(ctx, object_prototype, &ctx->regexp_constr);
1062 if(FAILED(hres))
1063 return hres;
1064
1066 jsval_obj(ctx->regexp_constr));
1067 if(FAILED(hres))
1068 return hres;
1069
1070 hres = create_string_constr(ctx, object_prototype, &ctx->string_constr);
1071 if(FAILED(hres))
1072 return hres;
1073
1075 jsval_obj(ctx->string_constr));
1076 if(FAILED(hres))
1077 return hres;
1078
1079 hres = create_vbarray_constr(ctx, object_prototype, &ctx->vbarray_constr);
1080 if(FAILED(hres))
1081 return hres;
1082
1084 jsval_obj(ctx->vbarray_constr));
1085 if(FAILED(hres))
1086 return hres;
1087
1088 return S_OK;
1089}
1090
1092{
1093 unsigned const_flags = ctx->version >= SCRIPTLANGUAGEVERSION_ES5 ? 0 : PROPF_WRITABLE;
1094 jsdisp_t *math, *constr;
1095 HRESULT hres;
1096
1097 if(ctx->global)
1098 return S_OK;
1099
1100 hres = create_dispex(ctx, &JSGlobal_info, NULL, &ctx->global);
1101 if(FAILED(hres))
1102 return hres;
1103
1104 hres = create_object_prototype(ctx, &ctx->object_prototype);
1105 if(FAILED(hres))
1106 return hres;
1107
1108 hres = init_constructors(ctx, ctx->object_prototype);
1109 if(FAILED(hres))
1110 return hres;
1111
1112 hres = init_object_prototype_accessors(ctx, ctx->object_prototype);
1113 if(FAILED(hres))
1114 return hres;
1115
1116 hres = create_math(ctx, &math);
1117 if(FAILED(hres))
1118 return hres;
1119
1121 jsdisp_release(math);
1122 if(FAILED(hres))
1123 return hres;
1124
1125 if(ctx->version >= 2) {
1126 jsdisp_t *json;
1127
1128 hres = create_json(ctx, &json);
1129 if(FAILED(hres))
1130 return hres;
1131
1133 jsdisp_release(json);
1134 if(FAILED(hres))
1135 return hres;
1136 }
1137
1138 hres = create_activex_constr(ctx, &constr);
1139 if(FAILED(hres))
1140 return hres;
1141
1143 jsval_obj(constr));
1144 jsdisp_release(constr);
1145 if(FAILED(hres))
1146 return hres;
1147
1148 hres = jsdisp_define_data_property(ctx->global, L"undefined", const_flags, jsval_undefined());
1149 if(FAILED(hres))
1150 return hres;
1151
1152 hres = jsdisp_define_data_property(ctx->global, L"NaN", const_flags, jsval_number(NAN));
1153 if(FAILED(hres))
1154 return hres;
1155
1156 hres = jsdisp_define_data_property(ctx->global, L"Infinity", const_flags, jsval_number(INFINITY));
1157 if(FAILED(hres))
1158 return hres;
1159
1161 if(FAILED(hres))
1162 return hres;
1163
1164 return init_set_constructor(ctx);
1165}
HRESULT create_array_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
Definition: array.c:1765
HRESULT init_arraybuf_constructors(script_ctx_t *ctx)
Definition: arraybuf.c:692
#define is_digit(c)
Definition: astoll.c:39
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:20
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
HRESULT create_bool_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
Definition: bool.c:196
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define __attribute__(x)
Definition: wpp_private.h:207
static const WCHAR empty[1]
Definition: string.c:47
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
HRESULT create_activex_constr(script_ctx_t *ctx, jsdisp_t **ret)
Definition: activex.c:189
HRESULT create_date_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
Definition: date.c:2442
HRESULT init_error_constr(script_ctx_t *ctx, jsdisp_t *object_prototype)
Definition: error.c:321
HRESULT init_function_constr(script_ctx_t *ctx, jsdisp_t *object_prototype)
Definition: function.c:1476
HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
Definition: function.c:773
#define JSCRIPT_MAJOR_VERSION
Definition: resource.h:21
#define JSCRIPT_BUILD_VERSION
Definition: resource.h:23
#define JSCRIPT_MINOR_VERSION
Definition: resource.h:22
MonoAssembly int argc
Definition: metahost.c:107
#define INT_MIN
Definition: limits.h:25
#define INT_MAX
Definition: limits.h:26
#define isfinite(x)
Definition: math.h:363
#define isnan(x)
Definition: math.h:360
#define NAN
Definition: math.h:273
#define INFINITY
Definition: math.h:272
static double ret_nan(BOOL update_sw)
Definition: math.c:84
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, function_code_t *function, scope_chain_t *scope, IDispatch *this_obj, jsdisp_t *function_instance, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: engine.c:3425
#define EXEC_GLOBAL
Definition: engine.h:305
#define EXEC_RETURN_TO_INTERP
Definition: engine.h:307
#define EXEC_EVAL
Definition: engine.h:308
HRESULT create_enumerator_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
Definition: enumerator.c:320
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
double pow(double x, double y)
Definition: freeldr.c:179
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble n
Definition: glext.h:7729
GLuint res
Definition: glext.h:9613
GLenum src
Definition: glext.h:6340
GLsizeiptr size
Definition: glext.h:5919
const GLubyte * c
Definition: glext.h:8905
GLenum GLint GLuint mask
Definition: glext.h:6028
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define WC_ERR_INVALID_CHARS
Definition: unicode.h:47
#define MB_ERR_INVALID_CHARS
Definition: unicode.h:41
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
void release_bytecode(bytecode_t *code)
Definition: compile.c:2459
HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, UINT64 source_context, unsigned start_line, const WCHAR *args, const WCHAR *delimiter, BOOL from_eval, BOOL use_decode, named_item_t *named_item, bytecode_t **ret)
Definition: compile.c:2725
HRESULT jsdisp_define_data_property(jsdisp_t *obj, const WCHAR *name, unsigned flags, jsval_t value)
Definition: dispex.c:3349
ULONG jsdisp_release(jsdisp_t *obj)
Definition: dispex.c:1911
HRESULT create_dispex(script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype, jsdisp_t **dispex)
Definition: dispex.c:2493
HRESULT jsdisp_define_property(jsdisp_t *obj, const WCHAR *name, property_desc_t *desc)
Definition: dispex.c:3216
HRESULT gc_run(script_ctx_t *ctx)
Definition: dispex.c:928
static const builtin_info_t JSGlobal_info
Definition: global.c:919
static const builtin_prop_t JSGlobal_props[]
Definition: global.c:899
static int hex_to_int(const WCHAR wch)
Definition: global.c:434
static int uri_char_table[]
Definition: global.c:34
static HRESULT JSGlobal_escape(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:72
HRESULT JSGlobal_eval(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:180
static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:637
static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
Definition: global.c:950
static BOOL is_ecma_nonblank(const WCHAR c)
Definition: global.c:59
static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:572
static WCHAR int_to_char(int i)
Definition: global.c:65
HRESULT init_global(script_ctx_t *ctx)
Definition: global.c:1091
static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:723
static HRESULT JSGlobal_unescape(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:441
static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:326
static HRESULT JSGlobal_GetObject(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:511
static HRESULT JSGlobal_ScriptEngineBuildVersion(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:556
HRESULT builtin_eval(script_ctx_t *ctx, call_frame_t *frame, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:137
static BOOL is_uri_reserved(WCHAR c)
Definition: global.c:48
static HRESULT JSGlobal_isNaN(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:186
static HRESULT JSGlobal_ScriptEngineMajorVersion(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:536
static HRESULT JSGlobal_CollectGarbage(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:566
static HRESULT init_object_prototype_accessors(script_ctx_t *ctx, jsdisp_t *object_prototype)
Definition: global.c:925
static HRESULT JSGlobal_ScriptEngine(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:518
static HRESULT JSGlobal_ScriptEngineMinorVersion(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:546
static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:787
static INT char_to_int(WCHAR c)
Definition: global.c:232
static BOOL is_uri_unescaped(WCHAR c)
Definition: global.c:53
static HRESULT JSGlobal_parseInt(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:243
static HRESULT JSGlobal_isFinite(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:209
HRESULT to_flat_string(script_ctx_t *, jsval_t, jsstr_t **, const WCHAR **)
Definition: jsutils.c:846
HRESULT Object_get_proto_(script_ctx_t *, jsval_t, WORD, unsigned, jsval_t *, jsval_t *)
Definition: object.c:393
HRESULT create_math(script_ctx_t *, jsdisp_t **)
Definition: math.c:503
#define DISPATCH_JSCRIPT_CALLEREXECSSOURCE
Definition: jscript.h:98
#define SCRIPTLANGUAGEVERSION_ES6
Definition: jscript.h:54
HRESULT create_object_prototype(script_ctx_t *, jsdisp_t **)
Definition: object.c:1126
HRESULT create_string_constr(script_ctx_t *, jsdisp_t *, jsdisp_t **)
Definition: string.c:1720
#define SCRIPTLANGUAGEVERSION_ES5
Definition: jscript.h:53
HRESULT create_vbarray_constr(script_ctx_t *, jsdisp_t *, jsdisp_t **)
Definition: vbarray.c:321
#define JS_E_INVALID_URI_CHAR
Definition: jscript.h:568
HRESULT create_number_constr(script_ctx_t *, jsdisp_t *, jsdisp_t **)
Definition: number.c:682
#define JS_E_INVALID_URI_CODING
Definition: jscript.h:567
HRESULT init_set_constructor(script_ctx_t *)
Definition: set.c:894
const char * debugstr_jsval(const jsval_t)
Definition: jsutils.c:35
HRESULT create_object_constr(script_ctx_t *, jsdisp_t *, jsdisp_t **)
Definition: object.c:1120
HRESULT to_number(script_ctx_t *, jsval_t, double *)
Definition: jsutils.c:630
HRESULT to_int32(script_ctx_t *, jsval_t, INT *)
Definition: jsutils.c:735
HRESULT create_regexp_constr(script_ctx_t *, jsdisp_t *, jsdisp_t **)
Definition: jsregexp.c:964
@ JSCLASS_GLOBAL
Definition: jscript.h:110
HRESULT create_json(script_ctx_t *, jsdisp_t **)
Definition: json.c:1032
HRESULT Object_set_proto_(script_ctx_t *, jsval_t, WORD, unsigned, jsval_t *, jsval_t *)
Definition: object.c:422
const unsigned int PROPF_WRITABLE
Definition: jsdisp.idl:37
const unsigned int PROPF_ENUMERABLE
Definition: jsdisp.idl:36
const unsigned int PROPF_CONFIGURABLE
Definition: jsdisp.idl:38
const unsigned int PROPF_METHOD
Definition: jsdisp.idl:33
jsstr_t * jsstr_undefined(void)
Definition: jsstr.c:296
const char * debugstr_jsstr(jsstr_t *str)
Definition: jsstr.c:37
jsstr_t * jsstr_alloc_buf(unsigned len, WCHAR **buf)
Definition: jsstr.c:69
static const WCHAR * jsstr_flatten(jsstr_t *str)
Definition: jsstr.h:136
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:107
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:100
HRESULT jsval_copy(jsval_t v, jsval_t *r)
Definition: jsutils.c:225
static jsval_t jsval_string(jsstr_t *str)
Definition: jsval.h:109
static jsval_t jsval_undefined(void)
Definition: jsval.h:146
static jsval_t jsval_obj(jsdisp_t *obj)
Definition: jsval.h:125
static jsval_t jsval_bool(BOOL b)
Definition: jsval.h:101
static jsstr_t * get_string(jsval_t v)
Definition: jsval.h:238
static jsval_t jsval_number(double n)
Definition: jsval.h:153
#define d
Definition: ke_i.h:81
#define e
Definition: ke_i.h:82
#define c
Definition: ke_i.h:80
#define sign(x)
Definition: mapdesc.cc:613
static PVOID ptr
Definition: dispmode.c:27
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1204
HRESULT hres
Definition: protocol.c:465
const char * uri
Definition: sec_mgr.c:1588
DWORD exp
Definition: msg.c:18625
#define argv
Definition: mplay32.c:18
#define MAXLONGLONG
static BOOL is_string(parse_buffer *buf)
Definition: parsing.c:600
short WCHAR
Definition: pedump.c:58
const WCHAR * str
#define iswspace(_c)
Definition: ctype.h:669
#define CP_UTF8
Definition: nls.h:20
#define towupper(c)
Definition: wctype.h:99
#define TRACE(s)
Definition: solgame.cpp:4
named_item_t * named_item
Definition: engine.h:199
IDispatch * this_obj
Definition: engine.h:287
bytecode_t * bytecode
Definition: engine.h:299
DWORD flags
Definition: engine.h:291
scope_chain_t * scope
Definition: engine.h:282
Definition: jsstr.h:36
Definition: jsval.h:54
jsclass_t class
Definition: jscript.h:183
Definition: inflate.c:139
Definition: unary.h:15
int64_t LONGLONG
Definition: typedefs.h:68
int32_t INT
Definition: typedefs.h:58
double DOUBLE
Definition: typedefs.h:70
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
size_t const unsigned const radix
Definition: xtoa.cpp:37
unsigned char BYTE
Definition: xxhash.c:193