mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 02:08:12 +03:00
Browser: Wrap DOMException values in regular JS::Error for console printing
Small hack to effortlessly make JS::MarkupGenerator output DOMExceptions formatted like regular errors.
This commit is contained in:
parent
e064194061
commit
8b78ed6308
Notes:
sideshowbarker
2024-07-18 22:08:14 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/8b78ed63089 Pull-request: https://github.com/SerenityOS/serenity/pull/5414 Reviewed-by: https://github.com/alimpfard
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user