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

Reland "[scanner] Simplify TemplateSpan raw literal character handling"

This is a reland of c1226cea1ec11d5b766226c912c475647a731274

Original change's description:
> [scanner] Simplify TemplateSpan raw literal character handling
> 
> Instead of adding and removing literal chars, only add raw literal characters when we have to and never remove them.
> 
> Change-Id: Ib604c8c9fb69a96708eec3a03de102e0668c01d7
> Reviewed-on: https://chromium-review.googlesource.com/1167505
> Reviewed-by: Marja Hölttä <marja@chromium.org>
> Reviewed-by: Caitlin Potter <caitp@igalia.com>
> Commit-Queue: Toon Verwaest <verwaest@chromium.org>

Change-Id: Ia15501d75c3beaf336e90a80e0abb738f696ef9e
Reviewed-on: https://chromium-review.googlesource.com/1170604Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55040}
parent 1413f07b
......@@ -1059,30 +1059,27 @@ Token::Value Scanner::ScanTemplateSpan() {
const bool in_template_literal = true;
while (true) {
uc32 c = c0_;
Advance<capture_raw>();
Advance();
if (c == '`') {
result = Token::TEMPLATE_TAIL;
ReduceRawLiteralLength(1);
break;
} else if (c == '$' && c0_ == '{') {
Advance<capture_raw>(); // Consume '{'
ReduceRawLiteralLength(2);
Advance(); // Consume '{'
break;
} else if (c == '\\') {
DCHECK(!unibrow::IsLineTerminator(kEndOfInput));
if (capture_raw) AddRawLiteralChar('\\');
if (unibrow::IsLineTerminator(c0_)) {
// The TV of LineContinuation :: \ LineTerminatorSequence is the empty
// code unit sequence.
uc32 lastChar = c0_;
Advance<capture_raw>();
Advance();
if (lastChar == '\r') {
ReduceRawLiteralLength(1); // Remove \r
if (c0_ == '\n') {
Advance<capture_raw>(); // Adds \n
} else {
AddRawLiteralChar('\n');
}
// Also skip \n.
if (c0_ == '\n') Advance();
lastChar = '\n';
}
if (capture_raw) AddRawLiteralChar(lastChar);
} else {
bool success = ScanEscape<capture_raw, in_template_literal>();
USE(success);
......@@ -1101,14 +1098,10 @@ Token::Value Scanner::ScanTemplateSpan() {
// The TRV of LineTerminatorSequence :: <CR><LF> is the sequence
// consisting of the CV 0x000A.
if (c == '\r') {
ReduceRawLiteralLength(1); // Remove \r
if (c0_ == '\n') {
Advance<capture_raw>(); // Adds \n
} else {
AddRawLiteralChar('\n');
}
if (c0_ == '\n') Advance(); // Skip \n
c = '\n';
}
if (capture_raw) AddRawLiteralChar(c);
AddLiteralChar(c);
}
}
......
......@@ -311,10 +311,6 @@ class Scanner {
int length() const { return is_one_byte_ ? position_ : (position_ >> 1); }
void ReduceLength(int delta) {
position_ -= delta * (is_one_byte_ ? kOneByteSize : kUC16Size);
}
void Reset() {
position_ = 0;
is_one_byte_ = true;
......@@ -461,11 +457,6 @@ class Scanner {
next_.raw_literal_chars->AddChar(c);
}
V8_INLINE void ReduceRawLiteralLength(int delta) {
DCHECK_NOT_NULL(next_.raw_literal_chars);
next_.raw_literal_chars->ReduceLength(delta);
}
// Stops scanning of a literal and drop the collected characters,
// e.g., due to an encountered error.
inline void DropLiteral() {
......
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