Reviewers: Dmitry Lomov (chromium),
Description:
Version 4.1.0.11 (cherry-pick)
Merged 02218adb6b310e1631f54dcc9d8643e4981e8a3c
Report SyntaxError on Token::ILLEGAL in ParseTemplateLiteral
BUG=v8:3820,v8:3821
LOG=N
[email protected]
Please review this at https://codereview.chromium.org/861173005/
Base URL: https://chromium.googlesource.com/v8/[email protected]
Affected files (+37, -3 lines):
M src/preparser.h
M src/version.cc
M test/cctest/test-parsing.cc
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
18004a5096d4c20f0ea81470c4a2f69681289fbb..e3868ff665a088efa431b4ba025fb82cf3d3d3e0
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2875,11 +2875,17 @@
ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool*
ok) {
do {
next = peek();
- if (!next) {
+ if (next == Token::EOS) {
ReportMessageAt(Scanner::Location(start, peek_position()),
"unterminated_template");
*ok = false;
return Traits::EmptyExpression();
+ } else if (next == Token::ILLEGAL) {
+ Traits::ReportMessageAt(
+ Scanner::Location(position() + 1, peek_position()),
+ "unexpected_token", "ILLEGAL", false);
+ *ok = false;
+ return Traits::EmptyExpression();
}
int expr_pos = peek_position();
@@ -2898,11 +2904,17 @@
ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool*
ok) {
next = scanner()->ScanTemplateContinuation();
Next();
- if (!next) {
+ if (next == Token::EOS) {
ReportMessageAt(Scanner::Location(start, position()),
"unterminated_template");
*ok = false;
return Traits::EmptyExpression();
+ } else if (next == Token::ILLEGAL) {
+ Traits::ReportMessageAt(
+ Scanner::Location(position() + 1, peek_position()),
+ "unexpected_token", "ILLEGAL", false);
+ *ok = false;
+ return Traits::EmptyExpression();
}
Traits::AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL);
Index: src/version.cc
diff --git a/src/version.cc b/src/version.cc
index
cd259f8306e0c134660dc686d3414403531c66d3..170a0c9e7ff65cfd3893e6f67e9225c6a1416deb
100644
--- a/src/version.cc
+++ b/src/version.cc
@@ -35,7 +35,7 @@
#define MAJOR_VERSION 4
#define MINOR_VERSION 1
#define BUILD_NUMBER 0
-#define PATCH_LEVEL 10
+#define PATCH_LEVEL 11
// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
#define IS_CANDIDATE_VERSION 0
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index
ef6b5d30c497550b5536b5831ef4d110fe915ab8..08caeab55f502954277b53376a08ab8a885f5170
100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -4549,6 +4549,28 @@ TEST(ScanUnterminatedTemplateLiterals) {
}
+TEST(TemplateLiteralsIllegalTokens) {
+ const char* context_data[][2] = {{"'use strict';", ""},
+ {"function foo(){ 'use strict';"
+ " var a, b, c; return ", "}"},
+ {NULL, NULL}};
+ const char* data[] = {
+ "`hello\\x`",
+ "`hello\\x${1}`",
+ "`hello${1}\\x`",
+ "`hello${1}\\x${2}`",
+ "`hello\\x\n`",
+ "`hello\\x\n${1}`",
+ "`hello${1}\\x\n`",
+ "`hello${1}\\x\n${2}`",
+ NULL};
+
+ static const ParserFlag always_flags[] = {kAllowHarmonyTemplates};
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
TEST(LexicalScopingSloppyMode) {
const char* context_data[][2] = {
{"", ""},
--
--
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.