1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.htmlunit.junit.annotation.HtmlUnitNYI;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23
24
25
26
27
28
29
30
31
32
33 @RunWith(BrowserRunner.class)
34 public class NativeArrayTest extends WebDriverTestCase {
35
36
37
38
39
40 @Test
41 @Alerts(DEFAULT = {"1<>5", "5<>2", "1<>2", "5<>1", "2<>1", "1<>1", "5<>9"},
42 CHROME = {"5<>1", "2<>5", "2<>5", "2<>1", "1<>2", "1<>1", "9<>2", "9<>5"},
43 EDGE = {"5<>1", "2<>5", "2<>5", "2<>1", "1<>2", "1<>1", "9<>2", "9<>5"})
44 @HtmlUnitNYI(FF = {"5<>1", "2<>5", "2<>5", "2<>1", "1<>2", "1<>1", "9<>2", "9<>5"},
45 FF_ESR = {"5<>1", "2<>5", "2<>5", "2<>1", "1<>2", "1<>1", "9<>2", "9<>5"})
46 public void sortSteps() throws Exception {
47 final String html = DOCTYPE_HTML
48 + "<html><head><script>\n"
49 + LOG_TITLE_FUNCTION
50 + "function compare(x, y) {\n"
51 + " log('' + x + '<>' + y);\n"
52 + " return x - y;\n"
53 + "}\n"
54 + "function doTest() {\n"
55 + " var t = [1, 5, 2, 1, 9];\n"
56 + " t.sort(compare);\n"
57 + "}\n"
58 + "</script></head><body onload='doTest()'>\n"
59 + "</body></html>";
60
61 loadPageVerifyTitle2(html);
62 }
63
64
65
66
67
68 @Test
69 @Alerts("1,1,2,5,9")
70 public void sortIntComperator() throws Exception {
71 final String html = DOCTYPE_HTML
72 + "<html><head><script>\n"
73 + LOG_TITLE_FUNCTION
74 + "function compare(x, y) {\n"
75 + " return x - y;\n"
76 + "}\n"
77 + "function doTest() {\n"
78 + " var t = [1, 5, 2, 1, 9];\n"
79 + " t.sort(compare);\n"
80 + " log(t);\n"
81 + "}\n"
82 + "</script></head><body onload='doTest()'>\n"
83 + "</body></html>";
84
85 loadPageVerifyTitle2(html);
86 }
87
88
89
90
91
92 @Test
93 @Alerts("1,1,2,5,9")
94 public void sortSmallDoublesComperator() throws Exception {
95 final String html = DOCTYPE_HTML
96 + "<html><head><script>\n"
97 + LOG_TITLE_FUNCTION
98 + "function compare(x, y) {\n"
99 + " return (x - y) / 1001;\n"
100 + "}\n"
101 + "function doTest() {\n"
102 + " var t = [1, 5, 2, 1, 9];\n"
103 + " t.sort(compare);\n"
104 + " log(t);\n"
105 + "}\n"
106 + "</script></head><body onload='doTest()'>\n"
107 + "</body></html>";
108
109 loadPageVerifyTitle2(html);
110 }
111
112
113
114
115
116 @Test
117 @Alerts(DEFAULT = "1,5,2,1,9",
118 FF = "1,1,2,5,9",
119 FF_ESR = "1,1,2,5,9")
120 public void sortBoolComperator() throws Exception {
121 final String html = DOCTYPE_HTML
122 + "<html><head><script>\n"
123 + LOG_TITLE_FUNCTION
124 + "function compare(x, y) {\n"
125 + " return x >= y;\n"
126 + "}\n"
127 + "function doTest() {\n"
128 + " var t = ['1', '5', '2', '1', '9'];\n"
129 + " t.sort(compare);\n"
130 + " log(t);\n"
131 + "}\n"
132 + "</script></head><body onload='doTest()'>\n"
133 + "</body></html>";
134
135 loadPageVerifyTitle2(html);
136 }
137
138
139
140
141
142 @Test
143 @Alerts("1,1,2,5,9")
144 public void sortBool2IntComperator() throws Exception {
145 final String html = DOCTYPE_HTML
146 + "<html><head><script>\n"
147 + LOG_TITLE_FUNCTION
148 + "function compare(x, y) {\n"
149 + " return (x >= y) === true ? 1 : -1;\n"
150 + "}\n"
151 + "function doTest() {\n"
152 + " var t = ['1', '5', '2', '1', '9'];\n"
153 + " t.sort(compare);\n"
154 + " log(t);\n"
155 + "}\n"
156 + "</script></head><body onload='doTest()'>\n"
157 + "</body></html>";
158
159 loadPageVerifyTitle2(html);
160 }
161
162
163
164
165
166 @Test
167 @Alerts(DEFAULT = "1,5,2,1,9",
168 FF = "9,1,2,5,1",
169 FF_ESR = "9,1,2,5,1")
170 @HtmlUnitNYI(FF = "1,5,2,1,9",
171 FF_ESR = "1,5,2,1,9")
172 public void sortInvalidComperator() throws Exception {
173 final String html = DOCTYPE_HTML
174 + "<html><head><script>\n"
175 + LOG_TITLE_FUNCTION
176 + "function compare(x, y) {\n"
177 + " return 1;\n"
178 + "}\n"
179 + "function doTest() {\n"
180 + " var t = ['1', '5', '2', '1', '9'];\n"
181 + " t.sort(compare);\n"
182 + " log(t);\n"
183 + "}\n"
184 + "</script></head><body onload='doTest()'>\n"
185 + "</body></html>";
186
187 loadPageVerifyTitle2(html);
188 }
189
190
191
192
193
194 @Test
195 @Alerts({"concat: function", "constructor: function", "isArray: undefined", "join: function", "pop: function",
196 "push: function", "reverse: function", "shift: function", "slice: function", "sort: function",
197 "splice: function", "toLocaleString: function", "toString: function", "unshift: function"})
198 public void methods_common() throws Exception {
199 final String[] methods = {"concat", "constructor", "isArray", "join", "pop", "push", "reverse", "shift",
200 "slice", "sort", "splice", "toLocaleString", "toString", "unshift"};
201 final String html = NativeDateTest.createHTMLTestMethods("[]", methods);
202 loadPageVerifyTitle2(html);
203 }
204
205
206
207
208
209 @Test
210 @Alerts({"every: function", "filter: function", "forEach: function", "indexOf: function",
211 "lastIndexOf: function", "map: function", "reduce: function", "reduceRight: function", "some: function"})
212 public void methods_different() throws Exception {
213 final String[] methods = {"every", "filter", "forEach", "indexOf", "lastIndexOf", "map", "reduce",
214 "reduceRight", "some"};
215 final String html = NativeDateTest.createHTMLTestMethods("[]", methods);
216 loadPageVerifyTitle2(html);
217 }
218
219
220
221
222 @Test
223 @Alerts("toSource: undefined")
224 public void methods_toSource() throws Exception {
225 final String[] methods = {"toSource"};
226 final String html = NativeDateTest.createHTMLTestMethods("[]", methods);
227 loadPageVerifyTitle2(html);
228 }
229
230
231
232
233
234
235
236 @Test
237 @Alerts({"hello", "foo", "hello"})
238 public void deleteShouldNotWalkPrototypeChain() throws Exception {
239 final String html = DOCTYPE_HTML
240 + "<html><body><script>\n"
241 + LOG_TITLE_FUNCTION
242 + "Array.prototype.foo = function() { log('hello')};\n"
243 + "[].foo();\n"
244 + "var x = [];\n"
245 + "for (var i in x) {\n"
246 + " log(i);\n"
247 + " delete x[i];\n"
248 + "}\n"
249 + "[].foo();\n"
250 + "</script></body>";
251
252 loadPageVerifyTitle2(html);
253 }
254
255
256
257
258 @Test
259 @Alerts("function Array() { [native code] }")
260 public void constructorToString() throws Exception {
261 final String html = DOCTYPE_HTML
262 + "<html><head><script>\n"
263 + LOG_TITLE_FUNCTION
264 + "log([].constructor.toString());\n"
265 + "</script></head><body>\n"
266 + "</body></html>";
267
268 loadPageVerifyTitle2(html);
269 }
270
271
272
273
274 @Test
275 @Alerts({"mandarin", "", "mandarin"})
276 public void shiftOneElement() throws Exception {
277 final String html = DOCTYPE_HTML
278 + "<html>\n"
279 + "<head>\n"
280 + "<script>\n"
281 + LOG_TITLE_FUNCTION
282 + " var myFish = [ 'mandarin' ];\n"
283 + " log(myFish);\n"
284
285 + " var shifted = myFish.shift();\n"
286 + " log(myFish);\n"
287 + " log(shifted);\n"
288 + "</script>\n"
289 + "</head>\n"
290 + "<body>\n"
291 + "</body></html>";
292
293 loadPageVerifyTitle2(html);
294 }
295
296
297
298
299 @Test
300 @Alerts({"", "", "undefined"})
301 public void shiftEmpty() throws Exception {
302 final String html = DOCTYPE_HTML
303 + "<html>\n"
304 + "<head>\n"
305 + "<script>\n"
306 + LOG_TITLE_FUNCTION
307 + " var myFish = [ ];\n"
308 + " log(myFish);\n"
309
310 + " var shifted = myFish.shift();\n"
311 + " log(myFish);\n"
312 + " log(shifted);\n"
313 + "</script>\n"
314 + "</head>\n"
315 + "<body>\n"
316 + "</body></html>";
317
318 loadPageVerifyTitle2(html);
319 }
320
321
322
323
324 @Test
325 @Alerts({"3", "a", "b", "c"})
326 public void fromString() throws Exception {
327 final String html = DOCTYPE_HTML
328 + "<html>\n"
329 + "<head>\n"
330 + "<script>\n"
331 + LOG_TITLE_FUNCTION
332 + " if (Array.from) {\n"
333 + " var arr = Array.from('abc');\n"
334 + " log(arr.length);\n"
335 + " for (var i = 0; i < arr.length; i++) {\n"
336 + " log(arr[i]);\n"
337 + " }\n"
338 + " } else {\n"
339 + " log('not supported');\n"
340 + " }\n"
341 + "</script>\n"
342 + "</head>\n"
343 + "<body>\n"
344 + "</body></html>";
345
346 loadPageVerifyTitle2(html);
347 }
348
349
350
351
352 @Test
353 @Alerts({"3", "a", "b", "c"})
354 public void fromArray() throws Exception {
355 final String html = DOCTYPE_HTML
356 + "<html>\n"
357 + "<head>\n"
358 + "<script>\n"
359 + LOG_TITLE_FUNCTION
360 + " if (Array.from) {\n"
361 + " var arr = Array.from(['a', 'b', 'c']);\n"
362 + " log(arr.length);\n"
363 + " for (var i = 0; i < arr.length; i++) {\n"
364 + " log(arr[i]);\n"
365 + " }\n"
366 + " } else {\n"
367 + " log('not supported');\n"
368 + " }\n"
369 + "</script>\n"
370 + "</head>\n"
371 + "<body>\n"
372 + "</body></html>";
373
374 loadPageVerifyTitle2(html);
375 }
376
377
378
379
380 @Test
381 @Alerts({"3", "a", "b", "c"})
382 public void fromArrayIterator() throws Exception {
383 final String html = DOCTYPE_HTML
384 + "<html>\n"
385 + "<head>\n"
386 + "<script>\n"
387 + LOG_TITLE_FUNCTION
388 + " if (Array.from) {\n"
389 + " var input = ['a', 'b', 'c'];\n"
390 + " var arr = Array.from(input[Symbol.iterator]());\n"
391 + " log(arr.length);\n"
392 + " for (var i = 0; i < arr.length; i++) {\n"
393 + " log(arr[i]);\n"
394 + " }\n"
395 + " } else {\n"
396 + " log('not supported');\n"
397 + " }\n"
398 + "</script>\n"
399 + "</head>\n"
400 + "<body>\n"
401 + "</body></html>";
402
403 loadPageVerifyTitle2(html);
404 }
405
406
407
408
409 @Test
410 @Alerts({"4", "T", "e", "s", "t"})
411 public void fromStringIterator() throws Exception {
412 final String html = DOCTYPE_HTML
413 + "<html>\n"
414 + "<head>\n"
415 + "<script>\n"
416 + LOG_TITLE_FUNCTION
417 + " if (Array.from) {\n"
418 + " var arr = Array.from('Test'[Symbol.iterator]());\n"
419 + " log(arr.length);\n"
420 + " for (var i = 0; i < arr.length; i++) {\n"
421 + " log(arr[i]);\n"
422 + " }\n"
423 + " } else {\n"
424 + " log('not supported');\n"
425 + " }\n"
426 + "</script>\n"
427 + "</head>\n"
428 + "<body>\n"
429 + "</body></html>";
430
431 loadPageVerifyTitle2(html);
432 }
433
434
435
436
437 @Test
438 @Alerts({"2", "abc", "[object Window]"})
439 public void fromSet() throws Exception {
440 final String html = DOCTYPE_HTML
441 + "<html>\n"
442 + "<head>\n"
443 + "<script>\n"
444 + LOG_TITLE_FUNCTION
445 + " if (Array.from) {\n"
446 + " var s = new Set(['abc', window]);\n"
447 + " var arr = Array.from(s);\n"
448 + " log(arr.length);\n"
449 + " for (var i = 0; i < arr.length; i++) {\n"
450 + " log(arr[i]);\n"
451 + " }\n"
452 + " } else {\n"
453 + " log('not supported');\n"
454 + " }\n"
455 + "</script>\n"
456 + "</head>\n"
457 + "<body>\n"
458 + "</body></html>";
459
460 loadPageVerifyTitle2(html);
461 }
462
463
464
465
466 @Test
467 @Alerts({"3", "1,2", "3,4", "5,6"})
468 public void fromMap() throws Exception {
469 final String html = DOCTYPE_HTML
470 + "<html>\n"
471 + "<head>\n"
472 + "<script>\n"
473 + LOG_TITLE_FUNCTION
474 + " if (Array.from) {\n"
475 + " var m = new Map([[1, 2], [3, 4], [5, 6]]);\n"
476 + " var arr = Array.from(m);\n"
477 + " log(arr.length);\n"
478 + " for (var i = 0; i < arr.length; i++) {\n"
479 + " log(arr[i]);\n"
480 + " }\n"
481 + " } else {\n"
482 + " log('not supported');\n"
483 + " }\n"
484 + "</script>\n"
485 + "</head>\n"
486 + "<body>\n"
487 + "</body></html>";
488
489 loadPageVerifyTitle2(html);
490 }
491
492
493
494
495 @Test
496 @Alerts({"1", "by"})
497 public void fromUserDefinedIterable() throws Exception {
498 final String html = DOCTYPE_HTML
499 + "<html>\n"
500 + "<head>\n"
501 + "<script>\n"
502 + LOG_TITLE_FUNCTION
503 + " if (Array.from) {\n"
504 + " var myIterable = {};\n"
505 + " myIterable[Symbol.iterator] = function() {\n"
506 + " return {\n"
507 + " next: function(){\n"
508 + " if (this._first) {;\n"
509 + " this._first = false;\n"
510 + " return { value: 'by', done: false };\n"
511 + " }\n"
512 + " return { done: true };\n"
513 + " },\n"
514 + " _first: true\n"
515 + " };\n"
516 + " };\n"
517
518 + " var arr = Array.from(myIterable);\n"
519 + " log(arr.length);\n"
520 + " for (var i = 0; i < arr.length; i++) {\n"
521 + " log(arr[i]);\n"
522 + " }\n"
523 + " } else {\n"
524 + " log('not supported');\n"
525 + " }\n"
526 + "</script>\n"
527 + "</head>\n"
528 + "<body>\n"
529 + "</body></html>";
530
531 loadPageVerifyTitle2(html);
532 }
533
534
535
536
537 @Test
538 @Alerts("TypeError")
539 public void fromObject() throws Exception {
540 final String html = DOCTYPE_HTML
541 + "<html>\n"
542 + "<head>\n"
543 + "<script>\n"
544 + LOG_TITLE_FUNCTION
545 + " if (Array.from) {\n"
546 + " var myIterable = {};\n"
547 + " myIterable[Symbol.iterator] = function() {\n"
548 + " return { done: true };\n"
549 + " };\n"
550
551 + " try {\n"
552 + " Array.from(myIterable);\n"
553 + " } catch(e) { log('TypeError'); }\n"
554 + " } else {\n"
555 + " log('not supported');\n"
556 + " }\n"
557 + "</script>\n"
558 + "</head>\n"
559 + "<body>\n"
560 + "</body></html>";
561
562 loadPageVerifyTitle2(html);
563 }
564
565
566
567
568 @Test
569 @Alerts("0")
570 public void fromNativeObject() throws Exception {
571 final String html = DOCTYPE_HTML
572 + "<html>\n"
573 + "<head>\n"
574 + "<script>\n"
575 + LOG_TITLE_FUNCTION
576 + " if (Array.from) {\n"
577 + " var arr = Array.from({firstName: 'Erika', age: 42});\n"
578 + " log(arr.length);\n"
579 + " for (var i = 0; i < arr.length; i++) {\n"
580 + " log(arr[i]);\n"
581 + " }\n"
582 + " } else {\n"
583 + " log('not supported');\n"
584 + " }\n"
585 + "</script>\n"
586 + "</head>\n"
587 + "<body>\n"
588 + "</body></html>";
589
590 loadPageVerifyTitle2(html);
591 }
592
593
594
595
596 @Test
597 @Alerts({"1", "abc"})
598 public void fromArguments() throws Exception {
599 final String html = DOCTYPE_HTML
600 + "<html>\n"
601 + "<head>\n"
602 + "<script>\n"
603 + LOG_TITLE_FUNCTION
604 + " function test(a) { return Array.from(arguments); }\n"
605
606 + " if (Array.from) {\n"
607 + " var arr = test('abc') \n"
608 + " log(arr.length);\n"
609 + " for (var i = 0; i < arr.length; i++) {\n"
610 + " log(arr[i]);\n"
611 + " }\n"
612 + " } else {\n"
613 + " log('not supported');\n"
614 + " }\n"
615 + "</script>\n"
616 + "</head>\n"
617 + "<body>\n"
618 + "</body></html>";
619
620 loadPageVerifyTitle2(html);
621 }
622
623
624
625
626 @Test
627 @Alerts({"true", "true", "true", "true", "false", "false", "false",
628 "false", "false", "false", "false", "false", "false"})
629 public void isArray() throws Exception {
630 final String html = DOCTYPE_HTML
631 + "<html>\n"
632 + "<head>\n"
633 + "<script>\n"
634 + LOG_TITLE_FUNCTION
635 + " log(Array.isArray([]));\n"
636 + " log(Array.isArray([1]));\n"
637 + " log(Array.isArray( new Array() ));\n"
638 + " log(Array.isArray( Array.prototype ));\n"
639 + " log(Array.isArray());\n"
640 + " log(Array.isArray({}));\n"
641 + " log(Array.isArray(null));\n"
642 + " log(Array.isArray(undefined));\n"
643 + " log(Array.isArray(17));\n"
644 + " log(Array.isArray('Array'));\n"
645 + " log(Array.isArray(true));\n"
646 + " log(Array.isArray(false));\n"
647 + " log(Array.isArray({ __proto__ : Array.prototype }));\n"
648 + "</script>\n"
649 + "</head>\n"
650 + "<body>\n"
651 + "</body></html>";
652
653 loadPageVerifyTitle2(html);
654 }
655
656
657
658
659 @Test
660 @Alerts({"function", "20"})
661 public void find() throws Exception {
662 final String html = DOCTYPE_HTML
663 + "<html>\n"
664 + "<head>\n"
665 + "<script>\n"
666 + LOG_TITLE_FUNCTION
667 + " function isBig(n) { return n >= 10; }\n"
668 + "\n"
669 + " var arr = [1, 20, 7, 17];\n"
670 + " log(typeof arr.find);\n"
671 + " if (typeof arr.find == 'function') {\n"
672 + " log(arr.find(isBig));\n"
673 + " }\n"
674 + "</script>\n"
675 + "</head>\n"
676 + "<body>\n"
677 + "</body></html>";
678
679 loadPageVerifyTitle2(html);
680 }
681
682
683
684
685 @Test
686 @Alerts({"function", "20"})
687 public void findPrototype() throws Exception {
688 final String html = DOCTYPE_HTML
689 + "<html>\n"
690 + "<head>\n"
691 + "<script>\n"
692 + LOG_TITLE_FUNCTION
693 + " function isBig(n) { return n >= 10; }\n"
694 + "\n"
695 + " var arr = [1, 20, 7, 17];\n"
696 + " var find = Array.prototype.find;\n"
697 + " log(typeof find);\n"
698 + " if (typeof find == 'function') {\n"
699 + " log(find.call(arr, isBig));\n"
700 + " }\n"
701 + "</script>\n"
702 + "</head>\n"
703 + "<body>\n"
704 + "</body></html>";
705
706 loadPageVerifyTitle2(html);
707 }
708
709
710
711
712 @Test
713 @Alerts({"undefined", "TypeError"})
714 public void findStatic() throws Exception {
715 final String html = DOCTYPE_HTML
716 + "<html>\n"
717 + "<head>\n"
718 + "<script>\n"
719 + LOG_TITLE_FUNCTION
720 + " function isBig(n) { return n >= 10; }\n"
721 + "\n"
722 + " log(typeof Array.find);\n"
723 + " var arr = [1, 20, 7, 17];\n"
724 + " try {\n"
725 + " log(Array.find(arr, isBig));\n"
726 + " } catch(e) { log('TypeError'); }\n"
727 + "</script>\n"
728 + "</head>\n"
729 + "<body>\n"
730 + "</body></html>";
731
732 loadPageVerifyTitle2(html);
733 }
734
735
736
737
738 @Test
739 @Alerts({"function", "1"})
740 public void findIndex() throws Exception {
741 final String html = DOCTYPE_HTML
742 + "<html>\n"
743 + "<head>\n"
744 + "<script>\n"
745 + LOG_TITLE_FUNCTION
746 + " function isBig(n) { return n >= 10; }\n"
747 + "\n"
748 + " var arr = [1, 20, 7, 17];\n"
749 + " log(typeof arr.findIndex);\n"
750 + " if (typeof arr.findIndex == 'function') {\n"
751 + " log(arr.findIndex(isBig));\n"
752 + " }\n"
753 + "</script>\n"
754 + "</head>\n"
755 + "<body>\n"
756 + "</body></html>";
757
758 loadPageVerifyTitle2(html);
759 }
760
761
762
763
764 @Test
765 @Alerts({"function", "1"})
766 public void findIndexPrototype() throws Exception {
767 final String html = DOCTYPE_HTML
768 + "<html>\n"
769 + "<head>\n"
770 + "<script>\n"
771 + LOG_TITLE_FUNCTION
772 + " function isBig(n) { return n >= 10; }\n"
773 + "\n"
774 + " var arr = [1, 20, 7, 17];\n"
775 + " var findIndex = Array.prototype.findIndex;\n"
776 + " log(typeof findIndex);\n"
777 + " if (typeof findIndex == 'function') {\n"
778 + " log(findIndex.call(arr, isBig));\n"
779 + " }\n"
780 + "</script>\n"
781 + "</head>\n"
782 + "<body>\n"
783 + "</body></html>";
784
785 loadPageVerifyTitle2(html);
786 }
787
788
789
790
791 @Test
792 @Alerts({"undefined", "TypeError"})
793 public void findIndexStatic() throws Exception {
794 final String html = DOCTYPE_HTML
795 + "<html>\n"
796 + "<head>\n"
797 + "<script>\n"
798 + LOG_TITLE_FUNCTION
799 + " function isBig(n) { return n >= 10; }\n"
800 + "\n"
801 + " log(typeof Array.findIndex);\n"
802 + " var arr = [1, 20, 7, 17];\n"
803 + " try {\n"
804 + " log(Array.findIndex(arr, isBig));\n"
805 + " } catch(e) { log('TypeError'); }\n"
806 + "</script>\n"
807 + "</head>\n"
808 + "<body>\n"
809 + "</body></html>";
810
811 loadPageVerifyTitle2(html);
812 }
813
814
815
816
817 @Test
818 @Alerts({"function", "20,17"})
819 public void filter() throws Exception {
820 final String html = DOCTYPE_HTML
821 + "<html>\n"
822 + "<head>\n"
823 + "<script>\n"
824 + LOG_TITLE_FUNCTION
825 + " function isBig(n) { return n >= 10; }\n"
826 + "\n"
827 + " var arr = [1, 20, 7, 17];\n"
828 + " log(typeof arr.filter);\n"
829 + " log(arr.filter(isBig));\n"
830 + "</script>\n"
831 + "</head>\n"
832 + "<body>\n"
833 + "</body></html>";
834
835 loadPageVerifyTitle2(html);
836 }
837
838
839
840
841 @Test
842 @Alerts({"function", "20,17"})
843 public void filterPrototype() throws Exception {
844 final String html = DOCTYPE_HTML
845 + "<html>\n"
846 + "<head>\n"
847 + "<script>\n"
848 + LOG_TITLE_FUNCTION
849 + " function isBig(n) { return n >= 10; }\n"
850 + "\n"
851 + " var arr = [1, 20, 7, 17];\n"
852 + " var filter = Array.prototype.filter;\n"
853 + " log(typeof filter);\n"
854 + " log(filter.call(arr, isBig));\n"
855 + "</script>\n"
856 + "</head>\n"
857 + "<body>\n"
858 + "</body></html>";
859
860 loadPageVerifyTitle2(html);
861 }
862
863
864
865
866 @Test
867 @Alerts({"undefined", "TypeError"})
868 public void filterStatic() throws Exception {
869 final String html = DOCTYPE_HTML
870 + "<html>\n"
871 + "<head>\n"
872 + "<script>\n"
873 + LOG_TITLE_FUNCTION
874 + " function isBig(n) { return n >= 10; }\n"
875 + "\n"
876 + " log(typeof Array.filter);\n"
877 + " var arr = [1, 20, 7, 17];\n"
878 + " try {\n"
879 + " log(Array.filter(arr, isBig));\n"
880 + " } catch(e) { log('TypeError'); }\n"
881 + "</script>\n"
882 + "</head>\n"
883 + "<body>\n"
884 + "</body></html>";
885
886 loadPageVerifyTitle2(html);
887 }
888
889
890
891
892 @Test
893 @Alerts({"function", "1,2,3,4"})
894 public void map() throws Exception {
895 final String html = DOCTYPE_HTML
896 + "<html>\n"
897 + "<head>\n"
898 + "<script>\n"
899 + LOG_TITLE_FUNCTION
900 + " var arr = [1, 4, 9, 16];\n"
901 + " log(typeof arr.map);\n"
902 + " log(arr.map(Math.sqrt));\n"
903 + "</script>\n"
904 + "</head>\n"
905 + "<body>\n"
906 + "</body></html>";
907
908 loadPageVerifyTitle2(html);
909 }
910
911
912
913
914 @Test
915 @Alerts({"function", "1,2,3,4"})
916 public void mapPrototype() throws Exception {
917 final String html = DOCTYPE_HTML
918 + "<html>\n"
919 + "<head>\n"
920 + "<script>\n"
921 + LOG_TITLE_FUNCTION
922 + " var arr = [1, 4, 9, 16];\n"
923 + " var map = Array.prototype.map;\n"
924 + " log(typeof map);\n"
925 + " log(map.call(arr, Math.sqrt));\n"
926 + "</script>\n"
927 + "</head>\n"
928 + "<body>\n"
929 + "</body></html>";
930
931 loadPageVerifyTitle2(html);
932 }
933
934
935
936
937 @Test
938 @Alerts({"undefined", "TypeError"})
939 public void mapStatic() throws Exception {
940 final String html = DOCTYPE_HTML
941 + "<html>\n"
942 + "<head>\n"
943 + "<script>\n"
944 + LOG_TITLE_FUNCTION
945 + " log(typeof Array.map);\n"
946 + " var arr = [1, 4, 9, 16];\n"
947 + " try {\n"
948 + " log(Array.map(arr, Math.sqrt));\n"
949 + " } catch(e) { log('TypeError'); }\n"
950 + "</script>\n"
951 + "</head>\n"
952 + "<body>\n"
953 + "</body></html>";
954
955 loadPageVerifyTitle2(html);
956 }
957
958
959
960
961 @Test
962 @Alerts({"function", "false"})
963 public void every() throws Exception {
964 final String html = DOCTYPE_HTML
965 + "<html>\n"
966 + "<head>\n"
967 + "<script>\n"
968 + LOG_TITLE_FUNCTION
969 + " function isSmall(n) { return n < 10; }\n"
970 + "\n"
971 + " var arr = [1, 4, 9, 16];\n"
972 + " log(typeof arr.every);\n"
973 + " log(arr.every(isSmall));\n"
974 + "</script>\n"
975 + "</head>\n"
976 + "<body>\n"
977 + "</body></html>";
978
979 loadPageVerifyTitle2(html);
980 }
981
982
983
984
985 @Test
986 @Alerts({"function", "false"})
987 public void everyPrototype() throws Exception {
988 final String html = DOCTYPE_HTML
989 + "<html>\n"
990 + "<head>\n"
991 + "<script>\n"
992 + LOG_TITLE_FUNCTION
993 + " function isSmall(n) { return n < 10; }\n"
994 + "\n"
995 + " var arr = [1, 4, 9, 16];\n"
996 + " var every = Array.prototype.every;\n"
997 + " log(typeof every);\n"
998 + " log(every.call(arr, isSmall));\n"
999 + "</script>\n"
1000 + "</head>\n"
1001 + "<body>\n"
1002 + "</body></html>";
1003
1004 loadPageVerifyTitle2(html);
1005 }
1006
1007
1008
1009
1010 @Test
1011 @Alerts({"undefined", "TypeError"})
1012 public void everyStatic() throws Exception {
1013 final String html = DOCTYPE_HTML
1014 + "<html>\n"
1015 + "<head>\n"
1016 + "<script>\n"
1017 + LOG_TITLE_FUNCTION
1018 + " function isSmall(n) { return n < 10; }\n"
1019 + "\n"
1020 + " log(typeof Array.every);\n"
1021 + " var arr = [1, 4, 9, 16];\n"
1022 + " try {\n"
1023 + " log(Array.every(arr, isSmall));\n"
1024 + " } catch(e) { log('TypeError'); }\n"
1025 + "</script>\n"
1026 + "</head>\n"
1027 + "<body>\n"
1028 + "</body></html>";
1029
1030 loadPageVerifyTitle2(html);
1031 }
1032
1033
1034
1035
1036 @Test
1037 @Alerts({"function", "true"})
1038 public void some() throws Exception {
1039 final String html = DOCTYPE_HTML
1040 + "<html>\n"
1041 + "<head>\n"
1042 + "<script>\n"
1043 + LOG_TITLE_FUNCTION
1044 + " function isSmall(n) { return n < 10; }\n"
1045 + "\n"
1046 + " var arr = [1, 4, 9, 16];\n"
1047 + " log(typeof arr.some);\n"
1048 + " log(arr.some(isSmall));\n"
1049 + "</script>\n"
1050 + "</head>\n"
1051 + "<body>\n"
1052 + "</body></html>";
1053
1054 loadPageVerifyTitle2(html);
1055 }
1056
1057
1058
1059
1060 @Test
1061 @Alerts({"function", "true"})
1062 public void somePrototype() throws Exception {
1063 final String html = DOCTYPE_HTML
1064 + "<html>\n"
1065 + "<head>\n"
1066 + "<script>\n"
1067 + LOG_TITLE_FUNCTION
1068 + " function isSmall(n) { return n < 10; }\n"
1069 + "\n"
1070 + " var arr = [1, 4, 9, 16];\n"
1071 + " var some = Array.prototype.some;\n"
1072 + " log(typeof some);\n"
1073 + " log(some.call(arr, isSmall));\n"
1074 + "</script>\n"
1075 + "</head>\n"
1076 + "<body>\n"
1077 + "</body></html>";
1078
1079 loadPageVerifyTitle2(html);
1080 }
1081
1082
1083
1084
1085 @Test
1086 @Alerts({"undefined", "TypeError"})
1087 public void someStatic() throws Exception {
1088 final String html = DOCTYPE_HTML
1089 + "<html>\n"
1090 + "<head>\n"
1091 + "<script>\n"
1092 + LOG_TITLE_FUNCTION
1093 + " function isSmall(n) { return n < 10; }\n"
1094 + "\n"
1095 + " log(typeof Array.some);\n"
1096 + " var arr = [1, 4, 9, 16];\n"
1097 + " try {\n"
1098 + " log(Array.some(arr, isSmall));\n"
1099 + " } catch(e) { log('TypeError'); }\n"
1100 + "</script>\n"
1101 + "</head>\n"
1102 + "<body>\n"
1103 + "</body></html>";
1104
1105 loadPageVerifyTitle2(html);
1106 }
1107
1108
1109
1110
1111 @Test
1112 @Alerts({"function", "4", "7"})
1113 public void forEach() throws Exception {
1114 final String html = DOCTYPE_HTML
1115 + "<html>\n"
1116 + "<head>\n"
1117 + "<script>\n"
1118 + LOG_TITLE_FUNCTION
1119 + " var arr = [4, 7];\n"
1120 + " log(typeof arr.forEach);\n"
1121 + " arr.forEach(function(elem) { log(elem) });\n"
1122 + "</script>\n"
1123 + "</head>\n"
1124 + "<body>\n"
1125 + "</body></html>";
1126
1127 loadPageVerifyTitle2(html);
1128 }
1129
1130
1131
1132
1133 @Test
1134 @Alerts({"function", "4", "7"})
1135 public void forEachPrototype() throws Exception {
1136 final String html = DOCTYPE_HTML
1137 + "<html>\n"
1138 + "<head>\n"
1139 + "<script>\n"
1140 + LOG_TITLE_FUNCTION
1141 + " var arr = [4, 7];\n"
1142 + " var forEach = Array.prototype.forEach;\n"
1143 + " log(typeof forEach);\n"
1144 + " forEach.call(arr, function(elem) { log(elem) });\n"
1145 + "</script>\n"
1146 + "</head>\n"
1147 + "<body>\n"
1148 + "</body></html>";
1149
1150 loadPageVerifyTitle2(html);
1151 }
1152
1153
1154
1155
1156 @Test
1157 @Alerts({"undefined", "TypeError"})
1158 public void forEachStatic() throws Exception {
1159 final String html = DOCTYPE_HTML
1160 + "<html>\n"
1161 + "<head>\n"
1162 + "<script>\n"
1163 + LOG_TITLE_FUNCTION
1164 + " log(typeof Array.forEach);\n"
1165 + " var arr = [4, 7];\n"
1166 + " try {\n"
1167 + " Array.forEach(arr, function(elem) { log(elem) });\n"
1168 + " } catch(e) { log('TypeError'); }\n"
1169 + "</script>\n"
1170 + "</head>\n"
1171 + "<body>\n"
1172 + "</body></html>";
1173
1174 loadPageVerifyTitle2(html);
1175 }
1176
1177
1178
1179
1180 @Test
1181 @Alerts({"function", "30"})
1182 public void reduce() throws Exception {
1183 final String html = DOCTYPE_HTML
1184 + "<html>\n"
1185 + "<head>\n"
1186 + "<script>\n"
1187 + LOG_TITLE_FUNCTION
1188 + " function sum(acc, val) { return acc + val; }\n"
1189 + "\n"
1190 + " var arr = [1, 4, 9, 16];\n"
1191 + " log(typeof arr.reduce);\n"
1192 + " log(arr.reduce(sum));\n"
1193 + "</script>\n"
1194 + "</head>\n"
1195 + "<body>\n"
1196 + "</body></html>";
1197
1198 loadPageVerifyTitle2(html);
1199 }
1200
1201
1202
1203
1204 @Test
1205 @Alerts({"function", "30"})
1206 public void reducePrototype() throws Exception {
1207 final String html = DOCTYPE_HTML
1208 + "<html>\n"
1209 + "<head>\n"
1210 + "<script>\n"
1211 + LOG_TITLE_FUNCTION
1212 + " function sum(acc, val) { return acc + val; }\n"
1213 + "\n"
1214 + " var arr = [1, 4, 9, 16];\n"
1215 + " var reduce = Array.prototype.reduce;\n"
1216 + " log(typeof reduce);\n"
1217 + " log(reduce.call(arr, sum));\n"
1218 + "</script>\n"
1219 + "</head>\n"
1220 + "<body>\n"
1221 + "</body></html>";
1222
1223 loadPageVerifyTitle2(html);
1224 }
1225
1226
1227
1228
1229 @Test
1230 @Alerts({"undefined", "TypeError"})
1231 public void reduceStatic() throws Exception {
1232 final String html = DOCTYPE_HTML
1233 + "<html>\n"
1234 + "<head>\n"
1235 + "<script>\n"
1236 + LOG_TITLE_FUNCTION
1237 + " function sum(acc, val) { return acc + val; }\n"
1238 + "\n"
1239 + " log(typeof Array.reduce);\n"
1240 + " var arr = [1, 4, 9, 16];\n"
1241 + " try {\n"
1242 + " log(Array.reduce(arr, sum));\n"
1243 + " } catch(e) { log('TypeError'); }\n"
1244 + "</script>\n"
1245 + "</head>\n"
1246 + "<body>\n"
1247 + "</body></html>";
1248
1249 loadPageVerifyTitle2(html);
1250 }
1251
1252
1253
1254
1255 @Test
1256 @Alerts({"function", "2"})
1257 public void reduceRight() throws Exception {
1258 final String html = DOCTYPE_HTML
1259 + "<html>\n"
1260 + "<head>\n"
1261 + "<script>\n"
1262 + LOG_TITLE_FUNCTION
1263 + " function diff(acc, val) { return acc - val; }\n"
1264 + "\n"
1265 + " var arr = [1, 4, 9, 16];\n"
1266 + " log(typeof arr.reduceRight);\n"
1267 + " log(arr.reduceRight(diff));\n"
1268 + "</script>\n"
1269 + "</head>\n"
1270 + "<body>\n"
1271 + "</body></html>";
1272
1273 loadPageVerifyTitle2(html);
1274 }
1275
1276
1277
1278
1279 @Test
1280 @Alerts({"function", "2"})
1281 public void reduceRightPrototype() throws Exception {
1282 final String html = DOCTYPE_HTML
1283 + "<html>\n"
1284 + "<head>\n"
1285 + "<script>\n"
1286 + LOG_TITLE_FUNCTION
1287 + " function diff(acc, val) { return acc - val; }\n"
1288 + "\n"
1289 + " var arr = [1, 4, 9, 16];\n"
1290 + " var reduceRight = Array.prototype.reduceRight;\n"
1291 + " log(typeof reduceRight);\n"
1292 + " log(reduceRight.call(arr, diff));\n"
1293 + "</script>\n"
1294 + "</head>\n"
1295 + "<body>\n"
1296 + "</body></html>";
1297
1298 loadPageVerifyTitle2(html);
1299 }
1300
1301
1302
1303
1304 @Test
1305 @Alerts({"undefined", "TypeError"})
1306 public void reduceRightStatic() throws Exception {
1307 final String html = DOCTYPE_HTML
1308 + "<html>\n"
1309 + "<head>\n"
1310 + "<script>\n"
1311 + LOG_TITLE_FUNCTION
1312 + " function diff(acc, val) { return acc - val; }\n"
1313 + "\n"
1314 + " log(typeof Array.reduceRight);\n"
1315 + " var arr = [1, 4, 9, 16];\n"
1316 + " try {\n"
1317 + " log(Array.reduceRight(arr, diff));\n"
1318 + " } catch(e) { log('TypeError'); }\n"
1319 + "</script>\n"
1320 + "</head>\n"
1321 + "<body>\n"
1322 + "</body></html>";
1323
1324 loadPageVerifyTitle2(html);
1325 }
1326
1327
1328
1329
1330 @Test
1331 @Alerts({"function", "1,4,9,16"})
1332 public void join() throws Exception {
1333 final String html = DOCTYPE_HTML
1334 + "<html>\n"
1335 + "<head>\n"
1336 + "<script>\n"
1337 + LOG_TITLE_FUNCTION
1338 + " var arr = [1, 4, 9, 16];\n"
1339 + " log(typeof arr.join);\n"
1340 + " log(arr.join());\n"
1341 + "</script>\n"
1342 + "</head>\n"
1343 + "<body>\n"
1344 + "</body></html>";
1345
1346 loadPageVerifyTitle2(html);
1347 }
1348
1349
1350
1351
1352 @Test
1353 @Alerts({"function", "1,4,9,16"})
1354 public void joinPrototype() throws Exception {
1355 final String html = DOCTYPE_HTML
1356 + "<html>\n"
1357 + "<head>\n"
1358 + "<script>\n"
1359 + LOG_TITLE_FUNCTION
1360 + " var arr = [1, 4, 9, 16];\n"
1361 + " var join = Array.prototype.join;\n"
1362 + " log(typeof join);\n"
1363 + " log(join.call(arr));\n"
1364 + "</script>\n"
1365 + "</head>\n"
1366 + "<body>\n"
1367 + "</body></html>";
1368
1369 loadPageVerifyTitle2(html);
1370 }
1371
1372
1373
1374
1375 @Test
1376 @Alerts({"undefined", "TypeError"})
1377 public void joinStatic() throws Exception {
1378 final String html = DOCTYPE_HTML
1379 + "<html>\n"
1380 + "<head>\n"
1381 + "<script>\n"
1382 + LOG_TITLE_FUNCTION
1383 + " log(typeof Array.join);\n"
1384 + " var arr = [1, 4, 9, 16];\n"
1385 + " try {\n"
1386 + " log(Array.join(arr));\n"
1387 + " } catch(e) { log('TypeError'); }\n"
1388 + "</script>\n"
1389 + "</head>\n"
1390 + "<body>\n"
1391 + "</body></html>";
1392
1393 loadPageVerifyTitle2(html);
1394 }
1395
1396
1397
1398
1399 @Test
1400 @Alerts({"function", "16,9,4,1"})
1401 public void reverse() throws Exception {
1402 final String html = DOCTYPE_HTML
1403 + "<html>\n"
1404 + "<head>\n"
1405 + "<script>\n"
1406 + LOG_TITLE_FUNCTION
1407 + " var arr = [1, 4, 9, 16];\n"
1408 + " log(typeof arr.reverse);\n"
1409 + " log(arr.reverse());\n"
1410 + "</script>\n"
1411 + "</head>\n"
1412 + "<body>\n"
1413 + "</body></html>";
1414
1415 loadPageVerifyTitle2(html);
1416 }
1417
1418
1419
1420
1421 @Test
1422 @Alerts({"function", "16,9,4,1"})
1423 public void reversePrototype() throws Exception {
1424 final String html = DOCTYPE_HTML
1425 + "<html>\n"
1426 + "<head>\n"
1427 + "<script>\n"
1428 + LOG_TITLE_FUNCTION
1429 + " var arr = [1, 4, 9, 16];\n"
1430 + " var reverse = Array.prototype.reverse;\n"
1431 + " log(typeof reverse);\n"
1432 + " log(reverse.call(arr));\n"
1433 + "</script>\n"
1434 + "</head>\n"
1435 + "<body>\n"
1436 + "</body></html>";
1437
1438 loadPageVerifyTitle2(html);
1439 }
1440
1441
1442
1443
1444 @Test
1445 @Alerts({"undefined", "TypeError"})
1446 public void reverseStatic() throws Exception {
1447 final String html = DOCTYPE_HTML
1448 + "<html>\n"
1449 + "<head>\n"
1450 + "<script>\n"
1451 + LOG_TITLE_FUNCTION
1452 + " log(typeof Array.reverse);\n"
1453 + " var arr = [1, 4, 9, 16];\n"
1454 + " try {\n"
1455 + " log(Array.reverse(arr));\n"
1456 + " } catch(e) { log('TypeError'); }\n"
1457 + "</script>\n"
1458 + "</head>\n"
1459 + "<body>\n"
1460 + "</body></html>";
1461
1462 loadPageVerifyTitle2(html);
1463 }
1464
1465
1466
1467
1468 @Test
1469 @Alerts({"function", "1,16,4,9"})
1470 public void sort() throws Exception {
1471 final String html = DOCTYPE_HTML
1472 + "<html>\n"
1473 + "<head>\n"
1474 + "<script>\n"
1475 + LOG_TITLE_FUNCTION
1476 + " var arr = [1, 4, 9, 16];\n"
1477 + " log(typeof arr.sort);\n"
1478 + " log(arr.sort());\n"
1479 + "</script>\n"
1480 + "</head>\n"
1481 + "<body>\n"
1482 + "</body></html>";
1483
1484 loadPageVerifyTitle2(html);
1485 }
1486
1487
1488
1489
1490 @Test
1491 @Alerts({"function", "1,16,4,9"})
1492 public void sortPrototype() throws Exception {
1493 final String html = DOCTYPE_HTML
1494 + "<html>\n"
1495 + "<head>\n"
1496 + "<script>\n"
1497 + LOG_TITLE_FUNCTION
1498 + " var arr = [1, 4, 9, 16];\n"
1499 + " var sort = Array.prototype.sort;\n"
1500 + " log(typeof sort);\n"
1501 + " log(sort.call(arr));\n"
1502 + "</script>\n"
1503 + "</head>\n"
1504 + "<body>\n"
1505 + "</body></html>";
1506
1507 loadPageVerifyTitle2(html);
1508 }
1509
1510
1511
1512
1513 @Test
1514 @Alerts({"undefined", "TypeError"})
1515 public void sortStatic() throws Exception {
1516 final String html = DOCTYPE_HTML
1517 + "<html>\n"
1518 + "<head>\n"
1519 + "<script>\n"
1520 + LOG_TITLE_FUNCTION
1521 + " log(typeof Array.sort);\n"
1522 + " var arr = [1, 4, 9, 16];\n"
1523 + " try {\n"
1524 + " log(Array.sort(arr));\n"
1525 + " } catch(e) { log('TypeError'); }\n"
1526 + "</script>\n"
1527 + "</head>\n"
1528 + "<body>\n"
1529 + "</body></html>";
1530
1531 loadPageVerifyTitle2(html);
1532 }
1533
1534
1535
1536
1537 @Test
1538 @Alerts({"function", "6", "1,4,9,16,3,7"})
1539 public void push() throws Exception {
1540 final String html = DOCTYPE_HTML
1541 + "<html>\n"
1542 + "<head>\n"
1543 + "<script>\n"
1544 + LOG_TITLE_FUNCTION
1545 + " var arr = [1, 4, 9, 16];\n"
1546 + " log(typeof arr.push);\n"
1547 + " log(arr.push(3, 7));\n"
1548 + " log(arr);\n"
1549 + "</script>\n"
1550 + "</head>\n"
1551 + "<body>\n"
1552 + "</body></html>";
1553
1554 loadPageVerifyTitle2(html);
1555 }
1556
1557
1558
1559
1560 @Test
1561 @Alerts({"function", "6", "1,4,9,16,3,7"})
1562 public void pushPrototype() throws Exception {
1563 final String html = DOCTYPE_HTML
1564 + "<html>\n"
1565 + "<head>\n"
1566 + "<script>\n"
1567 + LOG_TITLE_FUNCTION
1568 + " var arr = [1, 4, 9, 16];\n"
1569 + " var push = Array.prototype.push;\n"
1570 + " log(typeof push);\n"
1571 + " log(push.call(arr, 3, 7));\n"
1572 + " log(arr);\n"
1573 + "</script>\n"
1574 + "</head>\n"
1575 + "<body>\n"
1576 + "</body></html>";
1577
1578 loadPageVerifyTitle2(html);
1579 }
1580
1581
1582
1583
1584 @Test
1585 @Alerts({"undefined", "TypeError"})
1586 public void pushStatic() throws Exception {
1587 final String html = DOCTYPE_HTML
1588 + "<html>\n"
1589 + "<head>\n"
1590 + "<script>\n"
1591 + LOG_TITLE_FUNCTION
1592 + " log(typeof Array.push);\n"
1593 + " var arr = [1, 4, 9, 16];\n"
1594 + " try {\n"
1595 + " log(Array.push(arr, 3, 7));\n"
1596 + " log(arr);\n"
1597 + " } catch(e) { log('TypeError'); }\n"
1598 + "</script>\n"
1599 + "</head>\n"
1600 + "<body>\n"
1601 + "</body></html>";
1602
1603 loadPageVerifyTitle2(html);
1604 }
1605
1606
1607
1608
1609 @Test
1610 @Alerts({"function", "16", "1,4,9"})
1611 public void pop() throws Exception {
1612 final String html = DOCTYPE_HTML
1613 + "<html>\n"
1614 + "<head>\n"
1615 + "<script>\n"
1616 + LOG_TITLE_FUNCTION
1617 + " var arr = [1, 4, 9, 16];\n"
1618 + " log(typeof arr.pop);\n"
1619 + " log(arr.pop());\n"
1620 + " log(arr);\n"
1621 + "</script>\n"
1622 + "</head>\n"
1623 + "<body>\n"
1624 + "</body></html>";
1625
1626 loadPageVerifyTitle2(html);
1627 }
1628
1629
1630
1631
1632 @Test
1633 @Alerts({"function", "16", "1,4,9"})
1634 public void popPrototype() throws Exception {
1635 final String html = DOCTYPE_HTML
1636 + "<html>\n"
1637 + "<head>\n"
1638 + "<script>\n"
1639 + LOG_TITLE_FUNCTION
1640 + " var arr = [1, 4, 9, 16];\n"
1641 + " var pop = Array.prototype.pop;\n"
1642 + " log(typeof pop);\n"
1643 + " log(pop.call(arr));\n"
1644 + " log(arr);\n"
1645 + "</script>\n"
1646 + "</head>\n"
1647 + "<body>\n"
1648 + "</body></html>";
1649
1650 loadPageVerifyTitle2(html);
1651 }
1652
1653
1654
1655
1656 @Test
1657 @Alerts({"undefined", "TypeError"})
1658 public void popStatic() throws Exception {
1659 final String html = DOCTYPE_HTML
1660 + "<html>\n"
1661 + "<head>\n"
1662 + "<script>\n"
1663 + LOG_TITLE_FUNCTION
1664 + " log(typeof Array.pop);\n"
1665 + " var arr = [1, 4, 9, 16];\n"
1666 + " try {\n"
1667 + " log(Array.pop(arr));\n"
1668 + " log(arr);\n"
1669 + " } catch(e) { log('TypeError'); }\n"
1670 + "</script>\n"
1671 + "</head>\n"
1672 + "<body>\n"
1673 + "</body></html>";
1674
1675 loadPageVerifyTitle2(html);
1676 }
1677
1678
1679
1680
1681 @Test
1682 @Alerts({"function", "1", "4,9,16"})
1683 public void shift() throws Exception {
1684 final String html = DOCTYPE_HTML
1685 + "<html>\n"
1686 + "<head>\n"
1687 + "<script>\n"
1688 + LOG_TITLE_FUNCTION
1689 + " var arr = [1, 4, 9, 16];\n"
1690 + " log(typeof arr.shift);\n"
1691 + " log(arr.shift());\n"
1692 + " log(arr);\n"
1693 + "</script>\n"
1694 + "</head>\n"
1695 + "<body>\n"
1696 + "</body></html>";
1697
1698 loadPageVerifyTitle2(html);
1699 }
1700
1701
1702
1703
1704 @Test
1705 @Alerts({"function", "1", "4,9,16"})
1706 public void shiftPrototype() throws Exception {
1707 final String html = DOCTYPE_HTML
1708 + "<html>\n"
1709 + "<head>\n"
1710 + "<script>\n"
1711 + LOG_TITLE_FUNCTION
1712 + " var arr = [1, 4, 9, 16];\n"
1713 + " var shift = Array.prototype.shift;\n"
1714 + " log(typeof shift);\n"
1715 + " log(shift.call(arr));\n"
1716 + " log(arr);\n"
1717 + "</script>\n"
1718 + "</head>\n"
1719 + "<body>\n"
1720 + "</body></html>";
1721
1722 loadPageVerifyTitle2(html);
1723 }
1724
1725
1726
1727
1728 @Test
1729 @Alerts({"undefined", "TypeError"})
1730 public void shiftStatic() throws Exception {
1731 final String html = DOCTYPE_HTML
1732 + "<html>\n"
1733 + "<head>\n"
1734 + "<script>\n"
1735 + LOG_TITLE_FUNCTION
1736 + " log(typeof Array.shift);\n"
1737 + " var arr = [1, 4, 9, 16];\n"
1738 + " try {\n"
1739 + " log(Array.shift(arr));\n"
1740 + " log(arr);\n"
1741 + " } catch(e) { log('TypeError'); }\n"
1742 + "</script>\n"
1743 + "</head>\n"
1744 + "<body>\n"
1745 + "</body></html>";
1746
1747 loadPageVerifyTitle2(html);
1748 }
1749
1750
1751
1752
1753 @Test
1754 @Alerts({"function", "6", "3,7,1,4,9,16"})
1755 public void unshift() throws Exception {
1756 final String html = DOCTYPE_HTML
1757 + "<html>\n"
1758 + "<head>\n"
1759 + "<script>\n"
1760 + LOG_TITLE_FUNCTION
1761 + " var arr = [1, 4, 9, 16];\n"
1762 + " log(typeof arr.unshift);\n"
1763 + " log(arr.unshift(3, 7));\n"
1764 + " log(arr);\n"
1765 + "</script>\n"
1766 + "</head>\n"
1767 + "<body>\n"
1768 + "</body></html>";
1769
1770 loadPageVerifyTitle2(html);
1771 }
1772
1773
1774
1775
1776 @Test
1777 @Alerts({"function", "6", "3,7,1,4,9,16"})
1778 public void unshiftPrototype() throws Exception {
1779 final String html = DOCTYPE_HTML
1780 + "<html>\n"
1781 + "<head>\n"
1782 + "<script>\n"
1783 + LOG_TITLE_FUNCTION
1784 + " var arr = [1, 4, 9, 16];\n"
1785 + " var unshift = Array.prototype.unshift;\n"
1786 + " log(typeof unshift);\n"
1787 + " log(unshift.call(arr, 3, 7));\n"
1788 + " log(arr);\n"
1789 + "</script>\n"
1790 + "</head>\n"
1791 + "<body>\n"
1792 + "</body></html>";
1793
1794 loadPageVerifyTitle2(html);
1795 }
1796
1797
1798
1799
1800 @Test
1801 @Alerts({"undefined", "TypeError"})
1802 public void unshiftStatic() throws Exception {
1803 final String html = DOCTYPE_HTML
1804 + "<html>\n"
1805 + "<head>\n"
1806 + "<script>\n"
1807 + LOG_TITLE_FUNCTION
1808 + " log(typeof Array.unshift);\n"
1809 + " var arr = [1, 4, 9, 16];\n"
1810 + " try {\n"
1811 + " log(Array.unshift(arr, 3, 7));\n"
1812 + " log(arr);\n"
1813 + " } catch(e) { log('TypeError'); }\n"
1814 + "</script>\n"
1815 + "</head>\n"
1816 + "<body>\n"
1817 + "</body></html>";
1818
1819 loadPageVerifyTitle2(html);
1820 }
1821
1822
1823
1824
1825 @Test
1826 @Alerts({"function", "4,9", "1,16"})
1827 public void splice() throws Exception {
1828 final String html = DOCTYPE_HTML
1829 + "<html>\n"
1830 + "<head>\n"
1831 + "<script>\n"
1832 + LOG_TITLE_FUNCTION
1833 + " var arr = [1, 4, 9, 16];\n"
1834 + " log(typeof arr.splice);\n"
1835 + " log(arr.splice(1, 2));\n"
1836 + " log(arr);\n"
1837 + "</script>\n"
1838 + "</head>\n"
1839 + "<body>\n"
1840 + "</body></html>";
1841
1842 loadPageVerifyTitle2(html);
1843 }
1844
1845
1846
1847
1848 @Test
1849 @Alerts({"function", "4,9", "1,16"})
1850 public void splicePrototype() throws Exception {
1851 final String html = DOCTYPE_HTML
1852 + "<html>\n"
1853 + "<head>\n"
1854 + "<script>\n"
1855 + LOG_TITLE_FUNCTION
1856 + " var arr = [1, 4, 9, 16];\n"
1857 + " var splice = Array.prototype.splice;\n"
1858 + " log(typeof splice);\n"
1859 + " log(splice.call(arr, 1, 2));\n"
1860 + " log(arr);\n"
1861 + "</script>\n"
1862 + "</head>\n"
1863 + "<body>\n"
1864 + "</body></html>";
1865
1866 loadPageVerifyTitle2(html);
1867 }
1868
1869
1870
1871
1872 @Test
1873 @Alerts({"undefined", "TypeError"})
1874 public void spliceStatic() throws Exception {
1875 final String html = DOCTYPE_HTML
1876 + "<html>\n"
1877 + "<head>\n"
1878 + "<script>\n"
1879 + LOG_TITLE_FUNCTION
1880 + " log(typeof Array.splice);\n"
1881 + " var arr = [1, 4, 9, 16];\n"
1882 + " try {\n"
1883 + " log(Array.splice(arr, 1, 2));\n"
1884 + " log(arr);\n"
1885 + " } catch(e) { log('TypeError'); }\n"
1886 + "</script>\n"
1887 + "</head>\n"
1888 + "<body>\n"
1889 + "</body></html>";
1890
1891 loadPageVerifyTitle2(html);
1892 }
1893
1894
1895
1896
1897 @Test
1898 @Alerts({"function", "1,4,9,16,1,2", "1,4,9,16"})
1899 public void concat() throws Exception {
1900 final String html = DOCTYPE_HTML
1901 + "<html>\n"
1902 + "<head>\n"
1903 + "<script>\n"
1904 + LOG_TITLE_FUNCTION
1905 + " var arr = [1, 4, 9, 16];\n"
1906 + " log(typeof arr.concat);\n"
1907 + " log(arr.concat(1, 2));\n"
1908 + " log(arr);\n"
1909 + "</script>\n"
1910 + "</head>\n"
1911 + "<body>\n"
1912 + "</body></html>";
1913
1914 loadPageVerifyTitle2(html);
1915 }
1916
1917
1918
1919
1920 @Test
1921 @Alerts({"function", "1,4,9,16,1,2", "1,4,9,16"})
1922 public void concatPrototype() throws Exception {
1923 final String html = DOCTYPE_HTML
1924 + "<html>\n"
1925 + "<head>\n"
1926 + "<script>\n"
1927 + LOG_TITLE_FUNCTION
1928 + " var arr = [1, 4, 9, 16];\n"
1929 + " var concat = Array.prototype.concat;\n"
1930 + " log(typeof concat);\n"
1931 + " log(concat.call(arr, 1, 2));\n"
1932 + " log(arr);\n"
1933 + "</script>\n"
1934 + "</head>\n"
1935 + "<body>\n"
1936 + "</body></html>";
1937
1938 loadPageVerifyTitle2(html);
1939 }
1940
1941
1942
1943
1944 @Test
1945 @Alerts({"undefined", "TypeError"})
1946 public void concatStatic() throws Exception {
1947 final String html = DOCTYPE_HTML
1948 + "<html>\n"
1949 + "<head>\n"
1950 + "<script>\n"
1951 + LOG_TITLE_FUNCTION
1952 + " log(typeof Array.concat);\n"
1953 + " var arr = [1, 4, 9, 16];\n"
1954 + " try {\n"
1955 + " log(Array.concat(arr, 1, 2));\n"
1956 + " log(arr);\n"
1957 + " } catch(e) { log('TypeError'); }\n"
1958 + "</script>\n"
1959 + "</head>\n"
1960 + "<body>\n"
1961 + "</body></html>";
1962
1963 loadPageVerifyTitle2(html);
1964 }
1965
1966
1967
1968
1969 @Test
1970 @Alerts({"function", "4", "1,4,9,16"})
1971 public void slice() throws Exception {
1972 final String html = DOCTYPE_HTML
1973 + "<html>\n"
1974 + "<head>\n"
1975 + "<script>\n"
1976 + LOG_TITLE_FUNCTION
1977 + " var arr = [1, 4, 9, 16];\n"
1978 + " log(typeof arr.slice);\n"
1979 + " log(arr.slice(1, 2));\n"
1980 + " log(arr);\n"
1981 + "</script>\n"
1982 + "</head>\n"
1983 + "<body>\n"
1984 + "</body></html>";
1985
1986 loadPageVerifyTitle2(html);
1987 }
1988
1989
1990
1991
1992 @Test
1993 @Alerts({"function", "4", "1,4,9,16"})
1994 public void slicePrototype() throws Exception {
1995 final String html = DOCTYPE_HTML
1996 + "<html>\n"
1997 + "<head>\n"
1998 + "<script>\n"
1999 + LOG_TITLE_FUNCTION
2000 + " var arr = [1, 4, 9, 16];\n"
2001 + " var slice = Array.prototype.slice;\n"
2002 + " log(typeof slice);\n"
2003 + " log(slice.call(arr, 1, 2));\n"
2004 + " log(arr);\n"
2005 + "</script>\n"
2006 + "</head>\n"
2007 + "<body>\n"
2008 + "</body></html>";
2009
2010 loadPageVerifyTitle2(html);
2011 }
2012
2013
2014
2015
2016 @Test
2017 @Alerts({"undefined", "TypeError"})
2018 public void sliceStatic() throws Exception {
2019 final String html = DOCTYPE_HTML
2020 + "<html>\n"
2021 + "<head>\n"
2022 + "<script>\n"
2023 + LOG_TITLE_FUNCTION
2024 + " log(typeof Array.concat);\n"
2025 + " var arr = [1, 4, 9, 16];\n"
2026 + " try {\n"
2027 + " log(Array.slice(arr, 1, 2));\n"
2028 + " log(arr);\n"
2029 + " } catch(e) { log('TypeError'); }\n"
2030 + "</script>\n"
2031 + "</head>\n"
2032 + "<body>\n"
2033 + "</body></html>";
2034
2035 loadPageVerifyTitle2(html);
2036 }
2037
2038
2039
2040
2041 @Test
2042 @Alerts({"function", "2", "1,4,9,16"})
2043 public void indexOf() throws Exception {
2044 final String html = DOCTYPE_HTML
2045 + "<html>\n"
2046 + "<head>\n"
2047 + "<script>\n"
2048 + LOG_TITLE_FUNCTION
2049 + " var arr = [1, 4, 9, 16];\n"
2050 + " log(typeof arr.indexOf);\n"
2051 + " log(arr.indexOf(9));\n"
2052 + " log(arr);\n"
2053 + "</script>\n"
2054 + "</head>\n"
2055 + "<body>\n"
2056 + "</body></html>";
2057
2058 loadPageVerifyTitle2(html);
2059 }
2060
2061
2062
2063
2064 @Test
2065 @Alerts({"function", "2", "1,4,9,16"})
2066 public void indexOfPrototype() throws Exception {
2067 final String html = DOCTYPE_HTML
2068 + "<html>\n"
2069 + "<head>\n"
2070 + "<script>\n"
2071 + LOG_TITLE_FUNCTION
2072 + " var arr = [1, 4, 9, 16];\n"
2073 + " var indexOf = Array.prototype.indexOf;\n"
2074 + " log(typeof indexOf);\n"
2075 + " log(indexOf.call(arr, 9));\n"
2076 + " log(arr);\n"
2077 + "</script>\n"
2078 + "</head>\n"
2079 + "<body>\n"
2080 + "</body></html>";
2081
2082 loadPageVerifyTitle2(html);
2083 }
2084
2085
2086
2087
2088 @Test
2089 @Alerts({"undefined", "TypeError"})
2090 public void indexOfStatic() throws Exception {
2091 final String html = DOCTYPE_HTML
2092 + "<html>\n"
2093 + "<head>\n"
2094 + "<script>\n"
2095 + LOG_TITLE_FUNCTION
2096 + " log(typeof Array.indexOf);\n"
2097 + " var arr = [1, 4, 9, 16];\n"
2098 + " try {\n"
2099 + " log(Array.indexOf(arr, 9));\n"
2100 + " log(arr);\n"
2101 + " } catch(e) { log('TypeError'); }\n"
2102 + "</script>\n"
2103 + "</head>\n"
2104 + "<body>\n"
2105 + "</body></html>";
2106
2107 loadPageVerifyTitle2(html);
2108 }
2109
2110
2111
2112
2113 @Test
2114 @Alerts({"function", "2", "1,4,9,16"})
2115 public void lastIndexOf() throws Exception {
2116 final String html = DOCTYPE_HTML
2117 + "<html>\n"
2118 + "<head>\n"
2119 + "<script>\n"
2120 + LOG_TITLE_FUNCTION
2121 + " var arr = [1, 4, 9, 16];\n"
2122 + " log(typeof arr.lastIndexOf);\n"
2123 + " log(arr.lastIndexOf(9));\n"
2124 + " log(arr);\n"
2125 + "</script>\n"
2126 + "</head>\n"
2127 + "<body>\n"
2128 + "</body></html>";
2129
2130 loadPageVerifyTitle2(html);
2131 }
2132
2133
2134
2135
2136 @Test
2137 @Alerts({"function", "2", "1,4,9,16"})
2138 public void lastIndexOfPrototype() throws Exception {
2139 final String html = DOCTYPE_HTML
2140 + "<html>\n"
2141 + "<head>\n"
2142 + "<script>\n"
2143 + LOG_TITLE_FUNCTION
2144 + " var arr = [1, 4, 9, 16];\n"
2145 + " var lastIndexOf = Array.prototype.lastIndexOf;\n"
2146 + " log(typeof lastIndexOf);\n"
2147 + " log(lastIndexOf.call(arr, 9));\n"
2148 + " log(arr);\n"
2149 + "</script>\n"
2150 + "</head>\n"
2151 + "<body>\n"
2152 + "</body></html>";
2153
2154 loadPageVerifyTitle2(html);
2155 }
2156
2157
2158
2159
2160 @Test
2161 @Alerts({"undefined", "TypeError"})
2162 public void lastIndexOfStatic() throws Exception {
2163 final String html = DOCTYPE_HTML
2164 + "<html>\n"
2165 + "<head>\n"
2166 + "<script>\n"
2167 + LOG_TITLE_FUNCTION
2168 + " log(typeof Array.lastIndexOf);\n"
2169 + " var arr = [1, 4, 9, 16];\n"
2170 + " try {\n"
2171 + " log(Array.lastIndexOf(arr, 9));\n"
2172 + " log(arr);\n"
2173 + " } catch(e) { log('TypeError'); }\n"
2174 + "</script>\n"
2175 + "</head>\n"
2176 + "<body>\n"
2177 + "</body></html>";
2178
2179 loadPageVerifyTitle2(html);
2180 }
2181
2182
2183
2184
2185 @Test
2186 @Alerts("3")
2187 public void of() throws Exception {
2188 final String html = DOCTYPE_HTML
2189 + "<html>\n"
2190 + "<head>\n"
2191 + "<script>\n"
2192 + LOG_TITLE_FUNCTION
2193 + " if (Array.of) {\n"
2194 + " var arr = Array.of(1, 2, 3);\n"
2195 + " log(arr.length);\n"
2196 + " } else {\n"
2197 + " log('not supported');\n"
2198 + " }\n"
2199 + "</script>\n"
2200 + "</head>\n"
2201 + "<body>\n"
2202 + "</body></html>";
2203
2204 loadPageVerifyTitle2(html);
2205 }
2206 }