Index: src/scanner.cc |
diff --git a/src/scanner.cc b/src/scanner.cc |
index cebb5870f22dee984dee96e80ee61933574af587..944613081c012dfd14d52f39885151951ea62ca8 100644 |
--- a/src/scanner.cc |
+++ b/src/scanner.cc |
@@ -237,6 +237,11 @@ Token::Value Scanner::Next() { |
next_.location.end_pos = current_.location.end_pos; |
} |
current_ = next_; |
+ if (V8_UNLIKELY(next_next_.token != Token::UNINITIALIZED)) { |
+ next_ = next_next_; |
+ next_next_.token = Token::UNINITIALIZED; |
+ return current_.token; |
+ } |
has_line_terminator_before_next_ = false; |
has_multiline_comment_before_next_ = false; |
if (static_cast<unsigned>(c0_) <= 0x7f) { |
@@ -255,6 +260,20 @@ Token::Value Scanner::Next() { |
} |
+Token::Value Scanner::PeekAhead() { |
+ if (next_next_.token != Token::UNINITIALIZED) { |
+ return next_next_.token; |
+ } |
+ TokenDesc prev = current_; |
+ Next(); |
+ Token::Value ret = next_.token; |
+ next_next_ = next_; |
+ next_ = current_; |
+ current_ = prev; |
+ return ret; |
+} |
+ |
+ |
// TODO(yangguo): check whether this is actually necessary. |
static inline bool IsLittleEndianByteOrderMark(uc32 c) { |
// The Unicode value U+FFFE is guaranteed never to be assigned as a |
@@ -1432,7 +1451,7 @@ int Scanner::FindSymbol(DuplicateFinder* finder, int value) { |
bool Scanner::SetBookmark() { |
if (c0_ != kNoBookmark && bookmark_c0_ == kNoBookmark && |
- source_->SetBookmark()) { |
+ next_next_.token == Token::UNINITIALIZED && source_->SetBookmark()) { |
bookmark_c0_ = c0_; |
CopyTokenDesc(&bookmark_current_, ¤t_); |
CopyTokenDesc(&bookmark_next_, &next_); |