mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 07:48:47 +00:00
LibJS: Let parser keep track of errors
Rather than printing them to stderr directly the parser now keeps a Vector<Error>, which allows the "owner" of the parser to consume them individually after parsing. The Error struct has a message, line number, column number and a to_string() helper function to format this information into a meaningful error message. The Function() constructor will now include an error message when throwing a SyntaxError.
This commit is contained in:
parent
00b61a212f
commit
33defef267
Notes:
sideshowbarker
2024-07-19 06:38:47 +09:00
Author: https://github.com/linusg
Commit: 33defef267
Pull-request: https://github.com/SerenityOS/serenity/pull/2221
Reviewed-by: https://github.com/Dexesttp
7 changed files with 39 additions and 12 deletions
Libraries/LibWeb/DOM
|
@ -61,9 +61,10 @@ void HTMLScriptElement::children_changed()
|
|||
|
||||
auto parser = JS::Parser(JS::Lexer(source));
|
||||
auto program = parser.parse_program();
|
||||
if (parser.has_errors())
|
||||
if (parser.has_errors()) {
|
||||
parser.print_errors();
|
||||
return;
|
||||
|
||||
}
|
||||
document().interpreter().run(*program);
|
||||
}
|
||||
|
||||
|
@ -96,9 +97,10 @@ void HTMLScriptElement::inserted_into(Node& new_parent)
|
|||
|
||||
auto parser = JS::Parser(JS::Lexer(source));
|
||||
auto program = parser.parse_program();
|
||||
if (parser.has_errors())
|
||||
if (parser.has_errors()) {
|
||||
parser.print_errors();
|
||||
return;
|
||||
|
||||
}
|
||||
document().interpreter().run(*program);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue