Reviewers: arv, Dmitry Lomov (chromium),
Message:
PTAL
Trying to make octal treatment consistent with behaviour in strict mode,
simplify scanning, and produce a better error message.
https://bugs.ecmascript.org/show_bug.cgi?id=3477 and
https://github.com/rwaldron/tc39-notes/blob/b26f950b438b18ac3497fd717dfb2370a84f7fb3/es6/2014-09/sept-23.md#43-legacy-decimal-integer-literals-starting-with-0-and-containing-8-or-9
discuss this a bit
Description:
Simplify scanner and generate better error message for legacy octals in
templates
LOG=N
BUG=
[email protected], [email protected]
Please review this at https://codereview.chromium.org/812163003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+19, -25 lines):
M src/preparser.h
M src/scanner.cc
M test/mjsunit/harmony/templates.js
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
3b221ac09235654af5ff7fe241b6a507e6839df7..44cd0b74f9dfd280bdc2e21614d06b8b8b82cbf4
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2846,6 +2846,7 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT
tag, int start, bool* ok) {
if (peek() == Token::TEMPLATE_TAIL) {
Consume(Token::TEMPLATE_TAIL);
int pos = position();
+ CheckOctalLiteral(pos, peek_position(), CHECK_OK);
typename Traits::TemplateLiteralState ts =
Traits::OpenTemplateLiteral(pos);
Traits::AddTemplateSpan(&ts, true);
return Traits::CloseTemplateLiteral(&ts, start, tag);
@@ -2897,6 +2898,7 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT
tag, int start, bool* ok) {
} while (next == Token::TEMPLATE_SPAN);
DCHECK_EQ(next, Token::TEMPLATE_TAIL);
+ CheckOctalLiteral(pos, peek_position(), CHECK_OK);
// Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral.
return Traits::CloseTemplateLiteral(&ts, start, tag);
}
Index: src/scanner.cc
diff --git a/src/scanner.cc b/src/scanner.cc
index
7cd0895cb3ddb47169b88ed8c1ddf83c3ed4c2a5..d499e9b996dbbf0e8c348e49b0ecb678431fbb13
100644
--- a/src/scanner.cc
+++ b/src/scanner.cc
@@ -733,21 +733,7 @@ bool Scanner::ScanEscape() {
if (c < 0) return false;
break;
}
- case '0':
- if (in_template_literal) {
- // \ 0 DecimalDigit is never allowed in templates.
- if (IsDecimalDigit(c0_)) {
- Advance<capture_raw>(); // Advance to include the problematic
char.
- return false;
- }
-
- // The TV of TemplateCharacter :: \ EscapeSequence is the CV of
- // EscapeSequence.
- // The CV of EscapeSequence :: 0 is the code unit value 0.
- c = 0;
- break;
- }
- // Fall through.
+ case '0': // Fall through.
case '1': // fall through
case '2': // fall through
case '3': // fall through
@@ -755,14 +741,8 @@ bool Scanner::ScanEscape() {
case '5': // fall through
case '6': // fall through
case '7':
- if (!in_template_literal) {
- c = ScanOctalEscape<capture_raw>(c, 2);
- break;
- }
- // Fall through
- case '8':
- case '9':
- if (in_template_literal) return false;
+ c = ScanOctalEscape<capture_raw>(c, 2);
+ break;
}
// According to ECMA-262, section 7.8.4, characters not covered by the
Index: test/mjsunit/harmony/templates.js
diff --git a/test/mjsunit/harmony/templates.js
b/test/mjsunit/harmony/templates.js
index
e2e89dc67f4cf2e74d411bf8f40ffbf021a6bfdc..c339bb8cc7609f0eff03f84b85c790d036559ef1
100644
--- a/test/mjsunit/harmony/templates.js
+++ b/test/mjsunit/harmony/templates.js
@@ -476,9 +476,11 @@ var obj = {
(function testLegacyOctal() {
assertEquals('\u0000', `\0`);
assertEquals('\u0000a', `\0a`);
- for (var i = 0; i < 10; i++) {
+ for (var i = 0; i < 8; i++) {
var code = "`\\0" + i + "`";
assertThrows(code, SyntaxError);
+ code = "(function(){})" + code;
+ assertThrows(code, SyntaxError);
}
assertEquals('\\0', String.raw`\0`);
@@ -488,8 +490,18 @@ var obj = {
(function testSyntaxErrorsNonEscapeCharacter() {
assertThrows("`\\x`", SyntaxError);
assertThrows("`\\u`", SyntaxError);
- for (var i = 1; i < 10; i++) {
+ for (var i = 1; i < 8; i++) {
var code = "`\\" + i + "`";
assertThrows(code, SyntaxError);
+ code = "(function(){})" + code;
+ assertThrows(code, SyntaxError);
}
})();
+
+
+(function testValidNumericEscapes() {
+ assertEquals("8", `\8`);
+ assertEquals("9", `\9`);
+ assertEquals("\u00008", `\08`);
+ assertEquals("\u00009", `\09`);
+})();
--
--
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.