Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index 9ecf77a9ee5c30a10580ec935ed0b0dc276a590f..7ea9d946f9a6c21286398c8610b5efb287775f67 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -1648,8 +1648,11 @@ class PreParserTraits { |
| ++parameters->arity; |
| } |
| void DeclareFormalParameter(Scope* scope, PreParserIdentifier parameter, |
| - bool is_simple, |
| - ExpressionClassifier* classifier) {} |
| + ExpressionClassifier* classifier) { |
| + if (!classifier->is_simple_parameter_list()) { |
| + scope->SetHasNonSimpleParameters(); |
| + } |
| + } |
| void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
| @@ -1747,8 +1750,8 @@ class PreParser : public ParserBase<PreParserTraits> { |
| // At return, unless an error occurred, the scanner is positioned before the |
| // the final '}'. |
| PreParseResult PreParseLazyFunction( |
| - LanguageMode language_mode, FunctionKind kind, ParserRecorder* log, |
| - Scanner::BookmarkScope* bookmark = nullptr); |
| + LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, |
| + ParserRecorder* log, Scanner::BookmarkScope* bookmark = nullptr); |
| private: |
| friend class PreParserTraits; |
| @@ -2283,6 +2286,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| classifier->RecordExpressionError(scanner()->location(), |
| MessageTemplate::kUnexpectedToken, |
| Token::String(Token::ELLIPSIS)); |
| + classifier->RecordNonSimpleParameter(); |
| Scanner::Location expr_loc = scanner()->peek_location(); |
| Token::Value tok = peek(); |
| result = this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
| @@ -2295,6 +2299,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| return this->EmptyExpression(); |
| } |
| result = factory()->NewSpread(result, ellipsis_pos); |
| + |
| if (peek() == Token::COMMA) { |
| ReportMessageAt(scanner()->peek_location(), |
| MessageTemplate::kParamAfterRest); |
| @@ -2385,6 +2390,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
| this->ParseAssignmentExpression(accept_IN, &binding_classifier, CHECK_OK); |
| classifier->Accumulate(binding_classifier, |
| ExpressionClassifier::AllProductions); |
| + bool is_simple_parameter_list = this->IsIdentifier(result); |
| bool seen_rest = false; |
| while (peek() == Token::COMMA) { |
| if (seen_rest) { |
| @@ -2408,10 +2414,15 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
| ExpressionT right = this->ParseAssignmentExpression( |
| accept_IN, &binding_classifier, CHECK_OK); |
| if (is_rest) right = factory()->NewSpread(right, pos); |
| + is_simple_parameter_list = |
| + is_simple_parameter_list && this->IsIdentifier(right); |
| classifier->Accumulate(binding_classifier, |
| ExpressionClassifier::AllProductions); |
| result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); |
| } |
| + if (!is_simple_parameter_list || seen_rest) { |
| + classifier->RecordNonSimpleParameter(); |
| + } |
| return result; |
| } |
| @@ -2839,7 +2850,6 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| } |
| ExpressionT expression = this->ParseConditionalExpression( |
| accept_IN, &arrow_formals_classifier, CHECK_OK); |
| - |
| if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { |
| BindingPatternUnexpectedToken(classifier); |
| ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
| @@ -2847,7 +2857,10 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); |
| Scope* scope = |
| this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| + bool is_simple = arrow_formals_classifier.is_simple_parameter_list(); |
|
rossberg
2015/08/24 13:11:08
Nit: avoid the extra variable by storing to parame
conradw
2015/08/25 11:31:20
Done.
|
| + if (!is_simple) scope->SetHasNonSimpleParameters(); |
| FormalParametersT parameters(scope); |
| + parameters.is_simple = is_simple; |
| checkpoint.Restore(¶meters.materialized_literals_count); |
| scope->set_start_position(lhs_beg_pos); |
| @@ -3661,6 +3674,7 @@ void ParserBase<Traits>::ParseFormalParameter( |
| return; |
| } |
| parameters->is_simple = false; |
| + classifier->RecordNonSimpleParameter(); |
| } |
| ExpressionT initializer = Traits::EmptyExpression(); |
| @@ -3671,6 +3685,7 @@ void ParserBase<Traits>::ParseFormalParameter( |
| ValidateExpression(&init_classifier, ok); |
| if (!*ok) return; |
| parameters->is_simple = false; |
| + classifier->RecordNonSimpleParameter(); |
| } |
| Traits::AddFormalParameter(parameters, pattern, initializer, is_rest); |
| @@ -3711,6 +3726,7 @@ void ParserBase<Traits>::ParseFormalParameterList( |
| if (parameters->has_rest) { |
| parameters->is_simple = false; |
| + classifier->RecordNonSimpleParameter(); |
| if (peek() == Token::COMMA) { |
| ReportMessageAt(scanner()->peek_location(), |
| MessageTemplate::kParamAfterRest); |
| @@ -3722,8 +3738,7 @@ void ParserBase<Traits>::ParseFormalParameterList( |
| for (int i = 0; i < parameters->Arity(); ++i) { |
| auto parameter = parameters->at(i); |
| - Traits::DeclareFormalParameter( |
| - parameters->scope, parameter, parameters->is_simple, classifier); |
| + Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); |
| } |
| } |