mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
LibWeb: Print unhandled rejections the same way as unhandled exceptions
This commit is contained in:
parent
62491cda0b
commit
1e36224321
Notes:
sideshowbarker
2024-07-17 18:46:30 +09:00
Author: https://github.com/Lubrsi
Commit: 1e36224321
Pull-request: https://github.com/SerenityOS/serenity/pull/14406
Reviewed-by: https://github.com/linusg
3 changed files with 23 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue