Commit 6b4d7f81 authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

[es6] parse arrow ConciseBody with accept_IN flag

Fixes corner case where arrow function ConciseBody expression does not
accept 'in' in productions.

BUG=v8:4472
LOG=N
R=wingo@igalia.com, adamk@chromium.org, rossberg@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#31271}
parent 0db37104
......@@ -1217,8 +1217,10 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
if (ok) {
checkpoint.Restore(&formals.materialized_literals_count);
// Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should
// not be observable, or else the preparser would have failed.
Expression* expression =
ParseArrowFunctionLiteral(formals, formals_classifier, &ok);
ParseArrowFunctionLiteral(true, formals, formals_classifier, &ok);
if (ok) {
// Scanning must end at the same position that was recorded
// previously. If not, parsing has been interrupted due to a stack
......
......@@ -714,9 +714,10 @@ class ParserBase : public Traits {
ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok);
ExpressionT ParseMemberExpressionContinuation(
ExpressionT expression, ExpressionClassifier* classifier, bool* ok);
ExpressionT ParseArrowFunctionLiteral(
ExpressionT ParseArrowFunctionLiteral(bool accept_IN,
const FormalParametersT& parameters,
const ExpressionClassifier& classifier, bool* ok);
const ExpressionClassifier& classifier,
bool* ok);
ExpressionT ParseTemplateLiteral(ExpressionT tag, int start,
ExpressionClassifier* classifier, bool* ok);
void AddTemplateExpression(ExpressionT);
......@@ -2946,7 +2947,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
duplicate_loc);
}
expression = this->ParseArrowFunctionLiteral(
parameters, arrow_formals_classifier, CHECK_OK);
accept_IN, parameters, arrow_formals_classifier, CHECK_OK);
return expression;
}
......@@ -3882,7 +3883,7 @@ bool ParserBase<Traits>::IsNextLetKeyword() {
template <class Traits>
typename ParserBase<Traits>::ExpressionT
ParserBase<Traits>::ParseArrowFunctionLiteral(
const FormalParametersT& formal_parameters,
bool accept_IN, const FormalParametersT& formal_parameters,
const ExpressionClassifier& formals_classifier, bool* ok) {
if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
// ASI inserts `;` after arrow parameters if a line terminator is found.
......@@ -3940,7 +3941,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
parenthesized_function_ = false;
ExpressionClassifier classifier;
ExpressionT expression =
ParseAssignmentExpression(true, &classifier, CHECK_OK);
ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
ValidateExpression(&classifier, CHECK_OK);
body = this->NewStatementList(1, zone());
this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK);
......
......@@ -3727,6 +3727,14 @@ TEST(ErrorsArrowFunctions) {
static const ParserFlag flags[] = {kAllowLazy};
RunParserSyncTest(context_data, statement_data, kError, flags,
arraysize(flags));
// In a context where a concise arrow body is parsed with [~In] variant,
// ensure that an error is reported in both full parser and preparser.
const char* loop_context_data[][2] = {{"for (", "; 0;);"},
{nullptr, nullptr}};
const char* loop_expr_data[] = {"f => 'key' in {}", nullptr};
RunParserSyncTest(loop_context_data, loop_expr_data, kError, flags,
arraysize(flags));
}
......@@ -3801,6 +3809,15 @@ TEST(NoErrorsArrowFunctions) {
kAllowHarmonyDestructuring};
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
always_flags, arraysize(always_flags));
static const ParserFlag flags[] = {kAllowLazy};
// In a context where a concise arrow body is parsed with [~In] variant,
// ensure that nested expressions can still use the 'in' operator,
const char* loop_context_data[][2] = {{"for (", "; 0;);"},
{nullptr, nullptr}};
const char* loop_expr_data[] = {"f => ('key' in {})", nullptr};
RunParserSyncTest(loop_context_data, loop_expr_data, kSuccess, flags,
arraysize(flags));
}
......
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