[parser] Add DCHECKs and remove no-ops from destructuring assignment rewriting

After f1a551800f, we no longer have to
deal with a case where we rewrite destructuring assignments belonging
to some inner function. Remove a bit of code and add DCHECKs to reflect
that fact.

Change-Id: I7553e86d4ae2f6290853eee38f85d2f243b778a9
Reviewed-on: https://chromium-review.googlesource.com/922893
Reviewed-by: Marja Hölttä <marja@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51404}
This commit is contained in:
Adam Klein 2018-02-15 17:55:53 -08:00 committed by Commit Bot
parent 1cee6bfebb
commit 0f617ada3e

View File

@ -905,8 +905,9 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
scope->set_start_position(info->start_position());
ExpressionClassifier formals_classifier(this);
ParserFormalParameters formals(scope);
int rewritable_length =
function_state.destructuring_assignments_to_rewrite().length();
// The outer FunctionState should not contain destructuring assignments.
DCHECK_EQ(0,
function_state.destructuring_assignments_to_rewrite().length());
{
// Parsing patterns as variable reference expression creates
// NewUnresolved references in current scope. Enter arrow function
@ -944,8 +945,12 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
// Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should
// not be observable, or else the preparser would have failed.
Expression* expression =
ParseArrowFunctionLiteral(true, formals, rewritable_length, &ok);
const bool accept_IN = true;
// Any destructuring assignments in the current FunctionState
// actually belong to the arrow function itself.
const int rewritable_length = 0;
Expression* expression = ParseArrowFunctionLiteral(
accept_IN, formals, rewritable_length, &ok);
if (ok) {
// Scanning must end at the same position that was recorded
// previously. If not, parsing has been interrupted due to a stack
@ -958,10 +963,6 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
// must produce a FunctionLiteral.
DCHECK(expression->IsFunctionLiteral());
result = expression->AsFunctionLiteral();
// Rewrite destructuring assignments in the parameters. (The ones
// inside the function body are rewritten by
// ParseArrowFunctionLiteral.)
RewriteDestructuringAssignments();
} else {
ok = false;
}
@ -3887,6 +3888,9 @@ void Parser::RewriteDestructuringAssignments() {
// pair.scope may already have been removed by FinalizeBlockScope in the
// meantime.
Scope* scope = to_rewrite->scope()->GetUnremovedScope();
// Scope at the time of the rewriting and the original parsing
// should be in the same function.
DCHECK(scope->GetClosureScope() == scope_->GetClosureScope());
BlockState block_state(&scope_, scope);
RewriteDestructuringAssignment(to_rewrite);
}