promise-rejection-events-onerror.html (1214B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <link rel="help" href="https://html.spec.whatwg.org/#runtime-script-errors"> 6 <link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> 7 <script> 8 'use strict'; 9 setup({ 10 allow_uncaught_exception: true 11 }); 12 async_test(function(t) { 13 var e = new Error('e'); 14 var e2 = new Error('e2'); 15 16 window.onerror = function (msg, url, line, col, error) { 17 t.step(function() { 18 assert_true(msg.includes('e2')); 19 assert_equals(error, e2); 20 }); 21 t.done(); 22 }; 23 24 window.onrejectionhandled = function() { 25 // This should cause onerror 26 throw e2; 27 }; 28 29 var p = Promise.reject(e); 30 queueTask(function() { 31 queueTask(t.step_func(function() { 32 // This will cause onrejectionhandled 33 p.catch(function() {}); 34 })); 35 }); 36 }, 'Throwing inside an unhandledrejection handler invokes the error handler.'); 37 38 // This function queues a task in "DOM manipulation task source" 39 function queueTask(f) { 40 var d = document.createElement("details"); 41 d.ontoggle = function() { 42 f(); 43 }; 44 45 d.setAttribute("open", ""); 46 } 47 </script>