ReactOS 0.4.17-dev-357-ga8f14ff
array.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 <assert.h>
26
27#include "jscript.h"
28
29#include "wine/debug.h"
30
32
33typedef struct {
35
38
40{
41 return CONTAINING_RECORD(jsdisp, ArrayInstance, dispex);
42}
43
44static inline ArrayInstance *array_this(jsval_t vthis)
45{
46 jsdisp_t *jsdisp = is_object_instance(vthis) ? to_jsdisp(get_object(vthis)) : NULL;
47 return (jsdisp && is_class(jsdisp, JSCLASS_ARRAY)) ? array_from_jsdisp(jsdisp) : NULL;
48}
49
51{
54}
55
57{
58 jsdisp_t *jsdisp;
59 IDispatch *disp;
62
63 hres = to_object(ctx, vthis, &disp);
64 if(FAILED(hres))
65 return hres;
66
67 jsdisp = iface_to_jsdisp(disp);
68 IDispatch_Release(disp);
69 if(!jsdisp)
71 *jsthis = jsdisp;
72
73 if(is_class(jsdisp, JSCLASS_ARRAY)) {
74 *ret = array_from_jsdisp(jsdisp)->length;
75 return S_OK;
76 }
77
78 hres = jsdisp_propget_name(jsdisp, L"length", &val);
79 if(SUCCEEDED(hres)) {
82 if(SUCCEEDED(hres))
83 return hres;
84 }
85
86 jsdisp_release(jsdisp);
87 return hres;
88}
89
91{
94 return S_OK;
95 }
96
97 return jsdisp_propput_name(obj, L"length", jsval_number(length));
98}
99
101{
102 if(!idx) {
103 *ptr = '0';
104 return ptr;
105 }
106
107 while(idx) {
108 *ptr-- = '0' + (idx%10);
109 idx /= 10;
110 }
111
112 return ptr+1;
113}
114
116{
117 TRACE("%p\n", jsthis);
118
120 return S_OK;
121}
122
124{
126 DOUBLE len = -1;
127 DWORD i;
129
130 TRACE("%p %ld\n", This, This->length);
131
132 hres = to_number(ctx, value, &len);
133 if(FAILED(hres))
134 return hres;
135
136 len = floor(len);
137 if(len!=(DWORD)len)
138 return JS_E_INVALID_LENGTH;
139
140 for(i=len; i < This->length; i++) {
141 hres = jsdisp_delete_idx(&This->dispex, i);
142 if(FAILED(hres))
143 return hres;
144 }
145
146 This->length = len;
147 return S_OK;
148}
149
151{
152 jsval_t val;
153 DWORD i;
155
156 for(i=0; i < obj->length; i++) {
157 hres = jsdisp_get_idx(&obj->dispex, i, &val);
159 continue;
160 if(FAILED(hres))
161 return hres;
162
165 if(FAILED(hres))
166 return hres;
167 }
168
169 *len += obj->length;
170 return S_OK;
171}
172
174{
175 jsdisp_t *jsobj;
177
178 jsobj = iface_to_jsdisp(obj);
179 if(jsobj) {
180 if(is_class(jsobj, JSCLASS_ARRAY)) {
182 jsdisp_release(jsobj);
183 return hres;
184 }
185 jsdisp_release(jsobj);
186 }
187
188 return jsdisp_propput_idx(array, (*len)++, jsval_disp(obj));
189}
190
192 jsval_t *r)
193{
194 IDispatch *jsthis;
195 jsdisp_t *ret;
196 DWORD len = 0;
198
199 TRACE("\n");
200
201 hres = to_object(ctx, vthis, &jsthis);
202 if(FAILED(hres))
203 return hres;
204
205 hres = create_array(ctx, 0, &ret);
206 if(FAILED(hres))
207 goto done;
208
209 hres = concat_obj(ret, jsthis, &len);
210 if(SUCCEEDED(hres)) {
211 DWORD i;
212
213 for(i=0; i < argc; i++) {
216 else
218 if(FAILED(hres))
219 break;
220 }
221 }
222
223 if(FAILED(hres))
224 goto done;
225
226 if(r)
227 *r = jsval_obj(ret);
228 else
230done:
231 IDispatch_Release(jsthis);
232 return S_OK;
233}
234
236 unsigned seplen, HRESULT (*to_string)(script_ctx_t*,jsval_t,jsstr_t**), jsval_t *r)
237{
238 jsstr_t **str_tab, *ret = NULL;
239 jsval_t val;
240 DWORD i;
242
243 if(!length) {
244 if(r)
246 return S_OK;
247 }
248
249 str_tab = calloc(length, sizeof(*str_tab));
250 if(!str_tab)
251 return E_OUTOFMEMORY;
252
253 for(i=0; i < length; i++) {
255 if(hres == DISP_E_UNKNOWNNAME) {
256 hres = S_OK;
257 continue;
258 } else if(FAILED(hres))
259 break;
260
261 if(!is_undefined(val) && !is_null(val)) {
262 hres = to_string(ctx, val, str_tab+i);
264 if(FAILED(hres))
265 break;
266 }
267 }
268
269 if(SUCCEEDED(hres)) {
270 DWORD len = 0;
271
272 if(str_tab[0])
273 len = jsstr_length(str_tab[0]);
274 for(i=1; i < length; i++) {
275 len += seplen;
276 if(str_tab[i])
277 len += jsstr_length(str_tab[i]);
278 if(len > JSSTR_MAX_LENGTH) {
280 break;
281 }
282 }
283
284 if(SUCCEEDED(hres)) {
285 WCHAR *ptr = NULL;
286
288 if(ret) {
289 if(str_tab[0])
290 ptr += jsstr_flush(str_tab[0], ptr);
291
292 for(i=1; i < length; i++) {
293 if(seplen) {
294 memcpy(ptr, sep, seplen*sizeof(WCHAR));
295 ptr += seplen;
296 }
297
298 if(str_tab[i])
299 ptr += jsstr_flush(str_tab[i], ptr);
300 }
301 }else {
303 }
304 }
305 }
306
307 for(i=0; i < length; i++) {
308 if(str_tab[i])
309 jsstr_release(str_tab[i]);
310 }
311 free(str_tab);
312 if(FAILED(hres))
313 return hres;
314
315 TRACE("= %s\n", debugstr_jsstr(ret));
316
317 if(r)
318 *r = jsval_string(ret);
319 else
321 return S_OK;
322}
323
324/* ECMA-262 3rd Edition 15.4.4.5 */
326 jsval_t *r)
327{
328 jsdisp_t *jsthis;
331
332 TRACE("\n");
333
334 hres = get_length(ctx, vthis, &jsthis, &length);
335 if(FAILED(hres))
336 return hres;
337
338 if(argc) {
339 const WCHAR *sep;
340 jsstr_t *sep_str;
341
342 hres = to_flat_string(ctx, argv[0], &sep_str, &sep);
343 if(FAILED(hres))
344 goto done;
345
346 hres = array_join(ctx, jsthis, length, sep, jsstr_length(sep_str), to_string, r);
347
348 jsstr_release(sep_str);
349 }else {
350 hres = array_join(ctx, jsthis, length, L",", 1, to_string, r);
351 }
352
353done:
354 jsdisp_release(jsthis);
355 return hres;
356}
357
359 jsval_t *r)
360{
361 jsdisp_t *jsthis;
362 jsval_t val;
365
366 TRACE("\n");
367
368 hres = get_length(ctx, vthis, &jsthis, &length);
369 if(FAILED(hres))
370 return hres;
371
372 if(!length) {
373 hres = set_length(jsthis, 0);
374 if(FAILED(hres))
375 goto done;
376
377 if(r)
378 *r = jsval_undefined();
379 goto done;
380 }
381
382 length--;
383 hres = jsdisp_get_idx(jsthis, length, &val);
384 if(SUCCEEDED(hres))
385 hres = jsdisp_delete_idx(jsthis, length);
386 else if(hres == DISP_E_UNKNOWNNAME) {
388 hres = S_OK;
389 }else
390 goto done;
391
392 if(SUCCEEDED(hres))
393 hres = set_length(jsthis, length);
394
395 if(FAILED(hres)) {
397 goto done;
398 }
399
400 if(r)
401 *r = val;
402 else
404done:
405 jsdisp_release(jsthis);
406 return hres;
407}
408
409/* ECMA-262 3rd Edition 15.4.4.7 */
411 jsval_t *r)
412{
413 jsdisp_t *jsthis;
414 UINT32 length = 0;
415 unsigned i;
417
418 TRACE("\n");
419
420 hres = get_length(ctx, vthis, &jsthis, &length);
421 if(FAILED(hres))
422 return hres;
423
424 for(i=0; i < argc; i++) {
425 hres = jsdisp_propput_idx(jsthis, length+i, argv[i]);
426 if(FAILED(hres))
427 goto done;
428 }
429
430 hres = set_length(jsthis, length+argc);
431 if(FAILED(hres))
432 goto done;
433
434 if(r)
436done:
437 jsdisp_release(jsthis);
438 return hres;
439}
440
442 jsval_t *r)
443{
444 jsdisp_t *jsthis;
445 UINT32 length, k, l;
446 jsval_t v1, v2;
447 HRESULT hres1, hres2;
448
449 TRACE("\n");
450
451 hres1 = get_length(ctx, vthis, &jsthis, &length);
452 if(FAILED(hres1))
453 return hres1;
454
455 for(k=0; k<length/2; k++) {
456 l = length-k-1;
457
458 hres1 = jsdisp_get_idx(jsthis, k, &v1);
459 if(FAILED(hres1) && hres1!=DISP_E_UNKNOWNNAME)
460 goto done;
461
462 hres2 = jsdisp_get_idx(jsthis, l, &v2);
463 if(FAILED(hres2) && hres2!=DISP_E_UNKNOWNNAME) {
465 hres1 = hres2;
466 goto done;
467 }
468
469 if(hres1 == DISP_E_UNKNOWNNAME)
470 hres1 = jsdisp_delete_idx(jsthis, l);
471 else
472 hres1 = jsdisp_propput_idx(jsthis, l, v1);
473
474 if(FAILED(hres1)) {
477 goto done;
478 }
479
480 if(hres2 == DISP_E_UNKNOWNNAME)
481 hres2 = jsdisp_delete_idx(jsthis, k);
482 else
483 hres2 = jsdisp_propput_idx(jsthis, k, v2);
484
485 if(FAILED(hres2)) {
487 hres1 = hres2;
488 goto done;
489 }
490 }
491
492 if(r)
493 *r = jsval_obj(jsdisp_addref(jsthis));
494done:
495 jsdisp_release(jsthis);
496 return hres1;
497}
498
499/* ECMA-262 3rd Edition 15.4.4.9 */
501 jsval_t *r)
502{
503 jsdisp_t *jsthis;
504 UINT32 length = 0, i;
505 jsval_t v, ret;
507
508 TRACE("\n");
509
510 hres = get_length(ctx, vthis, &jsthis, &length);
511 if(FAILED(hres))
512 return hres;
513
514 if(!length) {
515 hres = set_length(jsthis, 0);
516 if(FAILED(hres))
517 goto done;
518
519 if(r)
520 *r = jsval_undefined();
521 goto done;
522 }
523
524 hres = jsdisp_get_idx(jsthis, 0, &ret);
525 if(hres == DISP_E_UNKNOWNNAME) {
527 hres = S_OK;
528 }
529
530 for(i=1; SUCCEEDED(hres) && i<length; i++) {
531 hres = jsdisp_get_idx(jsthis, i, &v);
533 hres = jsdisp_delete_idx(jsthis, i-1);
534 else if(SUCCEEDED(hres)) {
535 hres = jsdisp_propput_idx(jsthis, i-1, v);
537 }
538 }
539
540 if(SUCCEEDED(hres)) {
541 hres = jsdisp_delete_idx(jsthis, length-1);
542 if(SUCCEEDED(hres))
543 hres = set_length(jsthis, length-1);
544 }
545
546 if(FAILED(hres))
547 goto done;
548
549 if(r)
550 *r = ret;
551 else
553done:
554 jsdisp_release(jsthis);
555 return hres;
556}
557
558/* ECMA-262 3rd Edition 15.4.4.10 */
560{
561 jsdisp_t *arr, *jsthis;
565
566 TRACE("\n");
567
568 hres = get_length(ctx, vthis, &jsthis, &length);
569 if(FAILED(hres))
570 return hres;
571
572 if(argc) {
573 hres = to_number(ctx, argv[0], &range);
574 if(FAILED(hres))
575 goto done;
576
577 range = floor(range);
578 if(-range>length || isnan(range)) start = 0;
579 else if(range < 0) start = range+length;
580 else if(range <= length) start = range;
581 else start = length;
582 }
583 else start = 0;
584
585 if(argc > 1) {
586 hres = to_number(ctx, argv[1], &range);
587 if(FAILED(hres))
588 goto done;
589
590 range = floor(range);
591 if(-range>length) end = 0;
592 else if(range < 0) end = range+length;
593 else if(range <= length) end = range;
594 else end = length;
595 }
596 else end = length;
597
598 hres = create_array(ctx, (end>start)?end-start:0, &arr);
599 if(FAILED(hres))
600 goto done;
601
602 for(idx=start; idx<end; idx++) {
603 jsval_t v;
604
605 hres = jsdisp_get_idx(jsthis, idx, &v);
607 continue;
608
609 if(SUCCEEDED(hres)) {
612 }
613
614 if(FAILED(hres)) {
615 jsdisp_release(arr);
616 goto done;
617 }
618 }
619
620 if(r)
621 *r = jsval_obj(arr);
622 else
623 jsdisp_release(arr);
624 hres = S_OK;
625
626done:
627 jsdisp_release(jsthis);
628 return hres;
629}
630
632{
634
635 if(cmp_func) {
636 jsval_t args[2] = {v1, v2};
637 jsval_t res;
638 double n;
639
641 if(FAILED(hres))
642 return hres;
643
644 hres = to_number(ctx, res, &n);
646 if(FAILED(hres))
647 return hres;
648
649 if(n == 0)
650 *cmp = 0;
651 *cmp = n > 0.0 ? 1 : -1;
652 }else if(is_undefined(v1)) {
653 *cmp = is_undefined(v2) ? 0 : 1;
654 }else if(is_undefined(v2)) {
655 *cmp = -1;
656 }else if(is_number(v1) && is_number(v2)) {
657 double d = get_number(v1)-get_number(v2);
658 if(d > 0.0)
659 *cmp = 1;
660 else
661 *cmp = d < -0.0 ? -1 : 0;
662 }else {
663 jsstr_t *x, *y;
664
665 hres = to_string(ctx, v1, &x);
666 if(FAILED(hres))
667 return hres;
668
669 hres = to_string(ctx, v2, &y);
670 if(SUCCEEDED(hres)) {
671 *cmp = jsstr_cmp(x, y);
673 }
675 if(FAILED(hres))
676 return hres;
677 }
678
679 return S_OK;
680}
681
682/* ECMA-262 3rd Edition 15.4.4.11 */
684 jsval_t *r)
685{
686 jsdisp_t *jsthis, *cmp_func = NULL;
687 jsval_t *vtab, **sorttab = NULL;
689 DWORD i;
690 HRESULT hres = S_OK;
691
692 TRACE("\n");
693
694 hres = get_length(ctx, vthis, &jsthis, &length);
695 if(FAILED(hres))
696 return hres;
697
698 if(argc >= 1) {
699 if(is_object_instance(argv[0])) {
700 if(argc > 1 && ctx->version < SCRIPTLANGUAGEVERSION_ES5) {
701 WARN("invalid arg_cnt %d\n", argc);
703 goto done;
704 }
707 WARN("cmp_func is not a function\n");
708 if(cmp_func)
711 goto done;
712 }
713 }else if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5 ? !is_undefined(argv[0]) :
714 (!is_null(argv[0]) || is_null_disp(argv[0]))) {
715 WARN("invalid arg %s\n", debugstr_jsval(argv[0]));
717 goto done;
718 }
719 }
720
721 if(!length) {
722 if(cmp_func)
724 if(r)
725 *r = jsval_obj(jsdisp_addref(jsthis));
726 goto done;
727 }
728
729 vtab = calloc(length, sizeof(*vtab));
730 if(vtab) {
731 for(i=0; i<length; i++) {
732 hres = jsdisp_get_idx(jsthis, i, vtab+i);
733 if(hres == DISP_E_UNKNOWNNAME) {
734 vtab[i] = jsval_undefined();
735 hres = S_OK;
736 } else if(FAILED(hres)) {
737 WARN("Could not get elem %ld: %08lx\n", i, hres);
738 break;
739 }
740 }
741 }else {
743 }
744
745 if(SUCCEEDED(hres)) {
746 sorttab = malloc(length*2*sizeof(*sorttab));
747 if(!sorttab)
749 }
750
751 /* merge-sort */
752 if(SUCCEEDED(hres)) {
753 jsval_t *tmpv, **tmpbuf;
754 INT cmp;
755
756 tmpbuf = sorttab + length;
757 for(i=0; i < length; i++)
758 sorttab[i] = vtab+i;
759
760 for(i=0; i < length/2; i++) {
761 hres = sort_cmp(ctx, cmp_func, *sorttab[2*i+1], *sorttab[2*i], &cmp);
762 if(FAILED(hres))
763 break;
764
765 if(cmp < 0) {
766 tmpv = sorttab[2*i];
767 sorttab[2*i] = sorttab[2*i+1];
768 sorttab[2*i+1] = tmpv;
769 }
770 }
771
772 if(SUCCEEDED(hres)) {
773 DWORD k, a, b, bend;
774
775 for(k=2; k < length; k *= 2) {
776 for(i=0; i+k < length; i += 2*k) {
777 a = b = 0;
778 if(i+2*k <= length)
779 bend = k;
780 else
781 bend = length - (i+k);
782
783 memcpy(tmpbuf, sorttab+i, k*sizeof(jsval_t*));
784
785 while(a < k && b < bend) {
786 hres = sort_cmp(ctx, cmp_func, *tmpbuf[a], *sorttab[i+k+b], &cmp);
787 if(FAILED(hres))
788 break;
789
790 if(cmp < 0) {
791 sorttab[i+a+b] = tmpbuf[a];
792 a++;
793 }else {
794 sorttab[i+a+b] = sorttab[i+k+b];
795 b++;
796 }
797 }
798
799 if(FAILED(hres))
800 break;
801
802 if(a < k)
803 memcpy(sorttab+i+a+b, tmpbuf+a, (k-a)*sizeof(jsval_t*));
804 }
805
806 if(FAILED(hres))
807 break;
808 }
809 }
810
811 for(i=0; SUCCEEDED(hres) && i < length; i++)
812 hres = jsdisp_propput_idx(jsthis, i, *sorttab[i]);
813 }
814
815 if(vtab) {
816 for(i=0; i < length; i++)
817 jsval_release(vtab[i]);
818 free(vtab);
819 }
820 free(sorttab);
821 if(cmp_func)
823
824 if(FAILED(hres))
825 goto done;
826
827 if(r)
828 *r = jsval_obj(jsdisp_addref(jsthis));
829done:
830 jsdisp_release(jsthis);
831 return hres;
832}
833
834/* ECMA-262 3rd Edition 15.4.4.12 */
836 jsval_t *r)
837{
838 UINT32 length, start=0, delete_cnt=0, i, add_args = 0;
839 jsdisp_t *ret_array = NULL, *jsthis;
840 jsval_t val;
841 double d;
842 int n;
843 HRESULT hres = S_OK;
844
845 TRACE("\n");
846
847 hres = get_length(ctx, vthis, &jsthis, &length);
848 if(FAILED(hres))
849 return hres;
850
851 if(argc) {
852 hres = to_integer(ctx, argv[0], &d);
853 if(FAILED(hres))
854 goto done;
855
856 if(is_int32(d)) {
857 if((n = d) >= 0)
858 start = min(n, length);
859 else
860 start = -n > length ? 0 : length + n;
861 }else {
862 start = d < 0.0 ? 0 : length;
863 }
864 }
865
866 if(argc >= 2) {
867 hres = to_integer(ctx, argv[1], &d);
868 if(FAILED(hres))
869 goto done;
870
871 if(is_int32(d)) {
872 if((n = d) > 0)
873 delete_cnt = min(n, length-start);
874 }else if(d > 0.0) {
875 delete_cnt = length-start;
876 }
877
878 add_args = argc-2;
879 } else if (argc && ctx->version >= SCRIPTLANGUAGEVERSION_ES5) {
880 delete_cnt = length-start;
881 }
882
883 if(r) {
884 hres = create_array(ctx, 0, &ret_array);
885 if(FAILED(hres))
886 goto done;
887
888 for(i=0; SUCCEEDED(hres) && i < delete_cnt; i++) {
889 hres = jsdisp_get_idx(jsthis, start+i, &val);
890 if(hres == DISP_E_UNKNOWNNAME) {
891 hres = S_OK;
892 }else if(SUCCEEDED(hres)) {
893 hres = jsdisp_propput_idx(ret_array, i, val);
895 }
896 }
897
898 if(SUCCEEDED(hres))
899 hres = jsdisp_propput_name(ret_array, L"length", jsval_number(delete_cnt));
900 }
901
902 if(add_args < delete_cnt) {
903 for(i = start; SUCCEEDED(hres) && i < length-delete_cnt; i++) {
904 hres = jsdisp_get_idx(jsthis, i+delete_cnt, &val);
905 if(hres == DISP_E_UNKNOWNNAME) {
906 hres = jsdisp_delete_idx(jsthis, i+add_args);
907 }else if(SUCCEEDED(hres)) {
908 hres = jsdisp_propput_idx(jsthis, i+add_args, val);
910 }
911 }
912
913 for(i=length; SUCCEEDED(hres) && i != length-delete_cnt+add_args; i--)
914 hres = jsdisp_delete_idx(jsthis, i-1);
915 }else if(add_args > delete_cnt) {
916 for(i=length-delete_cnt; SUCCEEDED(hres) && i != start; i--) {
917 hres = jsdisp_get_idx(jsthis, i+delete_cnt-1, &val);
918 if(hres == DISP_E_UNKNOWNNAME) {
919 hres = jsdisp_delete_idx(jsthis, i+add_args-1);
920 }else if(SUCCEEDED(hres)) {
921 hres = jsdisp_propput_idx(jsthis, i+add_args-1, val);
923 }
924 }
925 }
926
927 for(i=0; SUCCEEDED(hres) && i < add_args; i++)
928 hres = jsdisp_propput_idx(jsthis, start+i, argv[i+2]);
929
930 if(SUCCEEDED(hres))
931 hres = jsdisp_propput_name(jsthis, L"length", jsval_number(length-delete_cnt+add_args));
932
933 if(FAILED(hres)) {
934 if(ret_array)
935 jsdisp_release(ret_array);
936 goto done;
937 }
938
939 if(r)
940 *r = jsval_obj(ret_array);
941done:
942 jsdisp_release(jsthis);
943 return hres;
944}
945
946/* ECMA-262 3rd Edition 15.4.4.2 */
948 jsval_t *r)
949{
951
952 TRACE("\n");
953
954 array = array_this(vthis);
955 if(!array)
956 return JS_E_ARRAY_EXPECTED;
957
958 return array_join(ctx, &array->dispex, array->length, L",", 1, to_string, r);
959}
960
962{
963 jsdisp_t *jsdisp;
964 IDispatch *obj;
966
967 switch(jsval_type(val)) {
968 case JSV_OBJECT:
969 hres = disp_call_name(ctx, get_object(val), L"toLocaleString", DISPATCH_METHOD, 0, NULL, &val);
970 if(FAILED(hres)) {
973 return hres;
974 }
975 break;
976 case JSV_NUMBER:
977 if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5)
979 /* fall through */
980 default:
981 if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5)
982 break;
983
984 hres = to_object(ctx, val, &obj);
985 if(FAILED(hres))
986 return hres;
987
988 jsdisp = as_jsdisp(obj);
989 hres = jsdisp_call_name(jsdisp, L"toLocaleString", DISPATCH_METHOD, 0, NULL, &val);
990 jsdisp_release(jsdisp);
991 if(FAILED(hres))
992 return hres;
993 break;
994 }
995
996 return to_string(ctx, val, str);
997}
998
1000 jsval_t *r)
1001{
1002 jsdisp_t *jsthis;
1003 UINT32 length;
1004 HRESULT hres;
1005 WCHAR buf[5];
1006 int len;
1007
1008 TRACE("\n");
1009
1010 if(ctx->version < SCRIPTLANGUAGEVERSION_ES5) {
1011 ArrayInstance *array = array_this(vthis);
1012 if(!array)
1013 return JS_E_ARRAY_EXPECTED;
1014 jsthis = jsdisp_addref(&array->dispex);
1015 length = array->length;
1016 }else {
1017 hres = get_length(ctx, vthis, &jsthis, &length);
1018 if(FAILED(hres))
1019 return hres;
1020 }
1021
1022 if(!(len = GetLocaleInfoW(ctx->lcid, LOCALE_SLIST, buf, ARRAY_SIZE(buf) - 1))) {
1023 buf[len++] = ',';
1024 len++;
1025 }
1026 buf[len - 1] = ' ';
1027 buf[len] = '\0';
1028
1030 jsdisp_release(jsthis);
1031 return hres;
1032}
1033
1035 jsval_t *r)
1036{
1037 jsval_t context_this = jsval_undefined();
1038 jsval_t value, args[3], res;
1039 BOOL boolval, ret = TRUE;
1041 unsigned length, i;
1042 jsdisp_t *jsthis;
1043 HRESULT hres;
1044
1045 TRACE("\n");
1046
1047 hres = get_length(ctx, vthis, &jsthis, &length);
1048 if(FAILED(hres))
1049 return hres;
1050
1051 /* FIXME: check IsCallable */
1052 if(!argc || !is_object_instance(argv[0])) {
1053 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1055 goto done;
1056 }
1057 callback = get_object(argv[0]);
1058
1059 if(argc > 1)
1060 context_this = argv[1];
1061
1062 for(i = 0; i < length; i++) {
1063 hres = jsdisp_get_idx(jsthis, i, &value);
1064 if(FAILED(hres)) {
1066 continue;
1067 goto done;
1068 }
1069 args[0] = value;
1070 args[1] = jsval_number(i);
1071 args[2] = jsval_obj(jsthis);
1074 if(FAILED(hres))
1075 goto done;
1076
1077 hres = to_boolean(res, &boolval);
1079 if(FAILED(hres))
1080 goto done;
1081 if(!boolval) {
1082 ret = FALSE;
1083 break;
1084 }
1085 }
1086
1087 if(r)
1088 *r = jsval_bool(ret);
1089 hres = S_OK;
1090done:
1091 jsdisp_release(jsthis);
1092 return hres;
1093}
1094
1096 jsval_t *r)
1097{
1098 jsval_t context_this = jsval_undefined();
1099 jsval_t value, args[3], res;
1100 unsigned length, i, j = 0;
1101 jsdisp_t *jsthis, *arr;
1103 HRESULT hres;
1104 BOOL boolval;
1105
1106 TRACE("\n");
1107
1108 hres = get_length(ctx, vthis, &jsthis, &length);
1109 if(FAILED(hres))
1110 return hres;
1111
1112 /* FIXME: check IsCallable */
1113 if(!argc || !is_object_instance(argv[0])) {
1114 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1116 goto done;
1117 }
1118 callback = get_object(argv[0]);
1119
1120 if(argc > 1)
1121 context_this = argv[1];
1122
1123 hres = create_array(ctx, 0, &arr);
1124 if(FAILED(hres))
1125 goto done;
1126
1127 for(i = 0; i < length; i++) {
1128 hres = jsdisp_get_idx(jsthis, i, &value);
1129 if(FAILED(hres)) {
1130 if(hres == DISP_E_UNKNOWNNAME) {
1131 hres = S_OK;
1132 continue;
1133 }
1134 break;
1135 }
1136 args[0] = value;
1137 args[1] = jsval_number(i);
1138 args[2] = jsval_obj(jsthis);
1140 if(SUCCEEDED(hres)) {
1141 hres = to_boolean(res, &boolval);
1143 if(SUCCEEDED(hres) && boolval)
1144 hres = jsdisp_propput_idx(arr, j++, value);
1145 }
1147 if(FAILED(hres))
1148 break;
1149 }
1150
1151 if(FAILED(hres)) {
1152 jsdisp_release(arr);
1153 goto done;
1154 }
1155 set_length(arr, j);
1156
1157 if(r)
1158 *r = jsval_obj(arr);
1159 else
1160 jsdisp_release(arr);
1161done:
1162 jsdisp_release(jsthis);
1163 return hres;
1164}
1165
1167 jsval_t *r)
1168{
1169 jsval_t context_this = jsval_undefined();
1170 jsval_t value, args[3], res;
1172 jsdisp_t *jsthis;
1173 unsigned length, i;
1174 HRESULT hres;
1175
1176 TRACE("\n");
1177
1178 hres = get_length(ctx, vthis, &jsthis, &length);
1179 if(FAILED(hres))
1180 return hres;
1181
1182 /* Fixme check IsCallable */
1183 if(!argc || !is_object_instance(argv[0])) {
1184 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1186 goto done;
1187 }
1188 callback = get_object(argv[0]);
1189
1190 if(argc > 1)
1191 context_this = argv[1];
1192
1193 for(i = 0; i < length; i++) {
1194 hres = jsdisp_get_idx(jsthis, i, &value);
1196 continue;
1197 if(FAILED(hres))
1198 goto done;
1199
1200 args[0] = value;
1201 args[1] = jsval_number(i);
1202 args[2] = jsval_obj(jsthis);
1205 if(FAILED(hres))
1206 goto done;
1208 }
1209
1210 if(r) *r = jsval_undefined();
1211 hres = S_OK;
1212done:
1213 jsdisp_release(jsthis);
1214 return hres;
1215}
1216
1218 jsval_t *r)
1219{
1220 jsdisp_t *jsthis;
1221 unsigned length, i, from = 0;
1223 BOOL eq;
1224 HRESULT hres;
1225
1226 TRACE("\n");
1227
1228 hres = get_length(ctx, vthis, &jsthis, &length);
1229 if(FAILED(hres))
1230 return hres;
1231 if(!length) {
1232 if(r) *r = jsval_number(-1);
1233 goto done;
1234 }
1235
1236 search = argc ? argv[0] : jsval_undefined();
1237
1238 if(argc > 1) {
1239 double from_arg;
1240
1241 hres = to_integer(ctx, argv[1], &from_arg);
1242 if(FAILED(hres))
1243 goto done;
1244
1245 if(from_arg >= 0)
1246 from = min(from_arg, length);
1247 else
1248 from = max(from_arg + length, 0);
1249 }
1250
1251 for(i = from; i < length; i++) {
1252 hres = jsdisp_get_idx(jsthis, i, &value);
1254 continue;
1255 if(FAILED(hres))
1256 goto done;
1257
1260 if(FAILED(hres))
1261 goto done;
1262 if(eq) {
1263 if(r) *r = jsval_number(i);
1264 goto done;
1265 }
1266 }
1267
1268 if(r) *r = jsval_number(-1);
1269 hres = S_OK;
1270done:
1271 jsdisp_release(jsthis);
1272 return hres;
1273}
1274
1276 jsval_t *r)
1277{
1279 unsigned i, length;
1280 jsdisp_t *jsthis;
1281 HRESULT hres;
1282 BOOL eq;
1283
1284 TRACE("\n");
1285
1286 hres = get_length(ctx, vthis, &jsthis, &length);
1287 if(FAILED(hres))
1288 return hres;
1289 if(!length)
1290 goto notfound;
1291
1292 search = argc ? argv[0] : jsval_undefined();
1293
1294 i = length - 1;
1295 if(argc > 1) {
1296 double from_arg;
1297
1298 hres = to_integer(ctx, argv[1], &from_arg);
1299 if(FAILED(hres))
1300 goto done;
1301
1302 if(from_arg >= 0.0)
1303 i = min(from_arg, i);
1304 else {
1305 from_arg += length;
1306 if(from_arg < 0.0)
1307 goto notfound;
1308 i = from_arg;
1309 }
1310 }
1311
1312 do {
1313 hres = jsdisp_get_idx(jsthis, i, &value);
1315 continue;
1316 if(FAILED(hres))
1317 goto done;
1318
1321 if(FAILED(hres))
1322 goto done;
1323 if(eq) {
1324 if(r) *r = jsval_number(i);
1325 goto done;
1326 }
1327 } while(i--);
1328
1329notfound:
1330 if(r) *r = jsval_number(-1);
1331 hres = S_OK;
1332done:
1333 jsdisp_release(jsthis);
1334 return hres;
1335}
1336
1338{
1339 jsval_t context_this = jsval_undefined();
1340 jsval_t callback_args[3], mapped_value;
1341 jsdisp_t *jsthis, *array;
1343 UINT32 length, k;
1344 HRESULT hres;
1345
1346 TRACE("\n");
1347
1348 hres = get_length(ctx, vthis, &jsthis, &length);
1349 if(FAILED(hres)) {
1350 FIXME("Could not get length\n");
1351 return hres;
1352 }
1353
1354 /* FIXME: check IsCallable */
1355 if(!argc || !is_object_instance(argv[0])) {
1356 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1358 goto done;
1359 }
1360 callback = get_object(argv[0]);
1361
1362 if(argc > 1)
1363 context_this = argv[1];
1364
1365 hres = create_array(ctx, 0, &array);
1366 if(FAILED(hres))
1367 goto done;
1368
1369 for(k = 0; k < length; k++) {
1370 hres = jsdisp_get_idx(jsthis, k, &callback_args[0]);
1371 if(hres == DISP_E_UNKNOWNNAME) {
1372 hres = S_OK;
1373 continue;
1374 }
1375 if(FAILED(hres))
1376 break;
1377
1378 callback_args[1] = jsval_number(k);
1379 callback_args[2] = jsval_obj(jsthis);
1380 hres = disp_call_value(ctx, callback, context_this, DISPATCH_METHOD, 3, callback_args, &mapped_value);
1381 jsval_release(callback_args[0]);
1382 if(FAILED(hres))
1383 break;
1384
1385 hres = jsdisp_propput_idx(array, k, mapped_value);
1386 if(FAILED(hres))
1387 break;
1388 }
1389
1390 if(SUCCEEDED(hres) && r)
1391 *r = jsval_obj(array);
1392 else
1394done:
1395 jsdisp_release(jsthis);
1396 return hres;
1397}
1398
1400{
1401 jsval_t callback_args[4], acc, new_acc;
1402 BOOL have_value = FALSE;
1404 jsdisp_t *jsthis;
1405 UINT32 length, k;
1406 HRESULT hres;
1407
1408 TRACE("\n");
1409
1410 hres = get_length(ctx, vthis, &jsthis, &length);
1411 if(FAILED(hres)) {
1412 FIXME("Could not get length\n");
1413 return hres;
1414 }
1415
1416 /* Fixme check IsCallable */
1417 if(!argc || !is_object_instance(argv[0])) {
1418 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1420 goto done;
1421 }
1422 callback = get_object(argv[0]);
1423
1424 if(argc > 1) {
1425 have_value = TRUE;
1426 hres = jsval_copy(argv[1], &acc);
1427 if(FAILED(hres))
1428 goto done;
1429 }
1430
1431 for(k = 0; k < length; k++) {
1432 hres = jsdisp_get_idx(jsthis, k, &callback_args[1]);
1433 if(hres == DISP_E_UNKNOWNNAME) {
1434 hres = S_OK;
1435 continue;
1436 }
1437 if(FAILED(hres))
1438 break;
1439
1440 if(!have_value) {
1441 have_value = TRUE;
1442 acc = callback_args[1];
1443 continue;
1444 }
1445
1446 callback_args[0] = acc;
1447 callback_args[2] = jsval_number(k);
1448 callback_args[3] = jsval_obj(jsthis);
1449 hres = disp_call_value(ctx, callback, jsval_undefined(), DISPATCH_METHOD, ARRAY_SIZE(callback_args), callback_args, &new_acc);
1450 jsval_release(callback_args[1]);
1451 if(FAILED(hres))
1452 break;
1453
1454 jsval_release(acc);
1455 acc = new_acc;
1456 }
1457
1458 if(SUCCEEDED(hres) && !have_value) {
1459 WARN("No array element\n");
1461 }
1462
1463 if(SUCCEEDED(hres) && r)
1464 *r = acc;
1465 else if(have_value)
1466 jsval_release(acc);
1467done:
1468 jsdisp_release(jsthis);
1469 return hres;
1470}
1471
1473 jsval_t *r)
1474{
1475 jsval_t context_this = jsval_undefined();
1476 jsval_t value, args[3], res;
1477 BOOL boolval, ret = FALSE;
1479 unsigned length, i;
1480 jsdisp_t *jsthis;
1481 HRESULT hres;
1482
1483 TRACE("\n");
1484
1485 hres = get_length(ctx, vthis, &jsthis, &length);
1486 if(FAILED(hres))
1487 return hres;
1488
1489 /* FIXME: check IsCallable */
1490 if(!argc || !is_object_instance(argv[0])) {
1491 FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
1493 goto done;
1494 }
1495 callback = get_object(argv[0]);
1496
1497 if(argc > 1)
1498 context_this = argv[1];
1499
1500 for(i = 0; i < length; i++) {
1501 hres = jsdisp_get_idx(jsthis, i, &value);
1502 if(FAILED(hres)) {
1504 continue;
1505 goto done;
1506 }
1507 args[0] = value;
1508 args[1] = jsval_number(i);
1509 args[2] = jsval_obj(jsthis);
1512 if(FAILED(hres))
1513 goto done;
1514
1515 hres = to_boolean(res, &boolval);
1517 if(FAILED(hres))
1518 goto done;
1519 if(boolval) {
1520 ret = TRUE;
1521 break;
1522 }
1523 }
1524
1525 if(r)
1526 *r = jsval_bool(ret);
1527 hres = S_OK;
1528done:
1529 jsdisp_release(jsthis);
1530 return hres;
1531}
1532
1533/* ECMA-262 3rd Edition 15.4.4.13 */
1535 jsval_t *r)
1536{
1537 jsdisp_t *jsthis;
1538 WCHAR buf[14], *buf_end, *str;
1539 UINT32 i, length;
1540 jsval_t val;
1541 DISPID id;
1542 HRESULT hres;
1543
1544 TRACE("\n");
1545
1546 hres = get_length(ctx, vthis, &jsthis, &length);
1547 if(FAILED(hres))
1548 return hres;
1549
1550 if(argc) {
1551 buf_end = buf + ARRAY_SIZE(buf)-1;
1552 *buf_end-- = 0;
1553 i = length;
1554
1555 while(i--) {
1556 str = idx_to_str(i, buf_end);
1557
1558 hres = jsdisp_get_id(jsthis, str, 0, &id);
1559 if(SUCCEEDED(hres)) {
1560 hres = jsdisp_propget(jsthis, id, &val);
1561 if(FAILED(hres))
1562 goto done;
1563
1564 hres = jsdisp_propput_idx(jsthis, i+argc, val);
1566 }else if(hres == DISP_E_UNKNOWNNAME) {
1567 hres = IDispatchEx_DeleteMemberByDispID(to_dispex(jsthis), id);
1568 }
1569 }
1570
1571 if(FAILED(hres))
1572 goto done;
1573 }
1574
1575 for(i=0; i<argc; i++) {
1576 hres = jsdisp_propput_idx(jsthis, i, argv[i]);
1577 if(FAILED(hres))
1578 goto done;
1579 }
1580
1581 if(argc) {
1582 length += argc;
1583 hres = set_length(jsthis, length);
1584 if(FAILED(hres))
1585 goto done;
1586 }
1587
1588 if(r)
1589 *r = ctx->version < 2 ? jsval_undefined() : jsval_number(length);
1590 hres = S_OK;
1591done:
1592 jsdisp_release(jsthis);
1593 return hres;
1594}
1595
1596static void Array_on_put(jsdisp_t *dispex, const WCHAR *name)
1597{
1599 const WCHAR *ptr = name;
1600 DWORD id = 0;
1601
1602 if(!is_digit(*ptr))
1603 return;
1604
1605 while(*ptr && is_digit(*ptr)) {
1606 id = id*10 + (*ptr-'0');
1607 ptr++;
1608 }
1609
1610 if(*ptr)
1611 return;
1612
1613 if(id >= array->length)
1614 array->length = id+1;
1615}
1616
1617static const builtin_prop_t Array_props[] = {
1618 {L"concat", Array_concat, PROPF_METHOD|1},
1619 {L"every", Array_every, PROPF_METHOD|PROPF_ES5|1},
1620 {L"filter", Array_filter, PROPF_METHOD|PROPF_ES5|1},
1621 {L"forEach", Array_forEach, PROPF_METHOD|PROPF_ES5|1},
1622 {L"indexOf", Array_indexOf, PROPF_METHOD|PROPF_ES5|1},
1623 {L"join", Array_join, PROPF_METHOD|1},
1624 {L"lastIndexOf", Array_lastIndexOf, PROPF_METHOD|PROPF_ES5|1},
1625 {L"length", NULL,0, Array_get_length, Array_set_length},
1626 {L"map", Array_map, PROPF_METHOD|PROPF_ES5|1},
1627 {L"pop", Array_pop, PROPF_METHOD},
1628 {L"push", Array_push, PROPF_METHOD|1},
1629 {L"reduce", Array_reduce, PROPF_METHOD|PROPF_ES5|1},
1630 {L"reverse", Array_reverse, PROPF_METHOD},
1631 {L"shift", Array_shift, PROPF_METHOD},
1632 {L"slice", Array_slice, PROPF_METHOD|2},
1633 {L"some", Array_some, PROPF_METHOD|PROPF_ES5|1},
1634 {L"sort", Array_sort, PROPF_METHOD|1},
1635 {L"splice", Array_splice, PROPF_METHOD|2},
1636 {L"toLocaleString", Array_toLocaleString, PROPF_METHOD},
1637 {L"toString", Array_toString, PROPF_METHOD},
1638 {L"unshift", Array_unshift, PROPF_METHOD|1},
1639};
1640
1643 .props_cnt = ARRAY_SIZE(Array_props),
1644 .props = Array_props,
1645 .on_put = Array_on_put,
1646};
1647
1650};
1651
1654 .props_cnt = ARRAY_SIZE(ArrayInst_props),
1655 .props = ArrayInst_props,
1656 .on_put = Array_on_put,
1657};
1658
1659/* ECMA-262 5.1 Edition 15.4.3.2 */
1661{
1662 jsdisp_t *obj;
1663
1664 TRACE("\n");
1665
1666 if(!argc || !is_object_instance(argv[0])) {
1667 if(r) *r = jsval_bool(FALSE);
1668 return S_OK;
1669 }
1670
1672 if(r) *r = jsval_bool(obj && is_class(obj, JSCLASS_ARRAY));
1673 return S_OK;
1674}
1675
1677 jsval_t *r)
1678{
1679 jsdisp_t *obj;
1680 DWORD i;
1681 HRESULT hres;
1682
1683 TRACE("\n");
1684
1685 switch(flags) {
1686 case DISPATCH_METHOD:
1687 case DISPATCH_CONSTRUCT: {
1688 if(argc == 1 && is_number(argv[0])) {
1689 double n = get_number(argv[0]);
1690
1691 if(n < 0 || !is_int32(n))
1692 return JS_E_INVALID_LENGTH;
1693 if(!r)
1694 return S_OK;
1695
1696 hres = create_array(ctx, n, &obj);
1697 if(FAILED(hres))
1698 return hres;
1699
1700 *r = jsval_obj(obj);
1701 return S_OK;
1702 }
1703
1704 if(!r)
1705 return S_OK;
1707 if(FAILED(hres))
1708 return hres;
1709
1710 for(i=0; i < argc; i++) {
1712 if(FAILED(hres))
1713 break;
1714 }
1715 if(FAILED(hres)) {
1717 return hres;
1718 }
1719
1720 *r = jsval_obj(obj);
1721 break;
1722 }
1723 default:
1724 FIXME("unimplemented flags: %x\n", flags);
1725 return E_NOTIMPL;
1726 }
1727
1728 return S_OK;
1729}
1730
1732{
1734 HRESULT hres;
1735
1736 array = calloc(1, sizeof(ArrayInstance));
1737 if(!array)
1738 return E_OUTOFMEMORY;
1739
1740 if(object_prototype)
1741 hres = init_dispex(&array->dispex, ctx, &Array_info, object_prototype);
1742 else
1743 hres = init_dispex_from_constr(&array->dispex, ctx, &ArrayInst_info, ctx->array_constr);
1744
1745 if(FAILED(hres)) {
1746 free(array);
1747 return hres;
1748 }
1749
1750 *ret = array;
1751 return S_OK;
1752}
1753
1756};
1757
1760 .call = Function_value,
1761 .props_cnt = ARRAY_SIZE(ArrayConstr_props),
1762 .props = ArrayConstr_props,
1763};
1764
1766{
1768 HRESULT hres;
1769
1770 hres = alloc_array(ctx, object_prototype, &array);
1771 if(FAILED(hres))
1772 return hres;
1773
1775
1776 jsdisp_release(&array->dispex);
1777 return hres;
1778}
1779
1781{
1783 HRESULT hres;
1784
1786 if(FAILED(hres))
1787 return hres;
1788
1789 array->length = length;
1790
1791 *ret = &array->dispex;
1792 return S_OK;
1793}
static const builtin_info_t ArrayConstr_info
Definition: array.c:1758
static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, unsigned seplen, HRESULT(*to_string)(script_ctx_t *, jsval_t, jsstr_t **), jsval_t *r)
Definition: array.c:235
static ArrayInstance * array_this(jsval_t vthis)
Definition: array.c:44
static HRESULT Array_shift(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:500
static HRESULT to_locale_string(script_ctx_t *ctx, jsval_t val, jsstr_t **str)
Definition: array.c:961
static HRESULT Array_sort(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:683
static HRESULT ArrayConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1676
static ArrayInstance * array_from_jsdisp(jsdisp_t *jsdisp)
Definition: array.c:39
static HRESULT Array_concat(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:191
static const builtin_info_t ArrayInst_info
Definition: array.c:1652
static HRESULT alloc_array(script_ctx_t *ctx, jsdisp_t *object_prototype, ArrayInstance **ret)
Definition: array.c:1731
static HRESULT Array_every(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1034
static HRESULT Array_push(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:410
static const builtin_info_t Array_info
Definition: array.c:1641
static HRESULT Array_lastIndexOf(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1275
static HRESULT Array_splice(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:835
static HRESULT Array_slice(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:559
HRESULT create_array(script_ctx_t *ctx, DWORD length, jsdisp_t **ret)
Definition: array.c:1780
static HRESULT Array_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:947
static HRESULT get_length(script_ctx_t *ctx, jsval_t vthis, jsdisp_t **jsthis, UINT32 *ret)
Definition: array.c:56
HRESULT create_array_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
Definition: array.c:1765
static void Array_on_put(jsdisp_t *dispex, const WCHAR *name)
Definition: array.c:1596
static HRESULT Array_toLocaleString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:999
static HRESULT Array_map(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1337
static HRESULT Array_indexOf(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1217
static const builtin_prop_t ArrayInst_props[]
Definition: array.c:1648
static HRESULT set_length(jsdisp_t *obj, DWORD length)
Definition: array.c:90
static const builtin_prop_t ArrayConstr_props[]
Definition: array.c:1754
static const builtin_prop_t Array_props[]
Definition: array.c:1617
static HRESULT concat_array(jsdisp_t *array, ArrayInstance *obj, DWORD *len)
Definition: array.c:150
static HRESULT Array_filter(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1095
WCHAR * idx_to_str(DWORD idx, WCHAR *ptr)
Definition: array.c:100
static HRESULT Array_join(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:325
static HRESULT Array_get_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: array.c:115
static HRESULT Array_reduce(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1399
static HRESULT Array_some(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1472
static HRESULT concat_obj(jsdisp_t *array, IDispatch *obj, DWORD *len)
Definition: array.c:173
static HRESULT Array_unshift(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1534
unsigned array_get_length(jsdisp_t *array)
Definition: array.c:50
static HRESULT Array_reverse(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:441
static HRESULT Array_set_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t value)
Definition: array.c:123
static HRESULT ArrayConstr_isArray(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1660
static HRESULT sort_cmp(script_ctx_t *ctx, jsdisp_t *cmp_func, jsval_t v1, jsval_t v2, INT *cmp)
Definition: array.c:631
static HRESULT Array_forEach(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:1166
static HRESULT Array_pop(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: array.c:358
#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
int(* cmp_func)(const void *ptr1, const void *ptr2)
Definition: btrfs.c:38
r l[0]
Definition: byte_order.h:168
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
HRESULT create_builtin_constructor(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:809
HRESULT Function_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:600
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1675
MonoAssembly int argc
Definition: metahost.c:107
#define assert(_expr)
Definition: assert.h:32
#define isnan(x)
Definition: math.h:360
_ACRTIMP double __cdecl floor(double)
Definition: floor.c:18
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
HRESULT jsval_strict_equal(jsval_t lval, jsval_t rval, BOOL *ret)
Definition: engine.c:684
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint start
Definition: gl.h:1545
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLdouble * v
Definition: gl.h:2040
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLuint GLuint end
Definition: gl.h:1545
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble n
Definition: glext.h:7729
GLuint res
Definition: glext.h:9613
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLint * range
Definition: glext.h:7539
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLfloat GLfloat v1
Definition: glext.h:6062
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
GLuint id
Definition: glext.h:5910
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
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 GLint GLint j
Definition: glfuncs.h:250
static HRESULT to_string(VARIANT *src, BSTR *dst)
Definition: host.c:46
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, jsval_t val)
Definition: dispex.c:2859
HRESULT jsdisp_get_id(jsdisp_t *jsdisp, const WCHAR *name, DWORD flags, DISPID *id)
Definition: dispex.c:2550
HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *constr)
Definition: dispex.c:2512
jsdisp_t * iface_to_jsdisp(IDispatch *iface)
Definition: dispex.c:2543
HRESULT disp_call_name(script_ctx_t *ctx, IDispatch *disp, const WCHAR *name, WORD flags, unsigned argc, jsval_t *argv, jsval_t *ret)
Definition: dispex.c:2740
ULONG jsdisp_release(jsdisp_t *obj)
Definition: dispex.c:1911
HRESULT jsdisp_delete_idx(jsdisp_t *obj, DWORD idx)
Definition: dispex.c:3019
jsdisp_t * as_jsdisp(IDispatch *disp)
Definition: dispex.c:2441
HRESULT jsdisp_call_value(jsdisp_t *jsfunc, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: dispex.c:2581
HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, jsval_t *r)
Definition: dispex.c:2963
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:2454
HRESULT jsdisp_propget_name(jsdisp_t *obj, const WCHAR *name, jsval_t *val)
Definition: dispex.c:2946
HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val)
Definition: dispex.c:2864
jsdisp_t * jsdisp_addref(jsdisp_t *obj)
Definition: dispex.c:1902
HRESULT jsdisp_call_name(jsdisp_t *disp, const WCHAR *name, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: dispex.c:2615
jsdisp_t * to_jsdisp(IDispatch *disp)
Definition: dispex.c:2447
HRESULT jsdisp_propget(jsdisp_t *jsdisp, DISPID id, jsval_t *val)
Definition: dispex.c:2983
HRESULT to_flat_string(script_ctx_t *, jsval_t, jsstr_t **, const WCHAR **)
Definition: jsutils.c:846
#define PROPF_ES5
Definition: jscript.h:90
#define JS_E_JSCRIPT_EXPECTED
Definition: jscript.h:561
HRESULT to_uint32(script_ctx_t *, jsval_t, UINT32 *)
Definition: jsutils.c:754
#define SCRIPTLANGUAGEVERSION_ES5
Definition: jscript.h:53
#define JS_E_FUNCTION_EXPECTED
Definition: jscript.h:552
static BOOL is_int32(double d)
Definition: jscript.h:508
HRESULT localize_number(script_ctx_t *, DOUBLE, BOOL, jsstr_t **)
Definition: number.c:350
static HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: jscript.h:518
HRESULT to_integer(script_ctx_t *, jsval_t, double *)
Definition: jsutils.c:676
#define JS_E_ARRAY_EXPECTED
Definition: jscript.h:572
const char * debugstr_jsval(const jsval_t)
Definition: jsutils.c:35
HRESULT to_object(script_ctx_t *, jsval_t, IDispatch **)
Definition: jsutils.c:864
HRESULT to_number(script_ctx_t *, jsval_t, double *)
Definition: jsutils.c:630
static IDispatchEx * to_dispex(jsdisp_t *jsdisp)
Definition: jscript.h:227
@ JSCLASS_FUNCTION
Definition: jscript.h:109
@ JSCLASS_ARRAY
Definition: jscript.h:104
#define JS_E_INVALID_PROPERTY
Definition: jscript.h:532
HRESULT to_boolean(jsval_t, BOOL *)
Definition: jsutils.c:489
#define JS_E_INVALID_ACTION
Definition: jscript.h:533
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Definition: jscript.h:503
#define JS_E_INVALID_LENGTH
Definition: jscript.h:571
const unsigned int PROPF_METHOD
Definition: jsdisp.idl:33
const unsigned int PROPF_CONSTR
Definition: jsdisp.idl:34
int jsstr_cmp(jsstr_t *str1, jsstr_t *str2)
Definition: jsstr.c:192
jsstr_t * jsstr_empty(void)
Definition: jsstr.c:291
const char * debugstr_jsstr(jsstr_t *str)
Definition: jsstr.c:37
jsstr_t * jsstr_alloc_buf(unsigned len, WCHAR **buf)
Definition: jsstr.c:69
#define JSSTR_MAX_LENGTH
Definition: jsstr.h:42
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:107
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:55
static unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
Definition: jsstr.h:145
HRESULT jsval_copy(jsval_t v, jsval_t *r)
Definition: jsutils.c:225
void jsval_release(jsval_t val)
Definition: jsutils.c:186
static BOOL is_number(jsval_t v)
Definition: jsval.h:200
@ JSV_NUMBER
Definition: jsval.h:49
@ JSV_OBJECT
Definition: jsval.h:47
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 jsval_type_t jsval_type(jsval_t v)
Definition: jsval.h:219
static BOOL is_null_disp(jsval_t v)
Definition: jsval.h:190
static BOOL is_undefined(jsval_t v)
Definition: jsval.h:180
static double get_number(jsval_t v)
Definition: jsval.h:233
static jsval_t jsval_disp(IDispatch *obj)
Definition: jsval.h:117
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:228
static BOOL is_object_instance(jsval_t v)
Definition: jsval.h:175
static BOOL is_null(jsval_t v)
Definition: jsval.h:185
static jsval_t jsval_number(double n)
Definition: jsval.h:153
#define d
Definition: ke_i.h:81
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
static IPrintDialogCallback callback
Definition: printdlg.c:326
HRESULT hres
Definition: protocol.c:465
#define eq(received, expected, label, type)
Definition: locale.c:179
#define cmp(status, error)
Definition: error.c:118
static VARIANTARG static DISPID
Definition: ordinal.c:49
#define min(a, b)
Definition: monoChain.cc:55
int k
Definition: mpi.c:3369
#define argv
Definition: mplay32.c:18
static short search(int val, const short *table, int size)
Definition: msg711.c:255
#define DISPATCH_METHOD
Definition: oleauto.h:1006
short WCHAR
Definition: pedump.c:58
#define calloc
Definition: rosglue.h:14
const WCHAR * str
#define TRACE(s)
Definition: solgame.cpp:4
CardRegion * from
Definition: spigame.cpp:19
jsdisp_t dispex
Definition: array.c:34
DWORD length
Definition: array.c:36
Definition: jsstr.h:36
Definition: jsval.h:54
Definition: match.c:390
Definition: undname.c:54
jsclass_t class
Definition: jscript.h:183
Definition: name.c:39
#define max(a, b)
Definition: svc.c:63
int32_t INT
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t UINT32
Definition: typedefs.h:59
double DOUBLE
Definition: typedefs.h:70
Definition: pdh_main.c:96
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:3618
#define LOCALE_SLIST
Definition: winnls.h:50