Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: test/mjsunit/harmony/iterator-close.js

Issue 2096933002: Remove all harmony runtime flags which shipped in M51 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/instanceof-es6.js ('k') | test/mjsunit/harmony/promise-species.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --harmony-iterator-close
6
7
8 function* g() { yield 42; return 88 };
9
10
11 // Return method is "undefined".
12 {
13 g.prototype.return = null;
14
15
16 assertEquals(undefined, (() => {
17 for (var x of g()) { break; }
18 })());
19
20 assertEquals(undefined, (() => {
21 for (let x of g()) { break; }
22 })());
23
24 assertEquals(undefined, (() => {
25 for (const x of g()) { break; }
26 })());
27
28 assertEquals(undefined, (() => {
29 for (x of g()) { break; }
30 })());
31
32
33 assertThrowsEquals(() => {
34 for (var x of g()) { throw 42; }
35 }, 42);
36
37 assertThrowsEquals(() => {
38 for (let x of g()) { throw 42; }
39 }, 42);
40
41 assertThrowsEquals(() => {
42 for (const x of g()) { throw 42; }
43 }, 42);
44
45 assertThrowsEquals(() => {
46 for (x of g()) { throw 42; }
47 }, 42);
48
49
50 assertEquals(42, (() => {
51 for (var x of g()) { return 42; }
52 })());
53
54 assertEquals(42, (() => {
55 for (let x of g()) { return 42; }
56 })());
57
58 assertEquals(42, (() => {
59 for (const x of g()) { return 42; }
60 })());
61
62 assertEquals(42, (() => {
63 for (x of g()) { return 42; }
64 })());
65
66
67 assertEquals(42, eval('for (var x of g()) { x; }'));
68
69 assertEquals(42, eval('for (let x of g()) { x; }'));
70
71 assertEquals(42, eval('for (const x of g()) { x; }'));
72
73 assertEquals(42, eval('for (x of g()) { x; }'));
74
75
76 assertEquals(42, (() => {
77 var [x] = g(); return x;
78 })());
79
80 assertEquals(42, (() => {
81 let [x] = g(); return x;
82 })());
83
84 assertEquals(42, (() => {
85 const [x] = g(); return x;
86 })());
87
88 assertEquals(42, (() => {
89 [x] = g(); return x;
90 })());
91
92 assertEquals(42,
93 (([x]) => x)(g())
94 );
95 }
96
97
98 // Return method is not callable.
99 {
100 g.prototype.return = 666;
101
102
103 assertThrows(() => {
104 for (var x of g()) { break; }
105 }, TypeError);
106
107 assertThrows(() => {
108 for (let x of g()) { break; }
109 }, TypeError);
110
111 assertThrows(() => {
112 for (const x of g()) { break; }
113 }, TypeError);
114
115 assertThrows(() => {
116 for (x of g()) { break; }
117 }, TypeError);
118
119
120 assertThrows(() => {
121 for (var x of g()) { throw 666; }
122 }, TypeError);
123
124 assertThrows(() => {
125 for (let x of g()) { throw 666; }
126 }, TypeError);
127
128 assertThrows(() => {
129 for (const x of g()) { throw 666; }
130 }, TypeError);
131
132 assertThrows(() => {
133 for (x of g()) { throw 666; }
134 }, TypeError);
135
136
137 assertThrows(() => {
138 for (var x of g()) { return 666; }
139 }, TypeError);
140
141 assertThrows(() => {
142 for (let x of g()) { return 666; }
143 }, TypeError);
144
145 assertThrows(() => {
146 for (const x of g()) { return 666; }
147 }, TypeError);
148
149 assertThrows(() => {
150 for (x of g()) { return 666; }
151 }, TypeError);
152
153
154 assertEquals(42, eval('for (var x of g()) { x; }'));
155
156 assertEquals(42, eval('for (let x of g()) { x; }'));
157
158 assertEquals(42, eval('for (const x of g()) { x; }'));
159
160 assertEquals(42, eval('for (x of g()) { x; }'));
161
162
163 assertThrows(() => {
164 var [x] = g(); return x;
165 }, TypeError);
166
167 assertThrows(() => {
168 let [x] = g(); return x;
169 }, TypeError);
170
171 assertThrows(() => {
172 const [x] = g(); return x;
173 }, TypeError);
174
175 assertThrows(() => {
176 [x] = g(); return x;
177 }, TypeError);
178
179 assertThrows(() => {
180 (([x]) => x)(g());
181 }, TypeError);
182 }
183
184
185 // Return method does not return an object.
186 {
187 g.prototype.return = () => 666;
188
189
190 assertThrows(() => {
191 for (var x of g()) { break; }
192 }, TypeError);
193
194 assertThrows(() => {
195 for (let x of g()) { break; }
196 }, TypeError);
197
198 assertThrows(() => {
199 for (const x of g()) { break; }
200 }, TypeError);
201
202 assertThrows(() => {
203 for (x of g()) { break; }
204 }, TypeError);
205
206
207 // Throw from the body of a for loop 'wins' vs throw
208 // originating from a bad 'return' value.
209
210 assertThrowsEquals(() => {
211 for (var x of g()) { throw 666; }
212 }, 666);
213
214 assertThrowsEquals(() => {
215 for (let x of g()) { throw 666; }
216 }, 666);
217
218 assertThrowsEquals(() => {
219 for (const x of g()) { throw 666; }
220 }, 666);
221
222 assertThrowsEquals(() => {
223 for (x of g()) { throw 666; }
224 }, 666);
225
226
227 assertThrows(() => {
228 for (var x of g()) { return 666; }
229 }, TypeError);
230
231 assertThrows(() => {
232 for (let x of g()) { return 666; }
233 }, TypeError);
234
235 assertThrows(() => {
236 for (const x of g()) { return 666; }
237 }, TypeError);
238
239 assertThrows(() => {
240 for (x of g()) { return 666; }
241 }, TypeError);
242
243
244 assertEquals(42, eval('for (var x of g()) { x; }'));
245
246 assertEquals(42, eval('for (let x of g()) { x; }'));
247
248 assertEquals(42, eval('for (const x of g()) { x; }'));
249
250 assertEquals(42, eval('for (x of g()) { x; }'));
251
252
253 assertThrows(() => {
254 var [x] = g(); return x;
255 }, TypeError);
256
257 assertThrows(() => {
258 let [x] = g(); return x;
259 }, TypeError);
260
261 assertThrows(() => {
262 const [x] = g(); return x;
263 }, TypeError);
264
265 assertThrows(() => {
266 [x] = g(); return x;
267 }, TypeError);
268
269 assertThrows(() => {
270 (([x]) => x)(g());
271 }, TypeError);
272 }
273
274
275 // Return method returns an object.
276 {
277 let log = [];
278 g.prototype.return = (...args) => { log.push(args); return {} };
279
280
281 log = [];
282 for (var x of g()) { break; }
283 assertEquals([[]], log);
284
285 log = [];
286 for (let x of g()) { break; }
287 assertEquals([[]], log);
288
289 log = [];
290 for (const x of g()) { break; }
291 assertEquals([[]], log);
292
293 log = [];
294 for (x of g()) { break; }
295 assertEquals([[]], log);
296
297
298 log = [];
299 assertThrowsEquals(() => {
300 for (var x of g()) { throw 42; }
301 }, 42);
302 assertEquals([[]], log);
303
304 log = [];
305 assertThrowsEquals(() => {
306 for (let x of g()) { throw 42; }
307 }, 42);
308 assertEquals([[]], log);
309
310 log = [];
311 assertThrowsEquals(() => {
312 for (const x of g()) { throw 42; }
313 }, 42);
314 assertEquals([[]], log);
315
316 log = [];
317 assertThrowsEquals(() => {
318 for (x of g()) { throw 42; }
319 }, 42);
320 assertEquals([[]], log);
321
322
323 log = [];
324 assertEquals(42, (() => {
325 for (var x of g()) { return 42; }
326 })());
327 assertEquals([[]], log);
328
329 log = [];
330 assertEquals(42, (() => {
331 for (let x of g()) { return 42; }
332 })());
333 assertEquals([[]], log);
334
335 log = [];
336 assertEquals(42, (() => {
337 for (const x of g()) { return 42; }
338 })());
339 assertEquals([[]], log);
340
341 log = [];
342 assertEquals(42, (() => {
343 for (x of g()) { return 42; }
344 })());
345 assertEquals([[]], log);
346
347
348 log = [];
349 assertEquals(42, eval('for (var x of g()) { x; }'));
350 assertEquals([], log);
351
352 log = [];
353 assertEquals(42, eval('for (let x of g()) { x; }'));
354 assertEquals([], log);
355
356 log = [];
357 assertEquals(42, eval('for (const x of g()) { x; }'));
358 assertEquals([], log);
359
360 log = [];
361 assertEquals(42, eval('for (x of g()) { x; }'));
362 assertEquals([], log);
363
364
365 // Even if doing the assignment throws, still call return
366 log = [];
367 x = { set attr(_) { throw 1234; } };
368 assertThrowsEquals(() => {
369 for (x.attr of g()) { throw 456; }
370 }, 1234);
371 assertEquals([[]], log);
372
373
374 log = [];
375 assertEquals(42, (() => {
376 var [x] = g(); return x;
377 })());
378 assertEquals([[]], log);
379
380 log = [];
381 assertEquals(42, (() => {
382 let [x] = g(); return x;
383 })());
384 assertEquals([[]], log);
385
386 log = [];
387 assertEquals(42, (() => {
388 const [x] = g(); return x;
389 })());
390 assertEquals([[]], log);
391
392 log = [];
393 assertEquals(42, (() => {
394 [x] = g(); return x;
395 })());
396 assertEquals([[]], log);
397
398 log = []
399 assertEquals(42,
400 (([x]) => x)(g())
401 );
402 assertEquals([[]], log);
403
404
405 log = [];
406 assertEquals(42, (() => {
407 var [x,] = g(); return x;
408 })());
409 assertEquals([[]], log);
410
411 log = [];
412 assertEquals(42, (() => {
413 let [x,] = g(); return x;
414 })());
415 assertEquals([[]], log);
416
417 log = [];
418 assertEquals(42, (() => {
419 const [x,] = g(); return x;
420 })());
421 assertEquals([[]], log);
422
423 log = [];
424 assertEquals(42, (() => {
425 [x,] = g(); return x;
426 })());
427 assertEquals([[]], log);
428
429 log = []
430 assertEquals(42,
431 (([x,]) => x)(g())
432 );
433 assertEquals([[]], log);
434
435
436 log = [];
437 assertEquals(42, (() => {
438 var [x,,] = g(); return x;
439 })());
440 assertEquals([], log);
441
442 log = [];
443 assertEquals(42, (() => {
444 let [x,,] = g(); return x;
445 })());
446 assertEquals([], log);
447
448 log = [];
449 assertEquals(42, (() => {
450 const [x,,] = g(); return x;
451 })());
452 assertEquals([], log);
453
454 log = [];
455 assertEquals(42, (() => {
456 [x,,] = g(); return x;
457 })());
458 assertEquals([], log);
459
460 log = []
461 assertEquals(42,
462 (([x,,]) => x)(g())
463 );
464 assertEquals([], log);
465
466
467 log = [];
468 assertEquals([42, undefined], (() => {
469 var [x, y] = g(); return [x, y];
470 })());
471 assertEquals([], log);
472
473 log = [];
474 assertEquals([42, undefined], (() => {
475 let [x, y] = g(); return [x, y];
476 })());
477 assertEquals([], log);
478
479 log = [];
480 assertEquals([42, undefined], (() => {
481 const [x, y] = g(); return [x, y];
482 })());
483 assertEquals([], log);
484
485 log = [];
486 assertEquals([42, undefined], (() => {
487 [x, y] = g(); return [x, y];
488 })());
489 assertEquals([], log);
490
491 log = []
492 assertEquals([42, undefined],
493 (([x, y]) => [x, y])(g())
494 );
495 assertEquals([], log);
496
497
498 log = [];
499 assertEquals([42], (() => {
500 var [...x] = g(); return x;
501 })());
502 assertEquals([], log);
503
504 log = [];
505 assertEquals([42], (() => {
506 let [...x] = g(); return x;
507 })());
508 assertEquals([], log);
509
510 log = [];
511 assertEquals([42], (() => {
512 const [...x] = g(); return x;
513 })());
514 assertEquals([], log);
515
516 log = [];
517 assertEquals([42], (() => {
518 [...x] = g(); return x;
519 })());
520 assertEquals([], log);
521
522 log = []
523 assertEquals([42],
524 (([...x]) => x)(g())
525 );
526 assertEquals([], log);
527
528
529 log = [];
530 assertEquals([42, []], (() => {
531 var [x, ...y] = g(); return [x, y];
532 })());
533 assertEquals([], log);
534
535 log = [];
536 assertEquals([42, []], (() => {
537 let [x, ...y] = g(); return [x, y];
538 })());
539 assertEquals([], log);
540
541 log = [];
542 assertEquals([42, []], (() => {
543 const [x, ...y] = g(); return [x, y];
544 })());
545 assertEquals([], log);
546
547 log = [];
548 assertEquals([42, []], (() => {
549 [x, ...y] = g(); return [x, y];
550 })());
551 assertEquals([], log);
552
553 log = []
554 assertEquals([42, []],
555 (([x, ...y]) => [x, y])(g())
556 );
557 assertEquals([], log);
558
559
560 log = [];
561 assertEquals([], (() => {
562 var [] = g(); return [];
563 })());
564 assertEquals([[]], log);
565
566 log = [];
567 assertEquals([], (() => {
568 let [] = g(); return [];
569 })());
570 assertEquals([[]], log);
571
572 log = [];
573 assertEquals([], (() => {
574 const [] = g(); return [];
575 })());
576 assertEquals([[]], log);
577
578 log = [];
579 assertEquals([], (() => {
580 [] = g(); return [];
581 })());
582 assertEquals([[]], log);
583
584 log = []
585 assertEquals([],
586 (([]) => [])(g())
587 );
588 assertEquals([[]], log);
589
590
591 log = [];
592 assertEquals([], (() => {
593 var [...[]] = g(); return [];
594 })());
595 assertEquals([], log);
596
597 log = [];
598 assertEquals([], (() => {
599 let [...[]] = g(); return [];
600 })());
601 assertEquals([], log);
602
603 log = [];
604 assertEquals([], (() => {
605 const [...[]] = g(); return [];
606 })());
607 assertEquals([], log);
608
609 log = [];
610 assertEquals([], (() => {
611 [...[]] = g(); return [];
612 })());
613 assertEquals([], log);
614
615 log = []
616 assertEquals([],
617 (([...[]]) => [])(g())
618 );
619 assertEquals([], log);
620
621
622 log = [];
623 assertEquals([42], (() => {
624 var [...[x]] = g(); return [x];
625 })());
626 assertEquals([], log);
627
628 log = [];
629 assertEquals([42], (() => {
630 let [...[x]] = g(); return [x];
631 })());
632 assertEquals([], log);
633
634 log = [];
635 assertEquals([42], (() => {
636 const [...[x]] = g(); return [x];
637 })());
638 assertEquals([], log);
639
640 log = [];
641 assertEquals([42], (() => {
642 [...[x]] = g(); return [x];
643 })());
644 assertEquals([], log);
645
646 log = []
647 assertEquals([42],
648 (([...[x]]) => [x])(g())
649 );
650 assertEquals([], log);
651
652
653 log = [];
654 assertEquals([42, undefined], (() => {
655 var [...[x, y]] = g(); return [x, y];
656 })());
657 assertEquals([], log);
658
659 log = [];
660 assertEquals([42, undefined], (() => {
661 let [...[x, y]] = g(); return [x, y];
662 })());
663 assertEquals([], log);
664
665 log = [];
666 assertEquals([42, undefined], (() => {
667 const [...[x, y]] = g(); return [x, y];
668 })());
669 assertEquals([], log);
670
671 log = [];
672 assertEquals([42, undefined], (() => {
673 [...[x, y]] = g(); return [x, y];
674 })());
675 assertEquals([], log);
676
677 log = []
678 assertEquals([42, undefined],
679 (([...[x, y]]) => [x, y])(g())
680 );
681 assertEquals([], log);
682
683
684 log = []
685 assertThrowsEquals(() => {
686 let x = { set foo(_) { throw 666; } };
687 [x.foo] = g();
688 }, 666);
689 assertEquals([[]], log);
690
691
692 log = []
693 assertThrows(() => {
694 var [[]] = g();
695 }, TypeError);
696 assertEquals([[]], log);
697
698 log = []
699 assertThrows(() => {
700 let [[]] = g();
701 }, TypeError);
702 assertEquals([[]], log);
703
704 log = []
705 assertThrows(() => {
706 const [[]] = g();
707 }, TypeError);
708 assertEquals([[]], log);
709
710 log = []
711 assertThrows(() => {
712 [[]] = g();
713 }, TypeError);
714 assertEquals([[]], log);
715
716 log = []
717 assertThrows(() => {
718 (([[]]) => 0)(g());
719 }, TypeError);
720 assertEquals([[]], log);
721
722
723 log = []
724 assertThrows(() => {
725 var [...[[]]] = g();
726 }, TypeError);
727 assertEquals([], log);
728
729 log = []
730 assertThrows(() => {
731 let [...[[]]] = g();
732 }, TypeError);
733 assertEquals([], log);
734
735 log = []
736 assertThrows(() => {
737 const [...[[]]] = g();
738 }, TypeError);
739 assertEquals([], log);
740
741 log = []
742 assertThrows(() => {
743 [...[[]]] = g();
744 }, TypeError);
745 assertEquals([], log);
746
747 log = []
748 assertThrows(() => {
749 (([...[[]]]) => 0)(g());
750 }, TypeError);
751 assertEquals([], log);
752
753
754 {
755 let backup = Array.prototype[Symbol.iterator];
756 Array.prototype[Symbol.iterator] = () => g();
757
758
759 log = [];
760 assertDoesNotThrow(() => {
761 var [x, ...[y]] = [1, 2, 3]
762 });
763 assertEquals(log, [[]]);
764
765 log = [];
766 assertDoesNotThrow(() => {
767 let [x, ...[y]] = [1, 2, 3];
768 });
769 assertEquals(log, [[]]);
770
771 log = [];
772 assertDoesNotThrow(() => {
773 const [x, ...[y]] = [1, 2, 3];
774 });
775 assertEquals(log, [[]]);
776
777 log = [];
778 assertDoesNotThrow(() => {
779 (([x, ...[y]]) => {})([1, 2, 3]);
780 });
781 assertEquals(log, [[]]);
782
783
784 log = [];
785 assertThrows(() => {
786 var [x, ...[[]]] = [1, 2, 3];
787 }, TypeError);
788 assertEquals(log, [[]]);
789
790 log = [];
791 assertThrows(() => {
792 let [x, ...[[]]] = [1, 2, 3];
793 }, TypeError);
794 assertEquals(log, [[]]);
795
796 log = [];
797 assertThrows(() => {
798 const [x, ...[[]]] = [1, 2, 3];
799 }, TypeError);
800 assertEquals(log, [[]]);
801
802 log = [];
803 assertThrows(() => {
804 (([x, ...[[]]]) => {})([1, 2, 3]);
805 }, TypeError);
806 assertEquals(log, [[]]);
807
808
809 log = [];
810 assertDoesNotThrow(() => {
811 var [x, ...[...y]] = [1, 2, 3];
812 });
813 assertEquals(log, []);
814
815 log = [];
816 assertDoesNotThrow(() => {
817 let [x, ...[...y]] = [1, 2, 3];
818 });
819 assertEquals(log, []);
820
821 log = [];
822 assertDoesNotThrow(() => {
823 const [x, ...[...y]] = [1, 2, 3];
824 });
825 assertEquals(log, []);
826
827 log = [];
828 assertDoesNotThrow(() => {
829 (([x, ...[...y]]) => {})([1, 2, 3]);
830 });
831 assertEquals(log, []);
832
833
834 Array.prototype[Symbol.iterator] = backup;
835 }
836 }
837
838
839 // Return method throws.
840 {
841 let log = [];
842 g.prototype.return = (...args) => { log.push(args); throw 23 };
843
844
845 log = [];
846 assertThrowsEquals(() => {
847 for (var x of g()) { break; }
848 }, 23);
849 assertEquals([[]], log);
850
851 log = [];
852 assertThrowsEquals(() => {
853 for (let x of g()) { break; }
854 }, 23);
855 assertEquals([[]], log);
856
857 log = [];
858 assertThrowsEquals(() => {
859 for (const x of g()) { break; }
860 }, 23);
861 assertEquals([[]], log);
862
863 log = [];
864 assertThrowsEquals(() => {
865 for (x of g()) { break; }
866 }, 23);
867 assertEquals([[]], log);
868
869
870 log = [];
871 assertThrowsEquals(() => {
872 for (var x of g()) { throw 42; }
873 }, 42);
874 assertEquals([[]], log);
875
876 log = [];
877 assertThrowsEquals(() => {
878 for (let x of g()) { throw 42; }
879 }, 42);
880 assertEquals([[]], log);
881
882 log = [];
883 assertThrowsEquals(() => {
884 for (const x of g()) { throw 42; }
885 }, 42);
886 assertEquals([[]], log);
887
888 log = [];
889 assertThrowsEquals(() => {
890 for (x of g()) { throw 42; }
891 }, 42);
892 assertEquals([[]], log);
893
894
895 log = [];
896 assertThrowsEquals(() => {
897 for (var x of g()) { return 42; }
898 }, 23);
899 assertEquals([[]], log);
900
901 log = [];
902 assertThrowsEquals(() => {
903 for (let x of g()) { return 42; }
904 }, 23);
905 assertEquals([[]], log);
906
907 log = [];
908 assertThrowsEquals(() => {
909 for (const x of g()) { return 42; }
910 }, 23);
911 assertEquals([[]], log);
912
913 log = [];
914 assertThrowsEquals(() => {
915 for (x of g()) { return 42; }
916 }, 23);
917 assertEquals([[]], log);
918
919
920 log = [];
921 assertEquals(42, eval('for (var x of g()) { x; }'));
922 assertEquals([], log);
923
924 log = [];
925 assertEquals(42, eval('for (let x of g()) { x; }'));
926 assertEquals([], log);
927
928 log = [];
929 assertEquals(42, eval('for (const x of g()) { x; }'));
930 assertEquals([], log);
931
932 log = [];
933 assertEquals(42, eval('for (x of g()) { x; }'));
934 assertEquals([], log);
935
936
937 log = [];
938 assertThrowsEquals(() => {
939 var [x] = g(); return x;
940 }, 23);
941 assertEquals([[]], log);
942
943 log = [];
944 assertThrowsEquals(() => {
945 let [x] = g(); return x;
946 }, 23);
947 assertEquals([[]], log);
948
949 log = [];
950 assertThrowsEquals(() => {
951 const [x] = g(); return x;
952 }, 23);
953 assertEquals([[]], log);
954
955 log = [];
956 assertThrowsEquals(() => {
957 [x] = g(); return x;
958 }, 23);
959 assertEquals([[]], log);
960
961 log = [];
962 assertThrowsEquals(() => {
963 (([x]) => x)(g())
964 }, 23);
965 assertEquals([[]], log);
966 }
967
968
969 // Next method throws.
970 {
971 g.prototype.next = () => { throw 666; };
972 g.prototype.return = () => { assertUnreachable() };
973
974
975 assertThrowsEquals(() => {
976 for (var x of g()) {}
977 }, 666);
978
979 assertThrowsEquals(() => {
980 for (let x of g()) {}
981 }, 666);
982
983 assertThrowsEquals(() => {
984 for (const x of g()) {}
985 }, 666);
986
987 assertThrowsEquals(() => {
988 for (x of g()) {}
989 }, 666);
990
991 assertThrowsEquals(() => {
992 var [x] = g();
993 }, 666);
994
995 assertThrowsEquals(() => {
996 let [x] = g();
997 }, 666);
998
999 assertThrowsEquals(() => {
1000 const [x] = g();
1001 }, 666);
1002
1003 assertThrowsEquals(() => {
1004 [x] = g();
1005 }, 666);
1006
1007 assertThrowsEquals(() => {
1008 (([x]) => x)(g());
1009 }, 666);
1010
1011 assertThrowsEquals(() => {
1012 var [...x] = g();
1013 }, 666);
1014
1015 assertThrowsEquals(() => {
1016 let [...x] = g();
1017 }, 666);
1018
1019 assertThrowsEquals(() => {
1020 const [...x] = g();
1021 }, 666);
1022
1023 assertThrowsEquals(() => {
1024 [...x] = g();
1025 }, 666);
1026
1027 assertThrowsEquals(() => {
1028 (([...x]) => x)(g());
1029 }, 666);
1030 }
1031
1032
1033 // Value throws.
1034 {
1035 g.prototype.next = () => ({get value() {throw 666}});
1036 g.prototype.return = () => { assertUnreachable() };
1037
1038
1039 assertThrowsEquals(() => {
1040 for (var x of g()) {}
1041 }, 666);
1042
1043 assertThrowsEquals(() => {
1044 for (let x of g()) {}
1045 }, 666);
1046
1047 assertThrowsEquals(() => {
1048 for (const x of g()) {}
1049 }, 666);
1050
1051 assertThrowsEquals(() => {
1052 for (x of g()) {}
1053 }, 666);
1054
1055 assertThrowsEquals(() => {
1056 var [x] = g();
1057 }, 666);
1058
1059 assertThrowsEquals(() => {
1060 let [x] = g();
1061 }, 666);
1062
1063 assertThrowsEquals(() => {
1064 const [x] = g();
1065 }, 666);
1066
1067 assertThrowsEquals(() => {
1068 [x] = g();
1069 }, 666);
1070
1071 assertThrowsEquals(() => {
1072 (([x]) => x)(g());
1073 }, 666);
1074
1075 assertThrowsEquals(() => {
1076 var [...x] = g();
1077 }, 666);
1078
1079 assertThrowsEquals(() => {
1080 let [...x] = g();
1081 }, 666);
1082
1083 assertThrowsEquals(() => {
1084 const [...x] = g();
1085 }, 666);
1086
1087 assertThrowsEquals(() => {
1088 [...x] = g();
1089 }, 666);
1090
1091 assertThrowsEquals(() => {
1092 (([...x]) => x)(g());
1093 }, 666);
1094 }
1095
1096
1097 // Done throws.
1098 {
1099 g.prototype.next = () => ({get done() {throw 666}});
1100 g.prototype.return = () => { assertUnreachable() };
1101
1102
1103 assertThrowsEquals(() => {
1104 for (var x of g()) {}
1105 }, 666);
1106
1107 assertThrowsEquals(() => {
1108 for (let x of g()) {}
1109 }, 666);
1110
1111 assertThrowsEquals(() => {
1112 for (const x of g()) {}
1113 }, 666);
1114
1115 assertThrowsEquals(() => {
1116 for (x of g()) {}
1117 }, 666);
1118
1119 assertThrowsEquals(() => {
1120 var [x] = g();
1121 }, 666);
1122
1123 assertThrowsEquals(() => {
1124 let [x] = g();
1125 }, 666);
1126
1127 assertThrowsEquals(() => {
1128 const [x] = g();
1129 }, 666);
1130
1131 assertThrowsEquals(() => {
1132 [x] = g();
1133 }, 666);
1134
1135 assertThrowsEquals(() => {
1136 (([x]) => x)(g());
1137 }, 666);
1138
1139 assertThrowsEquals(() => {
1140 var [...x] = g();
1141 }, 666);
1142
1143 assertThrowsEquals(() => {
1144 let [...x] = g();
1145 }, 666);
1146
1147 assertThrowsEquals(() => {
1148 const [...x] = g();
1149 }, 666);
1150
1151 assertThrowsEquals(() => {
1152 [...x] = g();
1153 }, 666);
1154
1155 assertThrowsEquals(() => {
1156 (([...x]) => x)(g());
1157 }, 666);
1158 }
1159
1160
1161 // Nested loops.
1162 {
1163 function* g1() { yield 1; yield 2; throw 3; }
1164 function* g2() { yield -1; yield -2; throw -3; }
1165
1166 assertDoesNotThrow(() => {
1167 for (let x of g1()) {
1168 for (let y of g2()) {
1169 if (y == -2) break;
1170 }
1171 if (x == 2) break;
1172 }
1173 }, -3);
1174
1175 assertThrowsEquals(() => {
1176 for (let x of g1()) {
1177 for (let y of g2()) {
1178 }
1179 }
1180 }, -3);
1181
1182 assertThrowsEquals(() => {
1183 for (let x of g1()) {
1184 for (let y of g2()) {
1185 if (y == -2) break;
1186 }
1187 }
1188 }, 3);
1189
1190 assertDoesNotThrow(() => {
1191 l: for (let x of g1()) {
1192 for (let y of g2()) {
1193 if (y == -2) break l;
1194 }
1195 }
1196 });
1197
1198 assertThrowsEquals(() => {
1199 for (let x of g1()) {
1200 for (let y of g2()) {
1201 throw 4;
1202 }
1203 }
1204 }, 4);
1205
1206 assertThrowsEquals(() => {
1207 for (let x of g1()) {
1208 for (let y of g2()) {
1209 if (y == -2) throw 4;
1210 }
1211 }
1212 }, 4);
1213
1214 let log = [];
1215 g1.prototype.return = () => { log.push(1); throw 5 };
1216 g2.prototype.return = () => { log.push(2); throw -5 };
1217
1218 log = [];
1219 assertThrowsEquals(() => {
1220 for (let x of g1()) {
1221 for (let y of g2()) {
1222 if (y == -2) break;
1223 }
1224 if (x == 2) break;
1225 }
1226 }, -5);
1227 assertEquals([2, 1], log);
1228
1229 log = [];
1230 assertThrowsEquals(() => {
1231 for (let x of g1()) {
1232 for (let y of g2()) {
1233 }
1234 }
1235 }, -3);
1236 assertEquals([1], log);
1237
1238 log = [];
1239 assertThrowsEquals(() => {
1240 for (let x of g1()) {
1241 for (let y of g2()) {
1242 if (y == -2) break;
1243 }
1244 }
1245 }, -5);
1246 assertEquals([2, 1], log);
1247
1248 log = [];
1249 assertThrowsEquals(() => {
1250 l: for (let x of g1()) {
1251 for (let y of g2()) {
1252 if (y == -2) break l;
1253 }
1254 }
1255 }, -5);
1256 assertEquals([2, 1], log);
1257
1258 log = [];
1259 assertThrowsEquals(() => {
1260 for (let x of g1()) {
1261 for (let y of g2()) {
1262 throw 4;
1263 }
1264 }
1265 }, 4);
1266 assertEquals([2, 1], log);
1267
1268 log = [];
1269 assertThrowsEquals(() => {
1270 for (let x of g1()) {
1271 for (let y of g2()) {
1272 if (y == -2) throw 4;
1273 }
1274 }
1275 }, 4);
1276 assertEquals([2, 1], log);
1277
1278 log = [];
1279 assertThrowsEquals(() => {
1280 for (let x of g1()) {
1281 try {
1282 for (let y of g2()) {
1283 }
1284 } catch (_) {}
1285 }
1286 }, 3);
1287 assertEquals([], log);
1288
1289 log = [];
1290 assertThrowsEquals(() => {
1291 for (let x of g1()) {
1292 try {
1293 for (let y of g2()) {
1294 }
1295 } catch (_) {}
1296 if (x == 2) break;
1297 }
1298 }, 5);
1299 assertEquals([1], log);
1300 }
1301
1302
1303 // yield*, argument's return method is "undefined".
1304 function TestYieldStarWithoutReturn(get_iterable) {
1305 assertTrue(get_iterable().return == undefined);
1306
1307 function* g() { yield* get_iterable() }
1308
1309 {
1310 let gen = g();
1311 assertEquals({value: 1, done: false}, gen.next());
1312 assertEquals({value: undefined, done: true}, gen.return());
1313 }
1314
1315 assertEquals(42, (() => {
1316 for (let x of g()) break;
1317 return 42;
1318 })());
1319
1320 assertEquals(42, (() => {
1321 for (let x of g()) return 42;
1322 })());
1323
1324 assertThrowsEquals(() => {
1325 for (let x of g()) throw 42;
1326 }, 42);
1327 }
1328 {
1329 let get_iterable1 = () => [1, 2];
1330 let get_iterable2 = function*() { yield 1; yield 2 };
1331 get_iterable2.prototype.return = null;
1332 TestYieldStarWithoutReturn(get_iterable1);
1333 TestYieldStarWithoutReturn(get_iterable2);
1334 }
1335
1336
1337 // yield*, argument's return method is defined.
1338 {
1339 let get_iterable = function*() { yield 1; yield 2 };
1340 const obj = {};
1341 get_iterable.prototype.return = (...args) => obj;
1342
1343 function* g() { yield* get_iterable() }
1344
1345 {
1346 let gen = g();
1347 assertEquals({value: 1, done: false}, gen.next());
1348 assertSame(obj, gen.return());
1349 assertSame(obj, gen.return());
1350 assertSame(obj, gen.return());
1351 assertEquals({value: 2, done: false}, gen.next());
1352 assertSame(obj, gen.return());
1353 assertSame(obj, gen.return());
1354 assertSame(obj, gen.return());
1355 assertEquals({value: undefined, done: true}, gen.next());
1356 assertEquals({value: undefined, done: true}, gen.return());
1357 assertEquals({value: undefined, done: true}, gen.return());
1358 }
1359
1360 assertEquals(42, (() => {
1361 for (let x of g()) break;
1362 return 42;
1363 })());
1364
1365 assertEquals(42, (() => {
1366 for (let x of g()) return 42;
1367 })());
1368
1369 assertThrowsEquals(() => {
1370 for (let x of g()) throw 42;
1371 }, 42);
1372 }
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/instanceof-es6.js ('k') | test/mjsunit/harmony/promise-species.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698