1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:48:11 +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:
Linus Groh 2020-05-14 16:26:01 +01:00 committed by Andreas Kling
parent 00b61a212f
commit 33defef267
7 changed files with 39 additions and 12 deletions

View file

@ -29,7 +29,11 @@ try {
assertThrowsError(() => {
new Function("[");
}, {
error: SyntaxError
error: SyntaxError,
// This might be confusing at first but keep in mind it's actually parsing
// function anonymous() { [ }
// This is in line with what other engines are reporting.
message: "Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"
});
console.log("PASS");