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.annotation.Alerts;
19 import org.htmlunit.junit.annotation.HtmlUnitNYI;
20 import org.junit.jupiter.api.Disabled;
21 import org.junit.jupiter.api.Test;
22
23
24
25
26
27
28
29
30 public class ArgumentsTest extends WebDriverTestCase {
31
32
33
34
35 @Test
36 @Alerts({"0", "0", "1", "0"})
37 public void arguments() throws Exception {
38 final String html = DOCTYPE_HTML
39 + "<html>\n"
40 + "<body>\n"
41 + "<script>\n"
42 + LOG_TITLE_FUNCTION
43
44 + " function test() {\n"
45 + " log(test.arguments.length);\n"
46 + " test1('hi');\n"
47 + " }\n"
48
49 + " function test1(a) {\n"
50 + " log(test.arguments.length);\n"
51 + " log(test1.arguments.length);\n"
52 + " log(arguments.callee.caller.arguments.length);\n"
53 + " }\n"
54
55 + " test();\n"
56 + "</script>\n"
57 + "</body></html>";
58
59 loadPageVerifyTitle2(html);
60 }
61
62
63
64
65 @Test
66 @Alerts("true")
67 public void argumentsPrototype() throws Exception {
68 final String html = DOCTYPE_HTML
69 + "<html>\n"
70 + "<body>\n"
71 + "<script>\n"
72 + LOG_TITLE_FUNCTION
73
74 + " function test() {\n"
75 + " log(arguments.prototype === {}.prototype);\n"
76 + " }\n"
77
78 + " test();\n"
79 + "</script>\n"
80 + "</body></html>";
81
82 loadPageVerifyTitle2(html);
83 }
84
85
86
87
88 @Test
89 @Alerts({"undefined/undefined", "undefined/undefined", "W-true", "C-true", "E-false"})
90 public void argumentsLengthProperty() throws Exception {
91 final String html = DOCTYPE_HTML
92 + "<html><body>"
93 + "<script>\n"
94 + LOG_TITLE_FUNCTION
95
96 + "function test() {\n"
97 + " let desc = Object.getOwnPropertyDescriptor(arguments, 'length');\n"
98 + " log(typeof desc.get + '/' + desc.get);\n"
99 + " log(typeof desc.set + '/' + desc.set);\n"
100 + " log('W-' + desc.writable);\n"
101 + " log('C-' + desc.configurable);\n"
102 + " log('E-' + desc.enumerable);\n"
103 + "}\n"
104
105 + "test();\n"
106 + "</script></body></html>";
107
108 loadPageVerifyTitle2(html);
109 }
110
111
112
113
114 @Test
115 @Alerts({"undefined/undefined", "undefined/undefined", "W-true", "C-true", "E-false"})
116 public void argumentsLengthPropertyStrict() throws Exception {
117 final String html = DOCTYPE_HTML
118 + "<html><body>"
119 + "<script>\n"
120 + "'use strict';\n"
121 + LOG_TITLE_FUNCTION
122
123 + "function test() {\n"
124 + " let desc = Object.getOwnPropertyDescriptor(arguments, 'length');\n"
125 + " log(typeof desc.get + '/' + desc.get);\n"
126 + " log(typeof desc.set + '/' + desc.set);\n"
127 + " log('W-' + desc.writable);\n"
128 + " log('C-' + desc.configurable);\n"
129 + " log('E-' + desc.enumerable);\n"
130 + "}\n"
131
132 + "test();\n"
133 + "</script></body></html>";
134
135 loadPageVerifyTitle2(html);
136 }
137
138
139
140
141 @Test
142 @Alerts({"undefined/undefined", "undefined/undefined", "W-true", "C-true", "E-false"})
143 public void argumentsCalleeProperty() throws Exception {
144 final String html = DOCTYPE_HTML
145 + "<html><body>"
146 + "<script>\n"
147 + LOG_TITLE_FUNCTION
148
149 + "function test() {\n"
150 + " let desc = Object.getOwnPropertyDescriptor(arguments, 'callee');\n"
151 + " log(typeof desc.get + '/' + desc.get);\n"
152 + " log(typeof desc.set + '/' + desc.set);\n"
153 + " log('W-' + desc.writable);\n"
154 + " log('C-' + desc.configurable);\n"
155 + " log('E-' + desc.enumerable);\n"
156 + "}\n"
157
158 + "test();\n"
159 + "</script></body></html>";
160
161 loadPageVerifyTitle2(html);
162 }
163
164
165
166
167 @Test
168 @Alerts(DEFAULT = {"function/function () { [native code] }",
169 "function/function () { [native code] }",
170 "W-undefined", "C-false", "E-false"},
171 FF = {"function/function() { [native code] }",
172 "function/function() { [native code] }",
173 "W-undefined", "C-false", "E-false"},
174 FF_ESR = {"function/function() { [native code] }",
175 "function/function() { [native code] }",
176 "W-undefined", "C-false", "E-false"})
177 @HtmlUnitNYI(FF = {"function/function () { [native code] }",
178 "function/function () { [native code] }",
179 "W-undefined", "C-false", "E-false"},
180 FF_ESR = {"function/function () { [native code] }",
181 "function/function () { [native code] }",
182 "W-undefined", "C-false", "E-false"})
183 public void argumentsCalleePropertyStrict() throws Exception {
184 final String html = DOCTYPE_HTML
185 + "<html><body>"
186 + "<script>\n"
187 + "'use strict';\n"
188 + LOG_TITLE_FUNCTION
189
190 + "function test() {\n"
191 + " let desc = Object.getOwnPropertyDescriptor(arguments, 'callee');\n"
192 + " log(typeof desc.get + '/' + desc.get);\n"
193 + " log(typeof desc.set + '/' + desc.set);\n"
194 + " log('W-' + desc.writable);\n"
195 + " log('C-' + desc.configurable);\n"
196 + " log('E-' + desc.enumerable);\n"
197 + "}\n"
198
199 + "test();\n"
200 + "</script></body></html>";
201
202 loadPageVerifyTitle2(html);
203 }
204
205
206
207
208 @Test
209 @Alerts({"null", "[object Arguments]", "[object Arguments]", "null"})
210 public void argumentsShouldBeNullOutsideFunction() throws Exception {
211 final String html = DOCTYPE_HTML
212 + "<html>\n"
213 + "<body>\n"
214 + "<script>\n"
215 + LOG_TITLE_FUNCTION
216 + " function test() {\n"
217 + " log(arguments);\n"
218 + " log(test.arguments);\n"
219 + " }\n"
220 + " log(test.arguments);\n"
221 + " test();\n"
222 + " log(test.arguments);\n"
223 + "</script>"
224 + "</body></html>";
225
226 loadPageVerifyTitle2(html);
227 }
228
229
230
231
232 @Test
233 @Alerts({"TypeError", "[object Arguments]", "TypeError", "TypeError"})
234 @HtmlUnitNYI(CHROME = {"null", "[object Arguments]", "[object Arguments]", "null"},
235 EDGE = {"null", "[object Arguments]", "[object Arguments]", "null"},
236 FF = {"null", "[object Arguments]", "[object Arguments]", "null"},
237 FF_ESR = {"null", "[object Arguments]", "[object Arguments]", "null"})
238 public void argumentsShouldBeNullOutsideFunctionStrict() throws Exception {
239 final String html = DOCTYPE_HTML
240 + "<html>\n"
241 + "<body>\n"
242 + "<script>\n"
243 + "'use strict';\n"
244 + LOG_TITLE_FUNCTION
245
246 + " function test() {\n"
247 + " log(arguments);\n"
248 + " try {\n"
249 + " log(test.arguments);\n"
250 + " } catch(e) {\n"
251 + " logEx(e);\n"
252 + " }\n"
253 + " }\n"
254
255 + " try {\n"
256 + " log(test.arguments);\n"
257 + " } catch(e) {\n"
258 + " logEx(e);\n"
259 + " }\n"
260 + " test();\n"
261 + " try {\n"
262 + " log(test.arguments);\n"
263 + " } catch(e) {\n"
264 + " logEx(e);\n"
265 + " }\n"
266 + "</script>\n"
267 + "</body></html>";
268
269 loadPageVerifyTitle2(html);
270 }
271
272
273
274
275 @Test
276 @Alerts("callee,length")
277 public void argumentsPropertyNames() throws Exception {
278 final String html = DOCTYPE_HTML
279 + "<html>\n"
280 + "<body>\n"
281 + "<script>\n"
282 + LOG_TITLE_FUNCTION
283 + "function test() {\n"
284 + " let p = Object.getOwnPropertyNames(arguments);\n"
285 + " p.sort();\n"
286 + " log(p);\n"
287 + "}\n"
288 + "test();\n"
289 + "</script>\n"
290 + "</body></html>";
291
292 loadPageVerifyTitle2(html);
293 }
294
295
296
297
298
299 @Test
300 @Alerts("callee,length")
301 public void argumentsPropertyNamesStrict() throws Exception {
302 final String html = DOCTYPE_HTML
303 + "<html>\n"
304 + "<body>\n"
305 + "<script>\n"
306 + "'use strict';\n"
307 + LOG_TITLE_FUNCTION
308 + "function test() {\n"
309 + " let p = Object.getOwnPropertyNames(arguments);\n"
310 + " p.sort();\n"
311 + " log(p);\n"
312 + "}\n"
313 + "test();\n"
314 + "</script>\n"
315 + "</body></html>";
316
317 loadPageVerifyTitle2(html);
318 }
319
320
321
322
323 @Test
324 @Alerts({"2", "2"})
325 public void passedCountDifferentFromDeclared() throws Exception {
326 final String html = DOCTYPE_HTML
327 + "<html>\n"
328 + "<body>\n"
329 + "<script>\n"
330 + LOG_TITLE_FUNCTION
331 + "function test() {\n"
332 + " log(arguments.length);\n"
333 + " log(test.arguments.length);\n"
334 + "}\n"
335 + "test('hi', 'there');\n"
336 + "</script>\n"
337 + "</body></html>";
338
339 loadPageVerifyTitle2(html);
340 }
341
342
343
344
345 @Test
346 @Alerts({"2", "TypeError"})
347 @HtmlUnitNYI(CHROME = {"2", "[object Arguments]"},
348 EDGE = {"2", "[object Arguments]"},
349 FF = {"2", "[object Arguments]"},
350 FF_ESR = {"2", "[object Arguments]"})
351 public void passedCountDifferentFromDeclaredStrict() throws Exception {
352 final String html = DOCTYPE_HTML
353 + "<html>\n"
354 + "<body>\n"
355 + "<script>\n"
356 + "'use strict';\n"
357 + LOG_TITLE_FUNCTION
358 + "function test() {\n"
359 + " log(arguments.length);\n"
360 + " try {\n"
361 + " log(test.arguments);\n"
362 + " } catch(e) {\n"
363 + " logEx(e);\n"
364 + " }\n"
365 + "}\n"
366 + "test('hi', 'there');\n"
367 + "</script>\n"
368 + "</body></html>";
369
370 loadPageVerifyTitle2(html);
371 }
372
373
374
375
376 @Test
377 @Alerts({"2", "hello", "world", "undefined", "undefined"})
378 public void readOnlyWhenAccessedThroughFunction() throws Exception {
379 final String html = DOCTYPE_HTML
380 + "<html>"
381 + "<body>"
382 + "<script>\n"
383 + LOG_TITLE_FUNCTION
384 + "function test() {\n"
385 + " test.arguments[1] = 'hi';\n"
386 + " test.arguments[3] = 'you';\n"
387 + " log(test.arguments.length);\n"
388 + " log(test.arguments[0]);\n"
389 + " log(test.arguments[1]);\n"
390 + " log(test.arguments[2]);\n"
391 + " log(test.arguments[3]);\n"
392 + "}\n"
393 + "test('hello', 'world');\n"
394 + "</script>\n"
395 + "</body></html>";
396
397 loadPageVerifyTitle2(html);
398 }
399
400
401
402
403 @Test
404 @Alerts({"2", "hello", "hi", "undefined", "you"})
405 public void writableWithinFunction() throws Exception {
406 final String html = DOCTYPE_HTML
407 + "<html>"
408 + "<body>\n"
409 + "<script>\n"
410 + LOG_TITLE_FUNCTION
411 + "function test() {\n"
412 + " arguments[1] = 'hi';\n"
413 + " arguments[3] = 'you';\n"
414 + " log(arguments.length);\n"
415 + " log(arguments[0]);\n"
416 + " log(arguments[1]);\n"
417 + " log(arguments[2]);\n"
418 + " log(arguments[3]);\n"
419 + "}\n"
420 + "test('hello', 'world');\n"
421 + "</script>\n"
422 + "</body></html>";
423
424 loadPageVerifyTitle2(html);
425 }
426
427
428
429
430 @Test
431 @Alerts({"2", "hello", "hi", "undefined", "you"})
432 public void writableWithinFunctionStrict() throws Exception {
433 final String html = DOCTYPE_HTML
434 + "<html><body>\n"
435 + "<script>\n"
436 + "'use strict';\n"
437 + LOG_TITLE_FUNCTION
438 + "function test() {\n"
439 + " arguments[1] = 'hi';\n"
440 + " arguments[3] = 'you';\n"
441 + " log(arguments.length);\n"
442 + " log(arguments[0]);\n"
443 + " log(arguments[1]);\n"
444 + " log(arguments[2]);\n"
445 + " log(arguments[3]);\n"
446 + "}\n"
447 + "test('hello', 'world');\n"
448 + "</script></body></html>";
449
450 loadPageVerifyTitle2(html);
451 }
452
453
454
455
456 @Test
457 @Alerts({"2", "hello", "hi", "undefined", "you",
458 "hello", "hi", "undefined"})
459 public void writableWithinFunctionAdjustsArgument() throws Exception {
460 final String html = DOCTYPE_HTML
461 + "<html><body>\n"
462 + "<script>\n"
463 + LOG_TITLE_FUNCTION
464 + "function test(a, b, c) {\n"
465 + " arguments[1] = 'hi';\n"
466 + " arguments[3] = 'you';\n"
467 + " log(arguments.length);\n"
468 + " log(arguments[0]);\n"
469 + " log(arguments[1]);\n"
470 + " log(arguments[2]);\n"
471 + " log(arguments[3]);\n"
472
473 + " log(a);\n"
474 + " log(b);\n"
475 + " log(c);\n"
476 + "}\n"
477 + "test('hello', 'world');\n"
478 + "</script></body></html>";
479
480 loadPageVerifyTitle2(html);
481 }
482
483
484
485
486 @Test
487 @Alerts({"2", "hello", "hi", "undefined", "you",
488 "hello", "world", "undefined"})
489 public void writableWithinFunctionAdjustsArgumentStrict() throws Exception {
490 final String html = DOCTYPE_HTML
491 + "<html><body>\n"
492 + "<script>\n"
493 + "'use strict';\n"
494 + LOG_TITLE_FUNCTION
495 + "function test(a, b, c) {\n"
496 + " arguments[1] = 'hi';\n"
497 + " arguments[3] = 'you';\n"
498 + " log(arguments.length);\n"
499 + " log(arguments[0]);\n"
500 + " log(arguments[1]);\n"
501 + " log(arguments[2]);\n"
502 + " log(arguments[3]);\n"
503
504 + " log(a);\n"
505 + " log(b);\n"
506 + " log(c);\n"
507 + "}\n"
508 + "test('hello', 'world');\n"
509 + "</script></body></html>";
510
511 loadPageVerifyTitle2(html);
512 }
513
514
515
516
517 @Test
518 @Alerts({"3", "hello", "hi", "world", "you", "hello", "whole,world"})
519 public void writableWithinFunctionRestAdjustsArgument() throws Exception {
520 final String html = DOCTYPE_HTML
521 + "<html><body>\n"
522 + "<script>\n"
523 + LOG_TITLE_FUNCTION
524 + "function test(a, ...b) {\n"
525 + " arguments[1] = 'hi';\n"
526 + " arguments[3] = 'you';\n"
527 + " log(arguments.length);\n"
528 + " log(arguments[0]);\n"
529 + " log(arguments[1]);\n"
530 + " log(arguments[2]);\n"
531 + " log(arguments[3]);\n"
532
533 + " log(a);\n"
534 + " log(b);\n"
535 + "}\n"
536 + "test('hello', 'whole', 'world');\n"
537 + "</script></body></html>";
538
539 loadPageVerifyTitle2(html);
540 }
541
542
543
544
545 @Test
546 @Alerts({"3", "hello", "hi", "world", "you", "hello", "whole,world"})
547 public void writableWithinFunctionRestAdjustsArgumentStrict() throws Exception {
548 final String html = DOCTYPE_HTML
549 + "<html><body>\n"
550 + "<script>\n"
551 + "'use strict';\n"
552 + LOG_TITLE_FUNCTION
553 + "function test(a, ...b) {\n"
554 + " arguments[1] = 'hi';\n"
555 + " arguments[3] = 'you';\n"
556 + " log(arguments.length);\n"
557 + " log(arguments[0]);\n"
558 + " log(arguments[1]);\n"
559 + " log(arguments[2]);\n"
560 + " log(arguments[3]);\n"
561
562 + " log(a);\n"
563 + " log(b);\n"
564 + "}\n"
565 + "test('hello', 'whole', 'world');\n"
566 + "</script></body></html>";
567
568 loadPageVerifyTitle2(html);
569 }
570
571
572
573
574 @Test
575 @Alerts({"1", "hello", "hi", "undefined", "you", "hello", "default",
576 "2", "hello", "hi", "undefined", "you", "hello", "world"})
577 public void writableWithinFunctionDefaultAdjustsArgument() throws Exception {
578 final String html = DOCTYPE_HTML
579 + "<html><body>\n"
580 + "<script>\n"
581 + LOG_TITLE_FUNCTION
582 + "function test(a, b='default') {\n"
583 + " arguments[1] = 'hi';\n"
584 + " arguments[3] = 'you';\n"
585 + " log(arguments.length);\n"
586 + " log(arguments[0]);\n"
587 + " log(arguments[1]);\n"
588 + " log(arguments[2]);\n"
589 + " log(arguments[3]);\n"
590
591 + " log(a);\n"
592 + " log(b);\n"
593 + "}\n"
594 + "test('hello');\n"
595 + "test('hello', 'world');\n"
596 + "</script></body></html>";
597
598 loadPageVerifyTitle2(html);
599 }
600
601
602
603
604 @Test
605 @Alerts({"1", "hello", "hi", "undefined", "you", "hello", "default",
606 "2", "hello", "hi", "undefined", "you", "hello", "world"})
607 public void writableWithinFunctionDefaultAdjustsArgumentStrict() throws Exception {
608 final String html = DOCTYPE_HTML
609 + "<html><body>\n"
610 + "<script>\n"
611 + "'use strict';\n"
612 + LOG_TITLE_FUNCTION
613 + "function test(a, b='default') {\n"
614 + " arguments[1] = 'hi';\n"
615 + " arguments[3] = 'you';\n"
616 + " log(arguments.length);\n"
617 + " log(arguments[0]);\n"
618 + " log(arguments[1]);\n"
619 + " log(arguments[2]);\n"
620 + " log(arguments[3]);\n"
621
622 + " log(a);\n"
623 + " log(b);\n"
624 + "}\n"
625 + "test('hello');\n"
626 + "test('hello', 'world');\n"
627 + "</script></body></html>";
628
629 loadPageVerifyTitle2(html);
630 }
631
632
633
634
635 @Test
636 @Alerts({"1", "[object Object]", "hi", "undefined", "you", "hello", "world"})
637 public void writableWithinFunctionDestructAdjustsArgument() throws Exception {
638 final String html = DOCTYPE_HTML
639 + "<html><body>\n"
640 + "<script>\n"
641 + LOG_TITLE_FUNCTION
642 + "function test({a, b}) {\n"
643 + " arguments[1] = 'hi';\n"
644 + " arguments[3] = 'you';\n"
645 + " log(arguments.length);\n"
646 + " log(arguments[0]);\n"
647 + " log(arguments[1]);\n"
648 + " log(arguments[2]);\n"
649 + " log(arguments[3]);\n"
650
651 + " log(a);\n"
652 + " log(b);\n"
653 + "}\n"
654 + "test({ a: 'hello', b: 'world'});\n"
655 + "</script></body></html>";
656
657 loadPageVerifyTitle2(html);
658 }
659
660
661
662
663 @Test
664 @Alerts({"1", "[object Object]", "hi", "undefined", "you", "hello", "world"})
665 public void writableWithinFunctionDestructAdjustsArgumentStrict() throws Exception {
666 final String html = DOCTYPE_HTML
667 + "<html><body>\n"
668 + "<script>\n"
669 + "'use strict';\n"
670 + LOG_TITLE_FUNCTION
671 + "function test({a, b}) {\n"
672 + " arguments[1] = 'hi';\n"
673 + " arguments[3] = 'you';\n"
674 + " log(arguments.length);\n"
675 + " log(arguments[0]);\n"
676 + " log(arguments[1]);\n"
677 + " log(arguments[2]);\n"
678 + " log(arguments[3]);\n"
679
680 + " log(a);\n"
681 + " log(b);\n"
682 + "}\n"
683 + "test({ a: 'hello', b: 'world'});\n"
684 + "</script></body></html>";
685
686 loadPageVerifyTitle2(html);
687 }
688
689
690
691
692 @Test
693 @Alerts("false")
694 public void argumentsEqualsFnArguments() throws Exception {
695 final String html = DOCTYPE_HTML
696 + "<html><body>\n"
697 + "<script>\n"
698 + LOG_TITLE_FUNCTION
699 + "function test() {\n"
700 + " log(arguments == test.arguments);\n"
701 + "}\n"
702 + "test('hello', 'world');\n"
703 + "</script></body></html>";
704
705 loadPageVerifyTitle2(html);
706 }
707
708
709
710
711 @Test
712 @Alerts("hi")
713 public void argumentsAsParameter() throws Exception {
714 final String html = DOCTYPE_HTML
715 + "<html><body>"
716 + "<script>\n"
717 + LOG_TITLE_FUNCTION
718 + "function test(arguments) {\n"
719 + " log(arguments);\n"
720 + "}\n"
721 + "test('hi');\n"
722 + "</script></body></html>";
723
724 loadPageVerifyTitle2(html);
725 }
726
727
728
729
730 @Test
731 @Disabled
732 @Alerts({})
733 public void argumentsAsParameterStrict() throws Exception {
734 final String html = DOCTYPE_HTML
735 + "<html><body>"
736 + "<script>\n"
737 + "'use strict';\n"
738 + LOG_TITLE_FUNCTION
739 + "function test(arguments) {\n"
740 + " log(arguments);\n"
741 + "}\n"
742 + "test('hi');\n"
743 + "</script></body></html>";
744
745 loadPageVerifyTitle2(html);
746 }
747
748
749
750
751 @Test
752 @Alerts({"function", "true", "undefined/undefined", "undefined/undefined", "true"})
753 public void argumentsCallee() throws Exception {
754 final String html = DOCTYPE_HTML
755 + "<html><body>"
756 + "<script>\n"
757 + LOG_TITLE_FUNCTION
758
759 + "function calleeFoo() { foo(); }\n"
760
761 + "function foo() {\n"
762 + " log(typeof arguments.callee);\n"
763 + " log(foo === arguments.callee);\n"
764
765 + " let desc = Object.getOwnPropertyDescriptor(arguments, 'callee');\n"
766 + " log(typeof desc.get + '/' + desc.get);\n"
767 + " log(typeof desc.set + '/' + desc.set);\n"
768 + " log(desc.get === desc.set);\n"
769 + "}\n"
770
771 + "calleeFoo();\n"
772 + "</script></body></html>";
773
774 loadPageVerifyTitle2(html);
775 }
776
777
778
779
780 @Test
781 @Alerts({"TypeError", "function/", "function/", "true"})
782 public void argumentsCalleeStrict() throws Exception {
783 final String html = DOCTYPE_HTML
784 + "<html><body>"
785 + "<script>\n"
786 + " 'use strict';\n"
787 + LOG_TITLE_FUNCTION
788
789 + "function calleeFoo() { foo(); }\n"
790
791 + "function foo() {\n"
792 + " try {\n"
793 + " log(arguments.callee);\n"
794 + " } catch(e) {\n"
795 + " logEx(e);\n"
796 + " }\n"
797 + " let desc = Object.getOwnPropertyDescriptor(arguments, 'callee');\n"
798 + " log(typeof desc.get + '/' + desc.get.name);\n"
799 + " log(typeof desc.set + '/' + desc.set.name);\n"
800 + " log(desc.get === desc.set);\n"
801 + "}\n"
802 + "calleeFoo();\n"
803 + "</script></body></html>";
804
805 loadPageVerifyTitle2(html);
806 }
807
808
809
810
811 @Test
812 @Alerts({"true", "true"})
813 public void argumentsCalleeDifferentFunctions() throws Exception {
814 final String html = DOCTYPE_HTML
815 + "<html><body>"
816 + "<script>\n"
817 + LOG_TITLE_FUNCTION
818 + "function foo1() {\n"
819 + " return Object.getOwnPropertyDescriptor(arguments, 'callee');\n"
820 + "}\n"
821 + "function foo2() {\n"
822 + " return Object.getOwnPropertyDescriptor(arguments, 'callee');\n"
823 + "}\n"
824 + "let desc1 = foo1();\n"
825 + "let desc2 = foo2();\n"
826 + "log(desc1.get === desc2.get);\n"
827 + "log(desc1.set === desc2.set);\n"
828 + "</script></body></html>";
829
830 loadPageVerifyTitle2(html);
831 }
832
833
834
835
836 @Test
837 @Alerts({"true", "true"})
838 public void argumentsCalleeDifferentFunctionsStrict() throws Exception {
839 final String html = DOCTYPE_HTML
840 + "<html><body>"
841 + "<script>\n"
842 + " 'use strict';\n"
843 + LOG_TITLE_FUNCTION
844 + "function foo1() {\n"
845 + " return Object.getOwnPropertyDescriptor(arguments, 'callee');\n"
846 + "}\n"
847 + "function foo2() {\n"
848 + " return Object.getOwnPropertyDescriptor(arguments, 'callee');\n"
849 + "}\n"
850 + "let desc1 = foo1();\n"
851 + "let desc2 = foo2();\n"
852 + "log(desc1.get === desc2.get);\n"
853 + "log(desc1.set === desc2.set);\n"
854 + "</script></body></html>";
855
856 loadPageVerifyTitle2(html);
857 }
858
859
860
861
862 @Test
863 @Alerts("undefined")
864 public void argumentsCaller() throws Exception {
865 final String html = DOCTYPE_HTML
866 + "<html>\n"
867 + "<body>\n"
868 + "<script>\n"
869 + LOG_TITLE_FUNCTION
870 + "function test() {\n"
871 + " log(arguments.caller);\n"
872 + "}\n"
873 + "test();\n"
874 + "</script>\n"
875 + "</body></html>";
876
877 loadPageVerifyTitle2(html);
878 }
879
880
881
882
883 @Test
884 @Alerts("undefined")
885 public void argumentsCallerStrict() throws Exception {
886 final String html = DOCTYPE_HTML
887 + "<html>\n"
888 + "<body>\n"
889 + "<script>\n"
890 + "'use strict';\n"
891 + LOG_TITLE_FUNCTION
892 + "function test() {\n"
893 + " log(arguments.caller);\n"
894 + "}\n"
895 + "test();\n"
896 + "</script>\n"
897 + "</body></html>";
898
899 loadPageVerifyTitle2(html);
900 }
901
902
903
904
905
906 @Test
907 @Alerts("0")
908 public void length() throws Exception {
909 final String html = DOCTYPE_HTML
910 + "<html><body>"
911 + "<script>\n"
912 + LOG_TITLE_FUNCTION
913 + "function test() {\n"
914 + " log(arguments.length);\n"
915 + "}\n"
916 + "test();\n"
917 + "</script></body></html>";
918
919 loadPageVerifyTitle2(html);
920 }
921
922
923
924
925
926 @Test
927 @Alerts("0")
928 public void lengthStrict() throws Exception {
929 final String html = DOCTYPE_HTML
930 + "<html><body>"
931 + "<script>\n"
932 + "'use strict';\n"
933 + LOG_TITLE_FUNCTION
934 + "function test() {\n"
935 + " log(arguments.length);\n"
936 + "}\n"
937 + "test();\n"
938 + "</script></body></html>";
939
940 loadPageVerifyTitle2(html);
941 }
942
943
944
945
946
947 @Test
948 @Alerts({"1", "undefined"})
949 public void argumentsWithUndefined() throws Exception {
950 final String html = DOCTYPE_HTML
951 + "<html><body>"
952 + "<script>\n"
953 + LOG_TITLE_FUNCTION
954 + "function test() {\n"
955 + " log(arguments.length);\n"
956 + " log(arguments[0]);\n"
957 + "}\n"
958 + "test(undefined);\n"
959 + "</script></body></html>";
960
961 loadPageVerifyTitle2(html);
962 }
963
964
965
966
967
968 @Test
969 @Alerts({"1", "null"})
970 public void argumentsWithNull() throws Exception {
971 final String html = DOCTYPE_HTML
972 + "<html><body>"
973 + "<script>\n"
974 + LOG_TITLE_FUNCTION
975 + "function test() {\n"
976 + " log(arguments.length);\n"
977 + " log(arguments[0]);\n"
978 + "}\n"
979 + "test(null);\n"
980 + "</script></body></html>";
981
982 loadPageVerifyTitle2(html);
983 }
984
985
986
987
988
989 @Test
990 @Alerts({"2", "true", "2", "undefined", "world"})
991 public void deleteArgumentsElement() throws Exception {
992 final String html = DOCTYPE_HTML
993 + "<html><body>"
994 + "<script>\n"
995 + LOG_TITLE_FUNCTION
996 + "function test() {\n"
997 + " log(arguments.length);\n"
998 + " log(delete arguments[0]);\n"
999 + " log(arguments.length);\n"
1000 + " log(arguments[0]);\n"
1001 + " log(arguments[1]);\n"
1002 + "}\n"
1003 + "test('hello', 'world');\n"
1004 + "</script></body></html>";
1005
1006 loadPageVerifyTitle2(html);
1007 }
1008
1009
1010
1011
1012
1013 @Test
1014 @Alerts({"2", "true", "2", "undefined", "world"})
1015 public void deleteArgumentsElementStrict() throws Exception {
1016 final String html = DOCTYPE_HTML
1017 + "<html><body>"
1018 + "<script>\n"
1019 + "'use strict';\n"
1020 + LOG_TITLE_FUNCTION
1021 + "function test() {\n"
1022 + " log(arguments.length);\n"
1023 + " log(delete arguments[0]);\n"
1024 + " log(arguments.length);\n"
1025 + " log(arguments[0]);\n"
1026 + " log(arguments[1]);\n"
1027 + "}\n"
1028 + "test('hello', 'world');\n"
1029 + "</script></body></html>";
1030
1031 loadPageVerifyTitle2(html);
1032 }
1033
1034
1035
1036
1037
1038 @Test
1039 @Alerts({"2", "5", "hello", "world", "undefined"})
1040 public void argumentsLengthWritable() throws Exception {
1041 final String html = DOCTYPE_HTML
1042 + "<html><body>"
1043 + "<script>\n"
1044 + LOG_TITLE_FUNCTION
1045 + "function test() {\n"
1046 + " log(arguments.length);\n"
1047 + " arguments.length = 5;\n"
1048 + " log(arguments.length);\n"
1049 + " log(arguments[0]);\n"
1050 + " log(arguments[1]);\n"
1051 + " log(arguments[2]);\n"
1052 + "}\n"
1053 + "test('hello', 'world');\n"
1054 + "</script></body></html>";
1055
1056 loadPageVerifyTitle2(html);
1057 }
1058
1059
1060
1061
1062
1063 @Test
1064 @Alerts({"2", "5", "hello", "world", "undefined"})
1065 public void argumentsLengthWritableStrict() throws Exception {
1066 final String html = DOCTYPE_HTML
1067 + "<html><body>"
1068 + "<script>\n"
1069 + "'use strict';\n"
1070 + LOG_TITLE_FUNCTION
1071 + "function test() {\n"
1072 + " log(arguments.length);\n"
1073 + " arguments.length = 5;\n"
1074 + " log(arguments.length);\n"
1075 + " log(arguments[0]);\n"
1076 + " log(arguments[1]);\n"
1077 + " log(arguments[2]);\n"
1078 + "}\n"
1079 + "test('hello', 'world');\n"
1080 + "</script></body></html>";
1081
1082 loadPageVerifyTitle2(html);
1083 }
1084
1085
1086
1087
1088
1089 @Test
1090 @Alerts("ReferenceError")
1091 public void argumentsInArrowFunction() throws Exception {
1092 final String html = DOCTYPE_HTML
1093 + "<html><body>"
1094 + "<script>\n"
1095 + LOG_TITLE_FUNCTION
1096 + "const test = () => {\n"
1097 + " try {\n"
1098 + " log(arguments.length);\n"
1099 + " } catch(e) {\n"
1100 + " logEx(e);\n"
1101 + " }\n"
1102 + "};\n"
1103 + "test('hello');\n"
1104 + "</script></body></html>";
1105
1106 loadPageVerifyTitle2(html);
1107 }
1108
1109
1110
1111
1112
1113 @Test
1114 @Alerts("ReferenceError")
1115 public void argumentsInArrowFunctionStrict() throws Exception {
1116 final String html = DOCTYPE_HTML
1117 + "<html><body>"
1118 + "<script>\n"
1119 + "'use strict';\n"
1120 + LOG_TITLE_FUNCTION
1121 + "const test = () => {\n"
1122 + " try {\n"
1123 + " log(arguments.length);\n"
1124 + " } catch(e) {\n"
1125 + " logEx(e);\n"
1126 + " }\n"
1127 + "};\n"
1128 + "test('hello');\n"
1129 + "</script></body></html>";
1130
1131 loadPageVerifyTitle2(html);
1132 }
1133
1134
1135
1136
1137
1138 @Test
1139 @Alerts("2")
1140 public void argumentsInNestedArrowFunction() throws Exception {
1141 final String html = DOCTYPE_HTML
1142 + "<html><body>"
1143 + "<script>\n"
1144 + LOG_TITLE_FUNCTION
1145 + "function test() {\n"
1146 + " const inner = () => {\n"
1147 + " log(arguments.length);\n"
1148 + " };\n"
1149 + " inner();\n"
1150 + "}\n"
1151 + "test('hello', 'world');\n"
1152 + "</script></body></html>";
1153
1154 loadPageVerifyTitle2(html);
1155 }
1156
1157
1158
1159
1160
1161 @Test
1162 @Alerts({"hello,world", "HELLO,WORLD"})
1163 public void argumentsArrayMethods() throws Exception {
1164 final String html = DOCTYPE_HTML
1165 + "<html><body>"
1166 + "<script>\n"
1167 + LOG_TITLE_FUNCTION
1168 + "function test() {\n"
1169 + " log(Array.prototype.join.call(arguments, ','));\n"
1170 + " let result = Array.prototype.map.call(arguments, x => x.toUpperCase());\n"
1171 + " log(result);\n"
1172 + "}\n"
1173 + "test('hello', 'world');\n"
1174 + "</script></body></html>";
1175
1176 loadPageVerifyTitle2(html);
1177 }
1178
1179
1180
1181
1182
1183 @Test
1184 @Alerts({"hello,world", "HELLO,WORLD"})
1185 public void argumentsArrayMethodsStric() throws Exception {
1186 final String html = DOCTYPE_HTML
1187 + "<html><body>"
1188 + "<script>\n"
1189 + "'use strict';\n"
1190 + LOG_TITLE_FUNCTION
1191 + "function test() {\n"
1192 + " log(Array.prototype.join.call(arguments, ','));\n"
1193 + " let result = Array.prototype.map.call(arguments, x => x.toUpperCase());\n"
1194 + " log(result);\n"
1195 + "}\n"
1196 + "test('hello', 'world');\n"
1197 + "</script></body></html>";
1198
1199 loadPageVerifyTitle2(html);
1200 }
1201
1202
1203
1204
1205
1206 @Test
1207 @Alerts({"false", "true"})
1208 public void argumentsNotArrayInstance() throws Exception {
1209 final String html = DOCTYPE_HTML
1210 + "<html><body>"
1211 + "<script>\n"
1212 + LOG_TITLE_FUNCTION
1213 + "function test() {\n"
1214 + " log(arguments instanceof Array);\n"
1215 + " log(arguments instanceof Object);\n"
1216 + "}\n"
1217 + "test();\n"
1218 + "</script></body></html>";
1219
1220 loadPageVerifyTitle2(html);
1221 }
1222
1223
1224
1225
1226
1227 @Test
1228 @Alerts({"false", "true"})
1229 public void argumentsNotArrayInstanceStrict() throws Exception {
1230 final String html = DOCTYPE_HTML
1231 + "<html><body>"
1232 + "<script>\n"
1233 + "'use strict';\n"
1234 + LOG_TITLE_FUNCTION
1235 + "function test() {\n"
1236 + " log(arguments instanceof Array);\n"
1237 + " log(arguments instanceof Object);\n"
1238 + "}\n"
1239 + "test();\n"
1240 + "</script></body></html>";
1241
1242 loadPageVerifyTitle2(html);
1243 }
1244
1245
1246
1247
1248
1249 @Test
1250 @Alerts("hello,world")
1251 public void argumentsIterator() throws Exception {
1252 final String html = DOCTYPE_HTML
1253 + "<html><body>"
1254 + "<script>\n"
1255 + LOG_TITLE_FUNCTION
1256 + "function test() {\n"
1257 + " let arr = [];\n"
1258 + " for (let arg of arguments) {\n"
1259 + " arr.push(arg);\n"
1260 + " }\n"
1261 + " log(arr);\n"
1262 + "}\n"
1263 + "test('hello', 'world');\n"
1264 + "</script></body></html>";
1265
1266 loadPageVerifyTitle2(html);
1267 }
1268
1269
1270
1271
1272
1273 @Test
1274 @Alerts("hello,world")
1275 public void argumentsIteratorStrict() throws Exception {
1276 final String html = DOCTYPE_HTML
1277 + "<html><body>"
1278 + "<script>\n"
1279 + "'use strict';\n"
1280 + LOG_TITLE_FUNCTION
1281 + "function test() {\n"
1282 + " let arr = [];\n"
1283 + " for (let arg of arguments) {\n"
1284 + " arr.push(arg);\n"
1285 + " }\n"
1286 + " log(arr);\n"
1287 + "}\n"
1288 + "test('hello', 'world');\n"
1289 + "</script></body></html>";
1290
1291 loadPageVerifyTitle2(html);
1292 }
1293
1294
1295
1296
1297
1298 @Test
1299 @Alerts("hello,world")
1300 public void argumentsSpreadOperator() throws Exception {
1301 final String html = DOCTYPE_HTML
1302 + "<html><body>"
1303 + "<script>\n"
1304 + LOG_TITLE_FUNCTION
1305 + "function test() {\n"
1306 + " let arr = [...arguments];\n"
1307 + " log(arr);\n"
1308 + "}\n"
1309 + "test('hello', 'world');\n"
1310 + "</script></body></html>";
1311
1312 loadPageVerifyTitle2(html);
1313 }
1314
1315
1316
1317
1318
1319 @Test
1320 @Alerts("hello,world")
1321 public void argumentsSpreadOperatorStrict() throws Exception {
1322 final String html = DOCTYPE_HTML
1323 + "<html><body>"
1324 + "<script>\n"
1325 + "'use strict';\n"
1326 + LOG_TITLE_FUNCTION
1327 + "function test() {\n"
1328 + " let arr = [...arguments];\n"
1329 + " log(arr);\n"
1330 + "}\n"
1331 + "test('hello', 'world');\n"
1332 + "</script></body></html>";
1333
1334 loadPageVerifyTitle2(html);
1335 }
1336
1337
1338
1339
1340
1341 @Test
1342 @Alerts({"3", "hello", "world", "!"})
1343 public void argumentsWithRestParameters() throws Exception {
1344 final String html = DOCTYPE_HTML
1345 + "<html><body>"
1346 + "<script>\n"
1347 + LOG_TITLE_FUNCTION
1348 + "function test(first, ...rest) {\n"
1349 + " log(arguments.length);\n"
1350 + " log(arguments[0]);\n"
1351 + " log(arguments[1]);\n"
1352 + " log(arguments[2]);\n"
1353 + "}\n"
1354 + "test('hello', 'world', '!');\n"
1355 + "</script></body></html>";
1356
1357 loadPageVerifyTitle2(html);
1358 }
1359
1360
1361
1362
1363
1364 @Test
1365 @Alerts({"3", "hello", "world", "!"})
1366 public void argumentsWithRestParametersStrict() throws Exception {
1367 final String html = DOCTYPE_HTML
1368 + "<html><body>"
1369 + "<script>\n"
1370 + "'use strict';\n"
1371 + LOG_TITLE_FUNCTION
1372 + "function test(first, ...rest) {\n"
1373 + " log(arguments.length);\n"
1374 + " log(arguments[0]);\n"
1375 + " log(arguments[1]);\n"
1376 + " log(arguments[2]);\n"
1377 + "}\n"
1378 + "test('hello', 'world', '!');\n"
1379 + "</script></body></html>";
1380
1381 loadPageVerifyTitle2(html);
1382 }
1383
1384
1385
1386
1387
1388 @Test
1389 @Alerts({"1", "hello", "undefined"})
1390 public void argumentsWithDefaultParameters() throws Exception {
1391 final String html = DOCTYPE_HTML
1392 + "<html><body>"
1393 + "<script>\n"
1394 + LOG_TITLE_FUNCTION
1395 + "function test(x, y = 'default') {\n"
1396 + " log(arguments.length);\n"
1397 + " log(arguments[0]);\n"
1398 + " log(arguments[1]);\n"
1399 + "}\n"
1400 + "test('hello');\n"
1401 + "</script></body></html>";
1402
1403 loadPageVerifyTitle2(html);
1404 }
1405
1406
1407
1408
1409
1410 @Test
1411 @Alerts({"1", "hello", "undefined"})
1412 public void argumentsWithDefaultParametersStrict() throws Exception {
1413 final String html = DOCTYPE_HTML
1414 + "<html><body>"
1415 + "<script>\n"
1416 + "'use strict';\n"
1417 + LOG_TITLE_FUNCTION
1418 + "function test(x, y = 'default') {\n"
1419 + " log(arguments.length);\n"
1420 + " log(arguments[0]);\n"
1421 + " log(arguments[1]);\n"
1422 + "}\n"
1423 + "test('hello');\n"
1424 + "</script></body></html>";
1425
1426 loadPageVerifyTitle2(html);
1427 }
1428
1429
1430
1431
1432
1433 @Test
1434 @Alerts("2")
1435 public void argumentsInEval() throws Exception {
1436 final String html = DOCTYPE_HTML
1437 + "<html><body>"
1438 + "<script>\n"
1439 + LOG_TITLE_FUNCTION
1440 + "function test() {\n"
1441 + " eval('log(arguments.length)');\n"
1442 + "}\n"
1443 + "test('hello', 'world');\n"
1444 + "</script></body></html>";
1445
1446 loadPageVerifyTitle2(html);
1447 }
1448
1449
1450
1451
1452
1453 @Test
1454 @Alerts("2")
1455 public void argumentsInEvalStrict() throws Exception {
1456 final String html = DOCTYPE_HTML
1457 + "<html><body>"
1458 + "<script>\n"
1459 + "'use strict';\n"
1460 + LOG_TITLE_FUNCTION
1461 + "function test() {\n"
1462 + " eval('log(arguments.length)');\n"
1463 + "}\n"
1464 + "test('hello', 'world');\n"
1465 + "</script></body></html>";
1466
1467 loadPageVerifyTitle2(html);
1468 }
1469
1470
1471
1472
1473
1474 @Test
1475 @Alerts("0,1")
1476 public void argumentsObjectKeys() throws Exception {
1477 final String html = DOCTYPE_HTML
1478 + "<html><body>"
1479 + "<script>\n"
1480 + LOG_TITLE_FUNCTION
1481 + "function test() {\n"
1482 + " log(Object.keys(arguments));\n"
1483 + "}\n"
1484 + "test('hello', 'world');\n"
1485 + "</script></body></html>";
1486
1487 loadPageVerifyTitle2(html);
1488 }
1489
1490
1491
1492
1493
1494 @Test
1495 @Alerts("0,1")
1496 public void argumentsObjectKeysStrict() throws Exception {
1497 final String html = DOCTYPE_HTML
1498 + "<html><body>"
1499 + "<script>\n"
1500 + "'use strict';\n"
1501 + LOG_TITLE_FUNCTION
1502 + "function test() {\n"
1503 + " log(Object.keys(arguments));\n"
1504 + "}\n"
1505 + "test('hello', 'world');\n"
1506 + "</script></body></html>";
1507
1508 loadPageVerifyTitle2(html);
1509 }
1510
1511
1512
1513
1514
1515 @Test
1516 @Alerts("{\"0\":\"hello\",\"1\":\"world\"}")
1517 public void argumentsJSONStringify() throws Exception {
1518 final String html = DOCTYPE_HTML
1519 + "<html><body>"
1520 + "<script>\n"
1521 + LOG_TITLE_FUNCTION
1522 + "function test() {\n"
1523 + " log(JSON.stringify(arguments));\n"
1524 + "}\n"
1525 + "test('hello', 'world');\n"
1526 + "</script></body></html>";
1527
1528 loadPageVerifyTitle2(html);
1529 }
1530
1531
1532
1533
1534
1535 @Test
1536 @Alerts("{\"0\":\"hello\",\"1\":\"world\"}")
1537 public void argumentsJSONStringifyStrict() throws Exception {
1538 final String html = DOCTYPE_HTML
1539 + "<html><body>"
1540 + "<script>\n"
1541 + "'use strict';\n"
1542 + LOG_TITLE_FUNCTION
1543 + "function test() {\n"
1544 + " log(JSON.stringify(arguments));\n"
1545 + "}\n"
1546 + "test('hello', 'world');\n"
1547 + "</script></body></html>";
1548
1549 loadPageVerifyTitle2(html);
1550 }
1551
1552
1553
1554
1555
1556 @Test
1557 @Alerts("2")
1558 public void argumentsInConstructor() throws Exception {
1559 final String html = DOCTYPE_HTML
1560 + "<html><body>"
1561 + "<script>\n"
1562 + LOG_TITLE_FUNCTION
1563 + "function MyClass() {\n"
1564 + " log(arguments.length);\n"
1565 + "}\n"
1566 + "new MyClass('hello', 'world');\n"
1567 + "</script></body></html>";
1568
1569 loadPageVerifyTitle2(html);
1570 }
1571
1572
1573
1574
1575
1576 @Test
1577 @Alerts("2")
1578 public void argumentsInConstructorStrict() throws Exception {
1579 final String html = DOCTYPE_HTML
1580 + "<html><body>"
1581 + "<script>\n"
1582 + "'use strict';\n"
1583 + LOG_TITLE_FUNCTION
1584 + "function MyClass() {\n"
1585 + " log(arguments.length);\n"
1586 + "}\n"
1587 + "new MyClass('hello', 'world');\n"
1588 + "</script></body></html>";
1589
1590 loadPageVerifyTitle2(html);
1591 }
1592
1593
1594
1595
1596
1597 @Test
1598 @Disabled
1599 @Alerts("2")
1600 public void argumentsInClassMethod() throws Exception {
1601 final String html = DOCTYPE_HTML
1602 + "<html><body>"
1603 + "<script>\n"
1604 + LOG_TITLE_FUNCTION
1605 + "class MyClass {\n"
1606 + " method() {\n"
1607 + " log(arguments.length);\n"
1608 + " }\n"
1609 + "}\n"
1610 + "new MyClass().method('hello', 'world');\n"
1611 + "</script></body></html>";
1612
1613 loadPageVerifyTitle2(html);
1614 }
1615
1616
1617
1618
1619
1620 @Test
1621 @Alerts("[object Arguments]")
1622 public void argumentsToString() throws Exception {
1623 final String html = DOCTYPE_HTML
1624 + "<html><body>"
1625 + "<script>\n"
1626 + LOG_TITLE_FUNCTION
1627 + "function test() {\n"
1628 + " log(Object.prototype.toString.call(arguments));\n"
1629 + "}\n"
1630 + "test();\n"
1631 + "</script></body></html>";
1632
1633 loadPageVerifyTitle2(html);
1634 }
1635
1636
1637
1638
1639
1640 @Test
1641 @Alerts("[object Arguments]")
1642 public void argumentsToStringStrict() throws Exception {
1643 final String html = DOCTYPE_HTML
1644 + "<html><body>"
1645 + "<script>\n"
1646 + "'use strict';\n"
1647 + LOG_TITLE_FUNCTION
1648 + "function test() {\n"
1649 + " log(Object.prototype.toString.call(arguments));\n"
1650 + "}\n"
1651 + "test();\n"
1652 + "</script></body></html>";
1653
1654 loadPageVerifyTitle2(html);
1655 }
1656 }