microtask_after_raf.html (1655B)
1 <!DOCTYPE html> 2 <head> 3 <link rel=author title="Aleks Totic" href="mailto:atotic@chromium.org"> 4 <link rel=help href="https://html.spec.whatwg.org/#clean-up-after-running-script"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="resources/common.js"></script> 8 </head> 9 <body style="height:2000px;"> 10 <script> 11 /* 12 promise 1, promise 2 execute immediately after rAF 13 promise 1 child executes immediately after promise 2. 14 15 Relevant specs: 16 17 https://html.spec.whatwg.org/#clean-up-after-running-script 18 If the JavaScript execution context stack is now empty, perform a microtask checkpoint. 19 20 https://html.spec.whatwg.org/#perform-a-microtask-checkpoint 21 "perform a microtask checkpoint" runs in a loop until all microtasks have been delivered. 22 */ 23 24 var test = async_test("Microtask execute immediately after script"); 25 26 window.requestAnimationFrame( function() { 27 var events = []; 28 29 Promise.resolve() 30 .then(function() { 31 events.push("promise 1"); 32 return Promise.resolve(); 33 }) 34 .then(function() { 35 test.step(function() { 36 events.push("promise 1 child"); 37 assert_array_equals(events, ["promise 1", "promise 2", "promise 1 child"]); 38 test.done(); 39 }); 40 }); 41 Promise.resolve() 42 .then(function() { 43 events.push("promise 2"); 44 }); 45 46 // Set up events that must be executed after Promise. 47 window.setTimeout(function() { 48 events.push('timeout'); 49 }, 0); 50 window.addEventListener('scroll', function() { 51 events.push('scroll'); 52 }); 53 window.scrollBy(0,10); 54 55 }); 56 </script> 57 </body>