Commit 40b06bc4 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Make IsValidPattern a range-check over Object/Array literal

Change-Id: I53fc5b8ff39c91fe509e292cf32f54ff4f8e2eb7
Reviewed-on: https://chromium-review.googlesource.com/c/1335694
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57508}
parent 96cf8476
......@@ -250,6 +250,11 @@ class Expression : public AstNode {
bool IsCompileTimeValue();
bool IsValidPattern() {
STATIC_ASSERT(kObjectLiteral + 1 == kArrayLiteral);
return IsInRange(node_type(), kObjectLiteral, kArrayLiteral);
}
protected:
Expression(int pos, NodeType type) : AstNode(pos, type) {}
......
......@@ -1211,10 +1211,6 @@ class ParserBase {
return true;
}
bool IsValidPattern(ExpressionT expression) {
return expression->IsObjectLiteral() || expression->IsArrayLiteral();
}
// Due to hoisting, the value of a 'var'-declared variable may actually change
// even if the code contains only the "initial" assignment, namely when that
// assignment occurs inside a loop. For example:
......@@ -2689,7 +2685,7 @@ ParserBase<Impl>::ParseAssignmentExpression() {
}
// Destructuring assignmment.
if (V8_UNLIKELY(IsValidPattern(expression) && op == Token::ASSIGN)) {
if (V8_UNLIKELY(expression->IsValidPattern() && op == Token::ASSIGN)) {
ValidateAssignmentPattern();
// This is definitely not an expression so don't accumulate
......@@ -4453,7 +4449,7 @@ bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) {
template <typename Impl>
void ParserBase<Impl>::CheckDestructuringElement(ExpressionT expression,
int begin, int end) {
if (!IsValidPattern(expression) && !expression->IsAssignment() &&
if (!expression->IsValidPattern() && !expression->IsAssignment() &&
!IsValidReferenceExpression(expression)) {
if (expression->IsProperty()) ValidateExpression();
classifier()->RecordAssignmentPatternError(
......
......@@ -236,6 +236,12 @@ class PreParserExpression {
return TypeField::decode(code_) == kArrayLiteralExpression;
}
bool IsValidPattern() const {
STATIC_ASSERT(kObjectLiteralExpression + 1 == kArrayLiteralExpression);
return IsInRange(TypeField::decode(code_),
kObjectLiteralExpression, kArrayLiteralExpression);
}
bool IsStringLiteral() const {
return TypeField::decode(code_) == kStringLiteralExpression;
}
......
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