mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 10:48:41 +00:00
LibWeb: Print unhandled rejections the same way as unhandled exceptions
This commit is contained in:
@@ -11,24 +11,19 @@
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/#report-the-exception
|
||||
void report_exception(JS::Completion const& throw_completion)
|
||||
void print_error_from_value(JS::Value value, ErrorInPromise error_in_promise)
|
||||
{
|
||||
// FIXME: This is just old code, and does not strictly follow the spec of report an exception.
|
||||
// FIXME: We should probably also report these exceptions to the JS console.
|
||||
VERIFY(throw_completion.type() == JS::Completion::Type::Throw);
|
||||
VERIFY(throw_completion.value().has_value());
|
||||
auto thrown_value = *throw_completion.value();
|
||||
if (thrown_value.is_object()) {
|
||||
auto& object = thrown_value.as_object();
|
||||
if (value.is_object()) {
|
||||
auto& object = value.as_object();
|
||||
auto& vm = object.vm();
|
||||
auto name = object.get_without_side_effects(vm.names.name).value_or(JS::js_undefined());
|
||||
auto message = object.get_without_side_effects(vm.names.message).value_or(JS::js_undefined());
|
||||
if (name.is_accessor() || message.is_accessor()) {
|
||||
// The result is not going to be useful, let's just print the value. This affects DOMExceptions, for example.
|
||||
dbgln("\033[31;1mUnhandled JavaScript exception:\033[0m {}", thrown_value);
|
||||
dbgln("\033[31;1mUnhandled JavaScript exception{}:\033[0m {}", error_in_promise == ErrorInPromise::Yes ? " (in promise)" : "", JS::Value(&object));
|
||||
} else {
|
||||
dbgln("\033[31;1mUnhandled JavaScript exception:\033[0m [{}] {}", name, message);
|
||||
dbgln("\033[31;1mUnhandled JavaScript exception{}:\033[0m [{}] {}", error_in_promise == ErrorInPromise::Yes ? " (in promise)" : "", name, message);
|
||||
}
|
||||
if (is<JS::Error>(object)) {
|
||||
auto const& error_value = static_cast<JS::Error const&>(object);
|
||||
@@ -39,8 +34,17 @@ void report_exception(JS::Completion const& throw_completion)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dbgln("\033[31;1mUnhandled JavaScript exception:\033[0m {}", thrown_value);
|
||||
dbgln("\033[31;1mUnhandled JavaScript exception:\033[0m {}", value);
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#report-the-exception
|
||||
void report_exception(JS::Completion const& throw_completion)
|
||||
{
|
||||
// FIXME: This is just old code, and does not strictly follow the spec of report an exception.
|
||||
VERIFY(throw_completion.type() == JS::Completion::Type::Throw);
|
||||
VERIFY(throw_completion.value().has_value());
|
||||
print_error_from_value(*throw_completion.value(), ErrorInPromise::No);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user