Commit dd065511 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Delay validating formal parameter initializers

No-Tree-Checks: true
No-Try: true
Change-Id: If9e39eb64db24e7d7dd2ae639d95f750aef04210
Reviewed-on: https://chromium-review.googlesource.com/c/1350119
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57817}
parent ea82d931
......@@ -2607,14 +2607,6 @@ ParserBase<Impl>::ParseAssignmentExpression() {
// Arrow functions.
if (V8_UNLIKELY(op == Token::ARROW)) {
ValidateArrowFormalParameters(expression);
// This reads strangely, but is correct: it checks whether any
// sub-expression of the parameter list failed to be a valid formal
// parameter initializer. Since YieldExpressions are banned anywhere
// in an arrow parameter list, this is correct.
// TODO(adamk): Rename "FormalParameterInitializerError" to refer to
// "YieldExpression", which is its only use.
ValidateFormalParameterInitializer();
Scanner::Location loc(lhs_beg_pos, end_position());
DeclarationScope* scope = NewFunctionScope(next_arrow_function_kind_);
......@@ -3042,8 +3034,6 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) {
ParseArguments(&args, &has_spread, true);
if (V8_LIKELY(peek() == Token::ARROW)) {
fni_.RemoveAsyncKeywordFromEnd();
ValidatePattern();
ValidateFormalParameterInitializer();
if (!classifier()->is_valid_async_arrow_formal_parameters()) {
ReportClassifierError(
classifier()->async_arrow_formal_parameters_error());
......@@ -3429,7 +3419,6 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters) {
ExpressionT pattern = ParseBindingPattern();
if (!impl()->IsIdentifier(pattern)) {
parameters->is_simple = false;
ValidateFormalParameterInitializer();
}
ExpressionT initializer = impl()->NullExpression();
......@@ -3443,8 +3432,8 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters) {
AcceptINScope scope(this, true);
initializer = ParseAssignmentExpression();
ValidateExpression();
ValidateFormalParameterInitializer();
parameters->is_simple = false;
Accumulate(ExpressionClassifier::FormalParameterInitializerProduction);
}
classifier()->RecordNonSimpleParameter();
impl()->SetFunctionNameFromIdentifierRef(initializer, pattern);
......
......@@ -910,6 +910,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
}
V8_INLINE void DeclareFormalParameters(ParserFormalParameters* parameters) {
ValidateFormalParameterInitializer();
bool is_simple = parameters->is_simple;
DeclarationScope* scope = parameters->scope;
if (!is_simple) scope->SetHasNonSimpleParameters();
......
......@@ -1666,12 +1666,14 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE void DeclareFormalParameters(
const PreParserFormalParameters* parameters) {
ValidateFormalParameterInitializer();
if (!parameters->is_simple) parameters->scope->SetHasNonSimpleParameters();
}
V8_INLINE void DeclareArrowFunctionFormalParameters(
PreParserFormalParameters* parameters, const PreParserExpression& params,
const Scanner::Location& params_loc) {
ValidateFormalParameterInitializer();
if (params.variables_ != nullptr) {
Scope* scope = parameters->scope;
for (auto variable : *params.variables_) {
......
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