mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Emit TokenType::Invalid for unterminated multi-line comments
This commit is contained in:
parent
03c1d43f6e
commit
19edcbd79c
Notes:
sideshowbarker
2024-07-19 01:41:36 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/19edcbd79cc Pull-request: https://github.com/SerenityOS/serenity/pull/3861
2 changed files with 19 additions and 1 deletions
|
@ -362,6 +362,7 @@ Token Lexer::next()
|
|||
{
|
||||
size_t trivia_start = m_position;
|
||||
auto in_template = !m_template_states.is_empty();
|
||||
bool unterminated_comment = false;
|
||||
|
||||
if (!in_template || m_template_states.last().in_expr) {
|
||||
// consume whitespace and comments
|
||||
|
@ -380,7 +381,11 @@ Token Lexer::next()
|
|||
do {
|
||||
consume();
|
||||
} while (!is_eof() && !is_block_comment_end());
|
||||
if (is_eof())
|
||||
unterminated_comment = true;
|
||||
consume(); // consume *
|
||||
if (is_eof())
|
||||
unterminated_comment = true;
|
||||
consume(); // consume /
|
||||
} else {
|
||||
break;
|
||||
|
@ -542,7 +547,12 @@ Token Lexer::next()
|
|||
consume();
|
||||
}
|
||||
} else if (m_current_char == EOF) {
|
||||
token_type = TokenType::Eof;
|
||||
if (unterminated_comment) {
|
||||
token_type = TokenType::Invalid;
|
||||
token_message = "Unterminated multi-line comment";
|
||||
} else {
|
||||
token_type = TokenType::Eof;
|
||||
}
|
||||
} else {
|
||||
// There is only one four-char operator: >>>=
|
||||
bool found_four_char_token = false;
|
||||
|
|
|
@ -21,3 +21,11 @@ return i;`;
|
|||
|
||||
expect(source).toEvalTo(1);
|
||||
});
|
||||
|
||||
test("unterminated multi-line comment", () => {
|
||||
expect("/*").not.toEval();
|
||||
expect("/**").not.toEval();
|
||||
expect("/*/").not.toEval();
|
||||
expect("/* foo").not.toEval();
|
||||
expect("foo /*").not.toEval();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue