diff options
author | Linus Groh <mail@linusgroh.de> | 2021-02-19 19:15:14 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-20 00:09:11 +0100 |
commit | 8b78ed630893e2dc0d08b8fcd6700b4d5a29ba1f (patch) | |
tree | b03e3011ec5160522c6dc9695c96402978e3ce0f /Userland/Applications/Browser | |
parent | e064194061d04dd93947c079ebb3d5f69df398b7 (diff) | |
download | serenity-8b78ed630893e2dc0d08b8fcd6700b4d5a29ba1f.zip |
Browser: Wrap DOMException values in regular JS::Error for console printing
Small hack to effortlessly make JS::MarkupGenerator output DOMExceptions
formatted like regular errors.
Diffstat (limited to 'Userland/Applications/Browser')
-rw-r--r-- | Userland/Applications/Browser/ConsoleWidget.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Userland/Applications/Browser/ConsoleWidget.cpp b/Userland/Applications/Browser/ConsoleWidget.cpp index ae132e50ba..7af99bff3e 100644 --- a/Userland/Applications/Browser/ConsoleWidget.cpp +++ b/Userland/Applications/Browser/ConsoleWidget.cpp @@ -35,6 +35,7 @@ #include <LibJS/Parser.h> #include <LibJS/Runtime/Error.h> #include <LibJS/SyntaxHighlighter.h> +#include <LibWeb/Bindings/DOMExceptionWrapper.h> #include <LibWeb/DOM/DocumentType.h> #include <LibWeb/DOM/ElementFactory.h> #include <LibWeb/DOM/Text.h> @@ -99,7 +100,12 @@ ConsoleWidget::ConsoleWidget() if (m_interpreter->exception()) { output_html.append("Uncaught exception: "); - output_html.append(JS::MarkupGenerator::html_from_value(m_interpreter->exception()->value())); + auto error = m_interpreter->exception()->value(); + if (error.is_object() && is<Web::Bindings::DOMExceptionWrapper>(error.as_object())) { + auto& dom_exception_wrapper = static_cast<Web::Bindings::DOMExceptionWrapper&>(error.as_object()); + error = JS::Error::create(m_interpreter->global_object(), dom_exception_wrapper.impl().name(), dom_exception_wrapper.impl().message()); + } + output_html.append(JS::MarkupGenerator::html_from_value(error)); print_html(output_html.string_view()); m_interpreter->vm().clear_exception(); |