Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Unified Diff: src/scanner.cc

Issue 6529032: Merge 6168:6800 from bleeding_edge to experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/scanner.h ('k') | src/scanner-base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scanner.cc
===================================================================
--- src/scanner.cc (revision 6800)
+++ src/scanner.cc (working copy)
@@ -48,14 +48,18 @@
BufferedUC16CharacterStream::~BufferedUC16CharacterStream() { }
-void BufferedUC16CharacterStream::PushBack(uc16 character) {
+void BufferedUC16CharacterStream::PushBack(uc32 character) {
+ if (character == kEndOfInput) {
+ pos_--;
+ return;
+ }
if (pushback_limit_ == NULL && buffer_cursor_ > buffer_) {
// buffer_ is writable, buffer_cursor_ is const pointer.
- buffer_[--buffer_cursor_ - buffer_] = character;
+ buffer_[--buffer_cursor_ - buffer_] = static_cast<uc16>(character);
pos_--;
return;
}
- SlowPushBack(character);
+ SlowPushBack(static_cast<uc16>(character));
}
@@ -72,7 +76,8 @@
buffer_end_ = buffer_ + kBufferSize;
buffer_cursor_ = buffer_end_;
}
- ASSERT(pushback_limit_ > buffer_);
+ // Ensure that there is room for at least one pushback.
+ ASSERT(buffer_cursor_ > buffer_);
ASSERT(pos_ > 0);
buffer_[--buffer_cursor_ - buffer_] = character;
if (buffer_cursor_ == buffer_) {
@@ -85,15 +90,17 @@
bool BufferedUC16CharacterStream::ReadBlock() {
+ buffer_cursor_ = buffer_;
if (pushback_limit_ != NULL) {
- buffer_cursor_ = buffer_;
+ // Leave pushback mode.
buffer_end_ = pushback_limit_;
pushback_limit_ = NULL;
- ASSERT(buffer_cursor_ != buffer_end_);
- return true;
+ // If there were any valid characters left at the
+ // start of the buffer, use those.
+ if (buffer_cursor_ < buffer_end_) return true;
+ // Otherwise read a new block.
}
unsigned length = FillBuffer(pos_, kBufferSize);
- buffer_cursor_ = buffer_;
buffer_end_ = buffer_ + length;
return length > 0;
}
@@ -512,17 +519,30 @@
Token::Value JsonScanner::ScanJsonNumber() {
LiteralScope literal(this);
- if (c0_ == '-') AddLiteralCharAdvance();
+ bool negative = false;
+
+ if (c0_ == '-') {
+ AddLiteralCharAdvance();
+ negative = true;
+ }
if (c0_ == '0') {
AddLiteralCharAdvance();
// Prefix zero is only allowed if it's the only digit before
// a decimal point or exponent.
if ('0' <= c0_ && c0_ <= '9') return Token::ILLEGAL;
} else {
+ int i = 0;
+ int digits = 0;
if (c0_ < '1' || c0_ > '9') return Token::ILLEGAL;
do {
+ i = i * 10 + c0_ - '0';
+ digits++;
AddLiteralCharAdvance();
} while (c0_ >= '0' && c0_ <= '9');
+ if (c0_ != '.' && c0_ != 'e' && c0_ != 'E' && digits < 10) {
+ number_ = (negative ? -i : i);
+ return Token::NUMBER;
+ }
}
if (c0_ == '.') {
AddLiteralCharAdvance();
@@ -540,6 +560,10 @@
} while (c0_ >= '0' && c0_ <= '9');
}
literal.Complete();
+ ASSERT_NOT_NULL(next_.literal_chars);
+ number_ = StringToDouble(next_.literal_chars->ascii_literal(),
+ NO_FLAGS, // Hex, octal or trailing junk.
+ OS::nan_value());
return Token::NUMBER;
}
« no previous file with comments | « src/scanner.h ('k') | src/scanner-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698