diff options
author | Linus Groh <mail@linusgroh.de> | 2020-10-24 12:48:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-24 16:34:01 +0200 |
commit | 9f036959e867e52bbec12a384e00f21ee0a07be2 (patch) | |
tree | ccb926219b5220ce61841991b5f7d31fae18c3a4 | |
parent | d6f8c52245abb173c176036ff0e4d79f57510b41 (diff) | |
download | serenity-9f036959e867e52bbec12a384e00f21ee0a07be2.zip |
LibJS: Report correct line/column for string literal syntax errors
We're passing a token to this function, so m_current_token is actually
the next token - which leads to incorrect line/column numbers for string
literal syntax errors:
"\u"
^
Uncaught exception: [SyntaxError]: Malformed unicode escape sequence (line: 1, column: 5)
Rather than:
"\u"
^
Uncaught exception: [SyntaxError]: Malformed unicode escape sequence (line: 1, column: 1)
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index c2b6e340c4..806d4aa73b 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -849,10 +849,8 @@ NonnullRefPtr<StringLiteral> Parser::parse_string_literal(Token token) message = "Unicode code_point must not be greater than 0x10ffff in escape sequence"; } - syntax_error( - message, - m_parser_state.m_current_token.line_number(), - m_parser_state.m_current_token.line_column()); + if (!message.is_empty()) + syntax_error(message, token.line_number(), token.line_column()); } if (m_parser_state.m_use_strict_directive == UseStrictDirectiveState::Looking) { |