1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:27:42 +00:00

WebContent+LibWeb+LibJS: Report exceptions to the JS console

Print exceptions passed to `HTML::report_exception` in the JS console

Refactored `ExceptionReporter`: in order to report exception now
you need to pass the relevant realm in it. For passed `JS::Value`
we now create `JS::Error` object to print value as the error message.
This commit is contained in:
Pavel 2022-10-08 19:38:32 +04:00 committed by Linus Groh
parent 2eb6dbd4f0
commit 40aad77ab1
14 changed files with 86 additions and 58 deletions

View file

@ -49,23 +49,15 @@ void WebContentConsoleClient::handle_input(String const& js_source)
auto result = script->run();
StringBuilder output_html;
if (result.is_abrupt()) {
output_html.append("Uncaught exception: "sv);
auto error = *result.release_error().value();
if (error.is_object())
output_html.append(JS::MarkupGenerator::html_from_error(error.as_object()));
else
output_html.append(JS::MarkupGenerator::html_from_value(error));
print_html(output_html.string_view());
return;
}
if (result.value().has_value())
print_html(JS::MarkupGenerator::html_from_value(*result.value()));
}
void WebContentConsoleClient::report_exception(JS::Error const& exception, bool in_promise)
{
print_html(JS::MarkupGenerator::html_from_error(exception, in_promise));
}
void WebContentConsoleClient::print_html(String const& line)
{
m_message_log.append({ .type = ConsoleOutput::Type::HTML, .data = line });