Commit b68df2d2 authored by vogelheim's avatar vogelheim Committed by Commit bot

Fix Scanner invariants w/ literal buffers.

This isn't the most elegant fix, but I'd prefer to not rework the logic
right now. What happens is:
- Most parts of the Scanner use nullptr to mean, no literal buffer.
- The bookmarking logic may end up with a state where there's a non-nullptr
  literal buffer, but it's empty. (length 0)
- These are functionally equivalent, so there's no 'real' bug.
- But it makes it hard to reason. This patch hence checks for length-0
  literal buffers, and uses nullptr instead.

R=marja@chromium.org
BUG=chromium:639191 v8:4947

Review-Url: https://codereview.chromium.org/2258073003
Cr-Commit-Position: refs/heads/master@{#38756}
parent 9bc44ff0
......@@ -1598,14 +1598,9 @@ void Scanner::ResetToBookmark() {
source_->ResetToBookmark();
c0_ = bookmark_c0_;
StartLiteral();
StartRawLiteral();
CopyTokenDesc(&next_, &bookmark_current_);
CopyToNextTokenDesc(&bookmark_current_);
current_ = next_;
StartLiteral();
StartRawLiteral();
CopyTokenDesc(&next_, &bookmark_next_);
CopyToNextTokenDesc(&bookmark_next_);
bookmark_c0_ = kBookmarkWasApplied;
}
......@@ -1620,6 +1615,13 @@ bool Scanner::BookmarkHasBeenReset() {
void Scanner::DropBookmark() { bookmark_c0_ = kNoBookmark; }
void Scanner::CopyToNextTokenDesc(TokenDesc* from) {
StartLiteral();
StartRawLiteral();
CopyTokenDesc(&next_, from);
if (next_.literal_chars->length() == 0) next_.literal_chars = nullptr;
if (next_.raw_literal_chars->length() == 0) next_.raw_literal_chars = nullptr;
}
void Scanner::CopyTokenDesc(TokenDesc* to, TokenDesc* from) {
DCHECK_NOT_NULL(to);
......
......@@ -534,6 +534,7 @@ class Scanner {
bool BookmarkHasBeenSet();
bool BookmarkHasBeenReset();
void DropBookmark();
void CopyToNextTokenDesc(TokenDesc* from);
static void CopyTokenDesc(TokenDesc* to, TokenDesc* from);
void ReportScannerError(const Location& location,
......
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