window-onerror-runtime-error-throw.html (1194B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>window.onerror: runtime scripterrors</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <!-- 8 9 https://html.spec.whatwg.org/multipage/#runtime-script-errors 10 says what to do for uncaught runtime script errors, and just below 11 describes what to do when onerror is a Function. 12 13 --> 14 </head> 15 <body> 16 17 <div id="log"></div> 18 <script> 19 setup({allow_uncaught_exception:true}); 20 var error_count = 0; 21 window.onerror = function(msg, url, lineno) { 22 ++error_count; 23 test(function() {assert_equals(url, window.location.href)}, 24 "correct url passed to window.onerror"); 25 test(function() {assert_equals(lineno, 36)}, 26 "correct line number passed to window.onerror"); 27 }; 28 </script> 29 <script> 30 try { 31 // This error is caught, so it should NOT trigger onerror. 32 throw "foo"; 33 } catch (ex) { 34 } 35 // This error is NOT caught, so it should trigger onerror. 36 throw "bar"; 37 </script> 38 <script> 39 test(function() {assert_equals(error_count, 1)}, 40 "correct number of calls to window.onerror"); 41 </script> 42 </body> 43 </html>