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

Unified Diff: src/scanner.cc

Issue 768203002: Simplify template literal raw string creation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add DCHECK in PushBack and remove some unused functions Created 6 years 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
Index: src/scanner.cc
diff --git a/src/scanner.cc b/src/scanner.cc
index 3214c6f1c765ac9005d77179b2014224e3190641..3ab92f5e258e50ca725ef455fbc5cb544d692861 100644
--- a/src/scanner.cc
+++ b/src/scanner.cc
@@ -34,6 +34,7 @@ Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const {
Scanner::Scanner(UnicodeCache* unicode_cache)
: unicode_cache_(unicode_cache),
+ capturing_raw_literal_(false),
octal_pos_(Location::invalid()),
harmony_scoping_(false),
harmony_modules_(false),
@@ -403,6 +404,7 @@ Token::Value Scanner::ScanHtmlComment() {
void Scanner::Scan() {
next_.literal_chars = NULL;
+ next_.raw_literal_chars = NULL;
Token::Value token;
do {
// Remember the position of the next token
@@ -802,15 +804,18 @@ Token::Value Scanner::ScanTemplateSpan() {
DCHECK(c0_ == '`' || c0_ == '}');
Advance(); // Consume ` or }
- LiteralScope literal(this);
+ LiteralScope literal(this, true);
+
while (true) {
uc32 c = c0_;
Advance();
if (c == '`') {
result = Token::TEMPLATE_TAIL;
+ ReduceRawLiteralLength(1);
break;
} else if (c == '$' && c0_ == '{') {
Advance(); // Consume '{'
+ ReduceRawLiteralLength(2);
break;
} else if (c == '\\') {
if (unicode_cache_->IsLineTerminator(c0_)) {
@@ -818,7 +823,14 @@ Token::Value Scanner::ScanTemplateSpan() {
// code unit sequence.
uc32 lastChar = c0_;
Advance();
- if (lastChar == '\r' && c0_ == '\n') Advance();
+ if (lastChar == '\r') {
+ ReduceRawLiteralLength(1); // Remove \r
+ if (c0_ == '\n') {
+ Advance(); // Adds \n
+ } else {
+ AddRawLiteralChar('\n');
+ }
+ }
} else if (c0_ == '0') {
Advance();
AddLiteralChar('0');
@@ -834,7 +846,12 @@ Token::Value Scanner::ScanTemplateSpan() {
// The TRV of LineTerminatorSequence :: <CR><LF> is the sequence
// consisting of the CV 0x000A.
if (c == '\r') {
- if (c0_ == '\n') Advance();
+ ReduceRawLiteralLength(1); // Remove \r
+ if (c0_ == '\n') {
+ Advance(); // Adds \n
+ } else {
+ AddRawLiteralChar('\n');
+ }
c = '\n';
}
AddLiteralChar(c);
@@ -1248,6 +1265,15 @@ const AstRawString* Scanner::NextSymbol(AstValueFactory* ast_value_factory) {
}
+const AstRawString* Scanner::CurrentRawSymbol(
+ AstValueFactory* ast_value_factory) {
+ if (is_raw_literal_one_byte()) {
+ return ast_value_factory->GetOneByteString(raw_literal_one_byte_string());
+ }
+ return ast_value_factory->GetTwoByteString(raw_literal_two_byte_string());
+}
+
+
double Scanner::DoubleValue() {
DCHECK(is_literal_one_byte());
return StringToDouble(
« src/scanner.h ('K') | « src/scanner.h ('k') | test/mjsunit/harmony/templates.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698