Report SyntaxError on Token::ILLEGAL in ParseTemplateLiteral

BUG=v8:3820, v8:3821
LOG=N
R=arv@chromium.org, dslomov@chromium.org, marja@chromium.org

Review URL: https://codereview.chromium.org/857433004

Cr-Commit-Position: refs/heads/master@{#26132}
This commit is contained in:
caitpotter88 2015-01-19 04:38:01 -08:00 committed by Commit bot
parent 6daecbd5ff
commit 02218adb6b
2 changed files with 36 additions and 2 deletions

View File

@ -2942,11 +2942,17 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) {
do { do {
CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK);
next = peek(); next = peek();
if (!next) { if (next == Token::EOS) {
ReportMessageAt(Scanner::Location(start, peek_position()), ReportMessageAt(Scanner::Location(start, peek_position()),
"unterminated_template"); "unterminated_template");
*ok = false; *ok = false;
return Traits::EmptyExpression(); 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(); int expr_pos = peek_position();
@ -2966,10 +2972,16 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) {
Next(); Next();
pos = position(); pos = position();
if (!next) { if (next == Token::EOS) {
ReportMessageAt(Scanner::Location(start, pos), "unterminated_template"); ReportMessageAt(Scanner::Location(start, pos), "unterminated_template");
*ok = false; *ok = false;
return Traits::EmptyExpression(); 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); Traits::AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL);

View File

@ -4552,6 +4552,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) { TEST(LexicalScopingSloppyMode) {
const char* context_data[][2] = { const char* context_data[][2] = {
{"", ""}, {"", ""},