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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/dom/resources/promise-rejection-events.js

Issue 1384913002: Revert of Don't report promise rejection events during the microtask checkpoint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | third_party/WebKit/Source/bindings/core/v8/RejectedPromises.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 'use strict'; 1 'use strict';
2 2
3 if (self.importScripts) { 3 if (self.importScripts) {
4 if ('ServiceWorkerGlobalScope' in self && self instanceof ServiceWorkerGlobalS cope) { 4 if ('ServiceWorkerGlobalScope' in self && self instanceof ServiceWorkerGlobalS cope) {
5 importScripts('../../serviceworker/resources/worker-testharness.js'); 5 importScripts('../../serviceworker/resources/worker-testharness.js');
6 } else { 6 } else {
7 importScripts('../../resources/testharness.js'); 7 importScripts('../../resources/testharness.js');
8 } 8 }
9 } 9 }
10 10
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 postMessageTask(function() { 264 postMessageTask(function() {
265 p = Promise.resolve().then(function() { 265 p = Promise.resolve().then(function() {
266 return Promise.reject(e); 266 return Promise.reject(e);
267 }) 267 })
268 .catch(function() {}); 268 .catch(function() {});
269 }); 269 });
270 }, 'no unhandledrejection/rejectionhandled: all inside a queued task, a rejectio n handler attached synchronously to ' + 270 }, 'no unhandledrejection/rejectionhandled: all inside a queued task, a rejectio n handler attached synchronously to ' +
271 'a promise created from returning a Promise.reject-created promise in a fulfi llment handler'); 271 'a promise created from returning a Promise.reject-created promise in a fulfi llment handler');
272 272
273 // 273 //
274 // Negative unhandledrejection/rejectionhandled tests with microtask-delayed att achment 274 // Negative unhandledrejection/rejectionhandled tests with delayed attachment
275 // 275 //
276 276
277 async_test(function(t) { 277 async_test(function(t) {
278 var e = new Error(); 278 var e = new Error();
279 var p; 279 var p;
280 280
281 onUnhandledFail(t, function() { return p; }); 281 onUnhandledFail(t, function() { return p; });
282 282
283 p = Promise.reject(e); 283 p = Promise.reject(e);
284 mutationObserverMicrotask(function() { 284 mutationObserverMicrotask(function() {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 mutationObserverMicrotask(function() { 442 mutationObserverMicrotask(function() {
443 p.catch(function() {}); 443 p.catch(function() {});
444 }); 444 });
445 }); 445 });
446 }); 446 });
447 }); 447 });
448 }, 0); 448 }, 0);
449 }, 'microtask nesting: attaching a handler inside a combination of promise micro tasks + mutationObserverMicrotask, ' + 449 }, 'microtask nesting: attaching a handler inside a combination of promise micro tasks + mutationObserverMicrotask, ' +
450 'all inside a setTimeout'); 450 'all inside a setTimeout');
451 451
452
453 // For workers, postMessageTask() involves posting tasks to other threads, so
454 // the following tests don't work there.
455
456 if ('document' in self) {
457 //
458 // Negative unhandledrejection/rejectionhandled tests with task-delayed attach ment
459 //
460
461 async_test(function(t) {
462 var e = new Error();
463 var p;
464
465 onUnhandledFail(t, function() { return p; });
466
467 var _reject;
468 p = new Promise(function(_, reject) {
469 _reject = reject;
470 });
471 _reject(e);
472 postMessageTask(function() {
473 var unreached = t.unreached_func('promise should not be fulfilled');
474 p.then(unreached, function() {});
475 });
476 }, 'delayed handling: a task delay before attaching a handler prevents unhandl edrejection');
477
478 async_test(function(t) {
479 var e = new Error();
480 var p;
481
482 onUnhandledFail(t, function() { return p; });
483
484 p = Promise.reject(e);
485 postMessageTask(function() {
486 Promise.resolve().then(function() {
487 p.catch(function() {});
488 });
489 });
490 }, 'delayed handling: postMessageTask after promise creation/rejection, plus p romise microtasks, is not too late to ' +
491 'attach a rejection handler');
492
493 async_test(function(t) {
494 var e = new Error();
495 var p;
496
497 onUnhandledFail(t, function() { return p; });
498
499 postMessageTask(function() {
500 Promise.resolve().then(function() {
501 Promise.resolve().then(function() {
502 Promise.resolve().then(function() {
503 Promise.resolve().then(function() {
504 p.catch(function() {});
505 });
506 });
507 });
508 });
509 });
510 p = Promise.reject(e);
511 }, 'delayed handling: postMessageTask before promise creation/rejection, plus many promise microtasks, is not too ' +
512 'late to attach a rejection handler');
513
514 async_test(function(t) {
515 var e = new Error();
516 var p;
517
518 onUnhandledFail(t, function() { return p; });
519
520 p = Promise.reject(e);
521 postMessageTask(function() {
522 Promise.resolve().then(function() {
523 Promise.resolve().then(function() {
524 Promise.resolve().then(function() {
525 Promise.resolve().then(function() {
526 p.catch(function() {});
527 });
528 });
529 });
530 });
531 });
532 }, 'delayed handling: postMessageTask after promise creation/rejection, plus m any promise microtasks, is not too ' +
533 'late to attach a rejection handler');
534 }
535
536 // 452 //
537 // Positive unhandledrejection/rejectionhandled tests with delayed attachment 453 // Positive unhandledrejection/rejectionhandled tests with delayed attachment
538 // 454 //
539 455
540 async_test(function(t) { 456 async_test(function(t) {
541 var e = new Error(); 457 var e = new Error();
542 var p; 458 var p;
543 459
544 onUnhandledSucceed(t, e, function() { return p; }); 460 onUnhandledSucceed(t, e, function() { return p; });
545 461
546 var _reject; 462 var _reject;
547 p = new Promise(function(_, reject) { 463 p = new Promise(function(_, reject) {
548 _reject = reject; 464 _reject = reject;
549 }); 465 });
550 _reject(e); 466 _reject(e);
551 postMessageTask(function() { 467 postMessageTask(function() {
552 postMessageTask(function() { 468 var unreached = t.unreached_func('promise should not be fulfilled');
553 var unreached = t.unreached_func('promise should not be fulfilled'); 469 p.then(unreached, function() {});
554 p.then(unreached, function() {});
555 });
556 }); 470 });
557 }, 'delayed handling: a nested-task delay before attaching a handler causes unha ndledrejection'); 471 }, 'delayed handling: a task delay before attaching a handler does not prevent u nhandledrejection');
558
559 async_test(function(t) {
560 var e = new Error();
561 var p;
562
563 onUnhandledSucceed(t, e, function() { return p; });
564
565 p = Promise.reject(e);
566 postMessageTask(function() {
567 postMessageTask(function() {
568 Promise.resolve().then(function() {
569 p.catch(function() {});
570 });
571 });
572 });
573 }, 'delayed handling: a nested-postMessageTask after promise creation/rejection, plus promise microtasks, is too ' +
574 'late to attach a rejection handler');
575
576 async_test(function(t) {
577 var e = new Error();
578 var p;
579
580 onUnhandledSucceed(t, e, function() { return p; });
581
582 postMessageTask(function() {
583 postMessageTask(function() {
584 Promise.resolve().then(function() {
585 Promise.resolve().then(function() {
586 Promise.resolve().then(function() {
587 Promise.resolve().then(function() {
588 p.catch(function() {});
589 });
590 });
591 });
592 });
593 });
594 });
595 p = Promise.reject(e);
596 }, 'delayed handling: a nested-postMessageTask before promise creation/rejection , plus many promise microtasks, is ' +
597 'too late to attach a rejection handler');
598
599 async_test(function(t) {
600 var e = new Error();
601 var p;
602
603 onUnhandledSucceed(t, e, function() { return p; });
604
605 p = Promise.reject(e);
606 postMessageTask(function() {
607 postMessageTask(function() {
608 Promise.resolve().then(function() {
609 Promise.resolve().then(function() {
610 Promise.resolve().then(function() {
611 Promise.resolve().then(function() {
612 p.catch(function() {});
613 });
614 });
615 });
616 });
617 });
618 });
619 }, 'delayed handling: a nested-postMessageTask after promise creation/rejection, plus many promise microtasks, is ' +
620 'too late to attach a rejection handler');
621 472
622 async_test(function(t) { 473 async_test(function(t) {
623 var unhandledPromises = []; 474 var unhandledPromises = [];
624 var unhandledReasons = []; 475 var unhandledReasons = [];
625 var e = new Error(); 476 var e = new Error();
626 var p; 477 var p;
627 478
628 var unhandled = function(ev) { 479 var unhandled = function(ev) {
629 if (ev.promise === p) { 480 if (ev.promise === p) {
630 t.step(function() { 481 t.step(function() {
(...skipping 21 matching lines...) Expand all
652 }); 503 });
653 setTimeout(function() { 504 setTimeout(function() {
654 var unreached = t.unreached_func('promise should not be fulfilled'); 505 var unreached = t.unreached_func('promise should not be fulfilled');
655 p.then(unreached, function(reason) { 506 p.then(unreached, function(reason) {
656 assert_equals(reason, e); 507 assert_equals(reason, e);
657 setTimeout(function() { t.done(); }, 10); 508 setTimeout(function() { t.done(); }, 10);
658 }); 509 });
659 }, 10); 510 }, 10);
660 }, 'delayed handling: delaying handling by setTimeout(,10) will cause both event s to fire'); 511 }, 'delayed handling: delaying handling by setTimeout(,10) will cause both event s to fire');
661 512
513 async_test(function(t) {
514 var e = new Error();
515 var p;
516
517 onUnhandledSucceed(t, e, function() { return p; });
518
519 p = Promise.reject(e);
520 postMessageTask(function() {
521 Promise.resolve().then(function() {
522 p.catch(function() {});
523 });
524 });
525 }, 'delayed handling: postMessageTask after promise creation/rejection, plus pro mise microtasks, is too late to ' +
526 'attach a rejection handler');
527
528 async_test(function(t) {
529 var e = new Error();
530 var p;
531
532 onUnhandledSucceed(t, e, function() { return p; });
533 postMessageTask(function() {
534 Promise.resolve().then(function() {
535 Promise.resolve().then(function() {
536 Promise.resolve().then(function() {
537 Promise.resolve().then(function() {
538 p.catch(function() {});
539 });
540 });
541 });
542 });
543 });
544 p = Promise.reject(e);
545 }, 'delayed handling: postMessageTask before promise creation/rejection, plus ma ny promise microtasks, is too late ' +
546 'to attach a rejection handler');
547
548 async_test(function(t) {
549 var e = new Error();
550 var p;
551
552 onUnhandledSucceed(t, e, function() { return p; });
553
554 p = Promise.reject(e);
555 postMessageTask(function() {
556 Promise.resolve().then(function() {
557 Promise.resolve().then(function() {
558 Promise.resolve().then(function() {
559 Promise.resolve().then(function() {
560 p.catch(function() {});
561 });
562 });
563 });
564 });
565 });
566 }, 'delayed handling: postMessageTask after promise creation/rejection, plus man y promise microtasks, is too late ' +
567 'to attach a rejection handler');
568
662 // 569 //
663 // Miscellaneous tests about integration with the rest of the platform 570 // Miscellaneous tests about integration with the rest of the platform
664 // 571 //
665 572
666 async_test(function(t) { 573 async_test(function(t) {
667 var e = new Error(); 574 var e = new Error();
668 var l = function(ev) { 575 var l = function(ev) {
669 var order = []; 576 var order = [];
670 mutationObserverMicrotask(function() { 577 mutationObserverMicrotask(function() {
671 order.push(1); 578 order.push(1);
672 }); 579 });
673 setTimeout(function() { 580 setTimeout(function() {
674 order.push(2); 581 order.push(2);
675 t.step(function() { 582 t.step(function() {
676 assert_array_equals(order, [1, 2]); 583 assert_array_equals(order, [1, 2]);
677 }); 584 });
678 t.done(); 585 t.done();
679 }, 1); 586 }, 1);
680 }; 587 };
681 addEventListener('unhandledrejection', l); 588 addEventListener('unhandledrejection', l);
682 ensureCleanup(t, l); 589 ensureCleanup(t, l);
683 Promise.reject(e); 590 Promise.reject(e);
684 }, 'mutationObserverMicrotask vs. postMessageTask ordering is not disturbed insi de unhandledrejection events'); 591 }, 'mutationObserverMicrotask vs. postMessageTask ordering is not disturbed insi de unhandledrejection events');
685 592
686 // For workers, postMessageTask() involves posting tasks to other threads, so
687 // the following tests don't work there.
688
689 if ('document' in self) {
690
691 // For the next two see https://github.com/domenic/unhandled-rejections-browse r-spec/issues/2#issuecomment-121121695
692 // and the following comments.
693
694 async_test(function(t) {
695 var sequenceOfEvents = [];
696
697 addEventListener('unhandledrejection', l);
698 ensureCleanup(t, l);
699
700 var p1 = Promise.reject();
701 var p2;
702 postMessageTask(function() {
703 p2 = Promise.reject();
704 postMessageTask(function() {
705 sequenceOfEvents.push('postMessageTask');
706 checkSequence();
707 });
708 });
709
710 function l(ev) {
711 if (ev.promise === p1 || ev.promise === p2) {
712 sequenceOfEvents.push(ev.promise);
713 checkSequence();
714 }
715 }
716
717 function checkSequence() {
718 if (sequenceOfEvents.length === 3) {
719 t.step(function() {
720 assert_array_equals(sequenceOfEvents, [p1, 'postMessageTask', p2]);
721 });
722 t.done();
723 }
724 }
725 }, 'postMessageTask ordering vs. the task queued for unhandled rejection notif ication (1)');
726
727 async_test(function(t) {
728 var sequenceOfEvents = [];
729
730 addEventListener('unhandledrejection', l);
731 ensureCleanup(t, l);
732
733 var p2;
734 postMessageTask(function() {
735 p2 = Promise.reject();
736 postMessageTask(function() {
737 sequenceOfEvents.push('postMessageTask');
738 checkSequence();
739 });
740 });
741
742 function l(ev) {
743 if (ev.promise == p2) {
744 sequenceOfEvents.push(ev.promise);
745 checkSequence();
746 }
747 }
748
749 function checkSequence() {
750 if (sequenceOfEvents.length === 2) {
751 t.step(function() {
752 assert_array_equals(sequenceOfEvents, ['postMessageTask', p2]);
753 });
754 t.done();
755 }
756 }
757 }, 'postMessageTask ordering vs. the task queued for unhandled rejection notif ication (2)');
758
759 async_test(function(t) {
760 var sequenceOfEvents = [];
761
762
763 addEventListener('unhandledrejection', unhandled);
764 addEventListener('rejectionhandled', handled);
765 ensureCleanup(t, unhandled, handled);
766
767 var p = Promise.reject();
768
769 setTimeout(function() {
770 postMessageTask(function() {
771 sequenceOfEvents.push('task before catch');
772 checkSequence();
773 });
774
775 p.catch(function() {
776 sequenceOfEvents.push('catch');
777 checkSequence();
778 });
779
780 postMessageTask(function() {
781 sequenceOfEvents.push('task after catch');
782 checkSequence();
783 });
784
785 sequenceOfEvents.push('after catch');
786 checkSequence();
787 }, 10);
788
789 function unhandled(ev) {
790 if (ev.promise === p) {
791 sequenceOfEvents.push('unhandled');
792 checkSequence();
793 }
794 }
795
796 function handled(ev) {
797 if (ev.promise === p) {
798 sequenceOfEvents.push('handled');
799 checkSequence();
800 }
801 }
802
803 function checkSequence() {
804 if (sequenceOfEvents.length === 6) {
805 t.step(function() {
806 assert_array_equals(sequenceOfEvents,
807 ['unhandled', 'after catch', 'catch', 'task before catch', 'handled' , 'task after catch']);
808 });
809 t.done();
810 }
811 }
812 }, 'rejectionhandled is dispatched from a queued task, and not immediately');
813 }
814
815 // 593 //
816 // HELPERS 594 // HELPERS
817 // 595 //
818 596
819 var globalPostMessageCounter = 0;
820
821 function postMessageTask(f) { 597 function postMessageTask(f) {
822 if ('document' in self) { 598 if ('document' in self) {
823 var message = 'abusingpostmessageforfunandprofit' + globalPostMessageCounter ; 599 var l = function() {
824 globalPostMessageCounter++; 600 removeEventListener('message', l);
825 var l = function(ev) { 601 f();
826 if (ev.data === message) {
827 removeEventListener('message', l);
828 f();
829 }
830 }; 602 };
831 addEventListener('message', l); 603 addEventListener('message', l);
832 postMessage(message, '*'); 604 postMessage('abusingpostmessageforfunandprofit', '*');
833 } else { 605 } else {
834 var channel = new MessageChannel(); 606 var channel = new MessageChannel();
835 channel.port1.onmessage = function() { channel.port1.close(); f(); }; 607 channel.port1.onmessage = function() { channel.port1.close(); f(); };
836 channel.port2.postMessage('abusingpostmessageforfunandprofit'); 608 channel.port2.postMessage('abusingpostmessageforfunandprofit');
837 channel.port2.close(); 609 channel.port2.close();
838 } 610 }
839 } 611 }
840 612
841 function mutationObserverMicrotask(f) { 613 function mutationObserverMicrotask(f) {
842 if ('document' in self) { 614 if ('document' in self) {
(...skipping 18 matching lines...) Expand all
861 t.done(); 633 t.done();
862 } 634 }
863 }; 635 };
864 addEventListener('unhandledrejection', l); 636 addEventListener('unhandledrejection', l);
865 ensureCleanup(t, l); 637 ensureCleanup(t, l);
866 } 638 }
867 639
868 function onUnhandledFail(t, expectedPromiseGetter) { 640 function onUnhandledFail(t, expectedPromiseGetter) {
869 var unhandled = function(evt) { 641 var unhandled = function(evt) {
870 if (evt.promise === expectedPromiseGetter()) { 642 if (evt.promise === expectedPromiseGetter()) {
871 t.step(function() { 643 t.unreached_func('unhandledrejection event is not supposed to be triggered ');
872 assert_unreached('unhandledrejection event is not supposed to be trigger ed');
873 });
874 } 644 }
875 }; 645 };
876 var handled = function(evt) { 646 var handled = function(evt) {
877 if (evt.promise === expectedPromiseGetter()) { 647 if (evt.promise === expectedPromiseGetter()) {
878 t.step(function() { 648 t.unreached_func('rejectionhandled event is not supposed to be triggered') ;
879 assert_unreached('rejectionhandled event is not supposed to be triggered ');
880 });
881 } 649 }
882 }; 650 };
883 addEventListener('unhandledrejection', unhandled); 651 addEventListener('unhandledrejection', unhandled);
884 addEventListener('rejectionhandled', handled); 652 addEventListener('rejectionhandled', handled);
885 ensureCleanup(t, unhandled, handled); 653 ensureCleanup(t, unhandled, handled);
886 setTimeout(function() { 654 setTimeout(function() {
887 t.done(); 655 t.done();
888 }, 10); 656 }, 10);
889 } 657 }
890 658
891 function ensureCleanup(t, unhandled, handled) { 659 function ensureCleanup(t, unhandled, handled) {
892 t.add_cleanup(function() { 660 t.add_cleanup(function() {
893 if (unhandled) 661 if (unhandled)
894 removeEventListener('unhandledrejection', unhandled); 662 removeEventListener('unhandledrejection', unhandled);
895 if (handled) 663 if (handled)
896 removeEventListener('rejectionhandled', handled); 664 removeEventListener('rejectionhandled', handled);
897 }); 665 });
898 } 666 }
899 667
900 done(); 668 done();
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/RejectedPromises.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698