Commit 12857348 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[scanner] Simplify HTML comment scanning

Change-Id: I3c04e3cedfa220d58eb1307977b99869485c7f4d
Reviewed-on: https://chromium-review.googlesource.com/1177744Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55170}
parent bda4096b
......@@ -14,25 +14,6 @@ namespace internal {
V8_INLINE Token::Value Scanner::SkipWhiteSpace() {
int start_position = source_pos();
SkipWhiteSpaceImpl();
// If there is an HTML comment end '-->' at the beginning of a
// line (with only whitespace in front of it), we treat the rest
// of the line as a comment. This is in line with the way
// SpiderMonkey handles it.
if (c0_ != '-' || !has_line_terminator_before_next_) {
// Return whether or not we skipped any characters.
if (source_pos() == start_position) {
return Token::ILLEGAL;
}
return Token::WHITESPACE;
}
return TryToSkipHTMLCommentAndWhiteSpaces(start_position);
}
V8_INLINE void Scanner::SkipWhiteSpaceImpl() {
while (true) {
// We won't skip behind the end of input.
DCHECK(!unicode_cache_->IsWhiteSpace(kEndOfInput));
......@@ -46,7 +27,16 @@ V8_INLINE void Scanner::SkipWhiteSpaceImpl() {
}
Advance();
}
// Return whether or not we skipped any characters.
if (source_pos() == start_position) {
DCHECK_NE('0', c0_);
return Token::ILLEGAL;
}
return Token::WHITESPACE;
}
} // namespace internal
} // namespace v8
......
......@@ -413,41 +413,6 @@ Token::Value Scanner::PeekAhead() {
return ret;
}
Token::Value Scanner::TryToSkipHTMLCommentAndWhiteSpaces(int start_position) {
while (true) {
DCHECK_EQ('-', c0_);
Advance();
// If there is an HTML comment end '-->' at the beginning of a
// line, we treat the rest of the line as a comment. This is in line with
// the way SpiderMonkey handles it.
if (c0_ != '-' || Peek() != '>') {
PushBack('-'); // undo Advance()
break;
}
Advance();
// Treat the rest of the line as a comment.
Token::Value token = SkipSingleHTMLComment();
if (token == Token::ILLEGAL) {
return token;
}
// Skip remaining whitespaces after the HTML comment.
SkipWhiteSpaceImpl();
// Only repeat loop if we find another HTML comment
if (c0_ != '-' || !has_line_terminator_before_next_) break;
}
// Return whether or not we skipped any characters.
if (source_pos() == start_position) {
return Token::ILLEGAL;
}
return Token::WHITESPACE;
}
Token::Value Scanner::SkipSingleHTMLComment() {
if (is_module_) {
ReportScannerError(source_pos(), MessageTemplate::kHtmlCommentInModule);
......
......@@ -588,8 +588,6 @@ class Scanner {
void Scan();
V8_INLINE Token::Value SkipWhiteSpace();
V8_INLINE void SkipWhiteSpaceImpl();
Token::Value TryToSkipHTMLCommentAndWhiteSpaces(int start_position);
Token::Value SkipSingleHTMLComment();
Token::Value SkipSingleLineComment();
Token::Value SkipSourceURLComment();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment