promise-rejection-event-during-parse.html (1513B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Promise rejection during initial parsing of document</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> 7 <body> 8 <p>The script in this test is executed immediately while parsing is ongoing, and 9 <a 10 href="https://html.spec.whatwg.org/multipage/webappapis.html#clean-up-after-running-script">cleaning 11 up after running script</a> involves queueing a task on the DOM manipulation 12 task source to fire the <code>unhandledrejection</code> event. Parsing then 13 completes, immediately transitioning the document's readiness state to 14 "interactive," and queuing another task on the DOM manipulation task source to 15 transition the state to "complete." 16 </p> 17 <script> 18 'use strict'; 19 setup({ allow_uncaught_exception: true }); 20 21 async_test(function(t) { 22 const events = []; 23 document.addEventListener('readystatechange', t.step_func(function() { 24 events.push('readystatechange:' + document.readyState); 25 })); 26 addEventListener('unhandledrejection', t.step_func(function() { 27 events.push('unhandledrejection'); 28 })); 29 30 Promise.reject(new Error('this error is intentional')); 31 32 addEventListener('load', t.step_func(function() { 33 assert_array_equals( 34 events, 35 [ 36 'readystatechange:interactive', 37 'unhandledrejection', 38 'readystatechange:complete' 39 ] 40 ); 41 t.done(); 42 })); 43 }); 44 </script>