Reviewers: caitp, Dmitry Lomov (chromium),
Message:
PTAL
Description:
ES6 template literals should not use legacy octal strings
BUG=v8:3736
LOG=Y
[email protected], [email protected]
Please review this at https://codereview.chromium.org/811113002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+23, -9 lines):
M src/scanner.h
M src/scanner.cc
M test/mjsunit/harmony/templates.js
Index: src/scanner.cc
diff --git a/src/scanner.cc b/src/scanner.cc
index
96459f3c6699ec07f5b3a73db6defd5665dc791e..1e259bdd310604c958e33726f022b3270b8e17b1
100644
--- a/src/scanner.cc
+++ b/src/scanner.cc
@@ -697,13 +697,13 @@ void Scanner::SeekForward(int pos) {
}
-template <bool capture_raw>
+template <bool capture_raw, bool in_template_literal>
bool Scanner::ScanEscape() {
uc32 c = c0_;
Advance<capture_raw>();
// Skip escaped newlines.
- if (c0_ >= 0 && unicode_cache_->IsLineTerminator(c)) {
+ if (!in_template_literal && c0_ >= 0 &&
unicode_cache_->IsLineTerminator(c)) {
// Allow CR+LF newlines in multiline string literals.
if (IsCarriageReturn(c) && IsLineFeed(c0_)) Advance<capture_raw>();
// Allow LF+CR newlines in multiline string literals.
@@ -739,7 +739,9 @@ bool Scanner::ScanEscape() {
case '5' : // fall through
case '6' : // fall through
case '7':
- c = ScanOctalEscape<capture_raw>(c, 2);
+ if (!in_template_literal) {
+ c = ScanOctalEscape<capture_raw>(c, 2);
+ }
break;
}
@@ -787,7 +789,7 @@ Token::Value Scanner::ScanString() {
uc32 c = c0_;
Advance();
if (c == '\\') {
- if (c0_ < 0 || !ScanEscape<false>()) return Token::ILLEGAL;
+ if (c0_ < 0 || !ScanEscape<false, false>()) return Token::ILLEGAL;
} else {
AddLiteralChar(c);
}
@@ -818,6 +820,7 @@ Token::Value Scanner::ScanTemplateSpan() {
LiteralScope literal(this);
StartRawLiteral();
const bool capture_raw = true;
+ const bool in_template_literal = true;
while (true) {
uc32 c = c0_;
@@ -844,11 +847,8 @@ Token::Value Scanner::ScanTemplateSpan() {
AddRawLiteralChar('\n');
}
}
- } else if (c0_ == '0') {
- Advance<capture_raw>();
- AddLiteralChar('0');
} else {
- ScanEscape<true>();
+ ScanEscape<capture_raw, in_template_literal>();
}
} else if (c < 0) {
// Unterminated template literal
Index: src/scanner.h
diff --git a/src/scanner.h b/src/scanner.h
index
d96ed579b070ecc6e83de670fc789084f1ac5ef1..6e668fd4921ca23e7dbbcd1755404c8269c20bd7
100644
--- a/src/scanner.h
+++ b/src/scanner.h
@@ -677,8 +677,9 @@ class Scanner {
// Scans an escape-sequence which is part of a string and adds the
// decoded character to the current literal. Returns true if a pattern
// is scanned.
- template <bool capture_raw>
+ template <bool capture_raw, bool in_template_literal>
bool ScanEscape();
+
// Decodes a Unicode escape-sequence which is part of an identifier.
// If the escape sequence cannot be decoded the result is kBadChar.
uc32 ScanIdentifierUnicodeEscape();
Index: test/mjsunit/harmony/templates.js
diff --git a/test/mjsunit/harmony/templates.js
b/test/mjsunit/harmony/templates.js
index
86caf453a5c998f7cb6f9cabdde145aba400ad2d..5350c64f0500cd40d300d4946d07811fba9bcf8f
100644
--- a/test/mjsunit/harmony/templates.js
+++ b/test/mjsunit/harmony/templates.js
@@ -471,3 +471,16 @@ var obj = {
// block
}`jkl`;
})();
+
+
+(function testLegacyOctal() {
+ assertEquals('0', `\0`);
+ assertEquals('01', `\01`);
+ assertEquals('012', `\012`);
+ assertEquals('123', `\123`);
+
+ assertEquals('\\0', String.raw`\0`);
+ assertEquals('\\01', String.raw`\01`);
+ assertEquals('\\012', String.raw`\012`);
+ assertEquals('\\123', String.raw`\123`);
+})();
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.