Commit 5ac88053 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Make it explicit when marking destructuring patterns as assigned

Divide MarkExpressionAsAssigned into MarkExpressionAsAssigned and
MarkPatternAsAssigned so it's clear when we need to mark just a single variable
or an entire destructuring assignment pattern.

Change-Id: Ia188b3d9b15944a1859676f483df229225ce8404
Reviewed-on: https://chromium-review.googlesource.com/c/1270945
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56505}
parent 2293f880
......@@ -2950,14 +2950,14 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN, bool* ok) {
if (is_destructuring_assignment) {
ValidateAssignmentPattern(CHECK_OK);
impl()->MarkPatternAsAssigned(expression);
} else {
expression = CheckAndRewriteReferenceExpression(
expression, lhs_beg_pos, end_position(),
MessageTemplate::kInvalidLhsInAssignment, CHECK_OK);
impl()->MarkExpressionAsAssigned(expression);
}
impl()->MarkExpressionAsAssigned(expression);
Token::Value op = Next(); // Get assignment operator.
if (op != Token::ASSIGN) {
classifier()->RecordPatternError(scanner()->location(),
......
......@@ -710,6 +710,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
}
}
V8_INLINE static void MarkPatternAsAssigned(Expression* expression) {}
// Determine if the expression is a variable proxy and mark it as being used
// in an assignment or with a increment/decrement operator.
V8_INLINE static void MarkExpressionAsAssigned(Expression* expression) {
......
......@@ -1373,8 +1373,7 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
const PreParserExpression& left, const PreParserExpression& right) {}
V8_INLINE void MarkExpressionAsAssigned(
const PreParserExpression& expression) {
V8_INLINE void MarkPatternAsAssigned(const PreParserExpression& expression) {
// TODO(marja): To be able to produce the same errors, the preparser needs
// to start tracking which expressions are variables and which are assigned.
if (expression.variables_ != nullptr) {
......@@ -1384,6 +1383,15 @@ class PreParser : public ParserBase<PreParser> {
}
}
V8_INLINE void MarkExpressionAsAssigned(
const PreParserExpression& expression) {
if (IsIdentifier(expression)) {
DCHECK_NOT_NULL(expression.variables_);
DCHECK_EQ(1, expression.variables_->LengthForTest());
expression.variables_->first()->set_is_assigned();
}
}
V8_INLINE bool ShortcutNumericLiteralBinaryExpression(
PreParserExpression* x, const PreParserExpression& y, Token::Value op,
int pos) {
......@@ -1416,7 +1424,7 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE PreParserStatement InitializeForEachStatement(
PreParserStatement stmt, const PreParserExpression& each,
const PreParserExpression& subject, PreParserStatement body) {
MarkExpressionAsAssigned(each);
MarkPatternAsAssigned(each);
return stmt;
}
......@@ -1425,7 +1433,7 @@ class PreParser : public ParserBase<PreParser> {
const PreParserExpression& iterable, PreParserStatement body,
bool finalize, IteratorType type,
int next_result_pos = kNoSourcePosition) {
MarkExpressionAsAssigned(each);
MarkPatternAsAssigned(each);
return stmt;
}
......
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