mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-08 12:19:37 +03:00
Browser: Show a "source location hint" for syntax errors :^)
This commit is contained in:
parent
015d65bc6f
commit
0f2b3cd280
Notes:
sideshowbarker
2024-07-19 06:06:43 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/0f2b3cd2801 Pull-request: https://github.com/SerenityOS/serenity/pull/2396
@ -79,15 +79,18 @@ ConsoleWidget::ConsoleWidget()
|
||||
auto parser = JS::Parser(JS::Lexer(js_source));
|
||||
auto program = parser.parse_program();
|
||||
|
||||
StringBuilder output_html;
|
||||
if (parser.has_errors()) {
|
||||
auto error = parser.errors()[0];
|
||||
auto hint = error.source_location_hint(js_source);
|
||||
if (!hint.is_empty())
|
||||
output_html.append(String::format("<pre>%s</pre>", hint.characters()));
|
||||
m_interpreter->throw_exception<JS::SyntaxError>(error.to_string());
|
||||
} else {
|
||||
m_interpreter->run(*program);
|
||||
}
|
||||
|
||||
if (m_interpreter->exception()) {
|
||||
StringBuilder output_html;
|
||||
output_html.append("Uncaught exception: ");
|
||||
output_html.append(JS::MarkupGenerator::html_from_value(m_interpreter->exception()->value()));
|
||||
print_html(output_html.string_view());
|
||||
|
Loading…
Reference in New Issue
Block a user