LibWeb: Add a feature to LibWeb tests to fail on unhandled exceptions

Previously, if there was an unhandled exception in an async test, it
might fail to call done() and timeout. Now we have a default "error"
handler to catch unhandled exceptions and fail the test. A few tests
want to actually test the behavior of window.onerror, so they need an
escape hatch.
This commit is contained in:
Andrew Kaster 2024-10-04 16:11:00 -06:00 committed by Andreas Kling
parent 1fa948f114
commit 8edaec79de
Notes: github-actions[bot] 2024-10-05 07:19:21 +00:00
4 changed files with 20 additions and 0 deletions

View file

@ -395,6 +395,7 @@ asyncTest
printElement
println
promiseTest
removeTestErrorHandler
spoofCurrentURL
test
timeout

View file

@ -2,6 +2,9 @@
<script src="../include.js"></script>
<script>
asyncTest(done => {
removeTestErrorHandler()
window.addEventListener("error", (event) => {
println(`onerror event fired: ${event.error}`);
done();

View file

@ -1,6 +1,8 @@
<script src="../include.js"></script>
<script>
test(() => {
removeTestErrorHandler()
window.onerror = (message, filename, lineno, colno, error) => {
println(`message = ${message}`);
println(`lineno = ${lineno}`);

View file

@ -52,6 +52,20 @@ function timeout(ms) {
return promise;
}
const __testErrorHandlerController = new AbortController();
window.addEventListener(
"error",
event => {
println(`Uncaught Error In Test: ${event.message}`);
__finishTest();
},
{ signal: __testErrorHandlerController.signal }
);
function removeTestErrorHandler() {
__testErrorHandlerController.abort();
}
document.addEventListener("DOMContentLoaded", function () {
__outputElement = document.createElement("pre");
__outputElement.setAttribute("id", "out");