ladybird/Tests/LibWeb/Text/input/HTML/WindowOrWorkerGlobalScope-reportError.html
Andrew Kaster 8edaec79de 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.
2024-10-05 09:18:32 +02:00

20 lines
808 B
HTML

<script src="../include.js"></script>
<script>
test(() => {
removeTestErrorHandler()
window.onerror = (message, filename, lineno, colno, error) => {
println(`message = ${message}`);
println(`lineno = ${lineno}`);
println(`colno = ${colno}`);
println(`error = ${error}`);
// We can't simply print the filename because it is the full path to the active script, which varies between machines.
const filenameURL = new URL(filename);
println(`filename URL scheme = ${filenameURL.protocol}`);
println(`filename URL final path segment = ${filenameURL.pathname.split('/').pop()}`);
return true;
};
window.reportError(new Error('Reporting an Error!'));
});
</script>