Commit 260074ac authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Inline checking part of CheckAndRewriteReferenceExpression

Change-Id: I50320af8484f247656b79beb3195f371635f6797
Reviewed-on: https://chromium-review.googlesource.com/c/1346495Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57699}
parent ccd91026
......@@ -1194,9 +1194,9 @@ class ParserBase {
// left-hand side of assignments). Although ruled out by ECMA as early errors,
// we allow calls for web compatibility and rewrite them to a runtime throw.
V8_INLINE ExpressionT
CheckAndRewriteReferenceExpression(ExpressionT expression, int beg_pos,
RewriteInvalidReferenceExpression(ExpressionT expression, int beg_pos,
int end_pos, MessageTemplate message);
ExpressionT CheckAndRewriteReferenceExpression(ExpressionT expression,
ExpressionT RewriteInvalidReferenceExpression(ExpressionT expression,
int beg_pos, int end_pos,
MessageTemplate message,
ParseErrorType type);
......@@ -2733,9 +2733,11 @@ ParserBase<Impl>::ParseAssignmentExpression() {
// assignment pattern-related errors.
Accumulate(~ExpressionClassifier::AssignmentPatternProduction);
expression = CheckAndRewriteReferenceExpression(
if (V8_UNLIKELY(!IsValidReferenceExpression(expression))) {
expression = RewriteInvalidReferenceExpression(
expression, lhs_beg_pos, end_position(),
MessageTemplate::kInvalidLhsInAssignment);
}
impl()->MarkExpressionAsAssigned(expression);
Consume(op);
......@@ -2999,9 +3001,11 @@ ParserBase<Impl>::ParsePrefixExpression() {
CheckStackOverflow();
ExpressionT expression = ParseUnaryExpression();
expression = CheckAndRewriteReferenceExpression(
if (V8_UNLIKELY(!IsValidReferenceExpression(expression))) {
expression = RewriteInvalidReferenceExpression(
expression, beg_pos, end_position(),
MessageTemplate::kInvalidLhsInPrefixOp);
}
impl()->MarkExpressionAsAssigned(expression);
return factory()->NewCountOperation(op, true /* prefix */, expression,
......@@ -3067,9 +3071,11 @@ ParserBase<Impl>::ParsePostfixExpression() {
if (!scanner()->HasLineTerminatorBeforeNext() && Token::IsCountOp(peek())) {
BindingPatternUnexpectedToken();
expression = CheckAndRewriteReferenceExpression(
if (V8_UNLIKELY(!IsValidReferenceExpression(expression))) {
expression = RewriteInvalidReferenceExpression(
expression, lhs_beg_pos, end_position(),
MessageTemplate::kInvalidLhsInPostfixOp);
}
impl()->MarkExpressionAsAssigned(expression);
Token::Value next = Next();
......@@ -4424,21 +4430,20 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
template <typename Impl>
typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::CheckAndRewriteReferenceExpression(ExpressionT expression,
ParserBase<Impl>::RewriteInvalidReferenceExpression(ExpressionT expression,
int beg_pos, int end_pos,
MessageTemplate message) {
return CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos,
return RewriteInvalidReferenceExpression(expression, beg_pos, end_pos,
message, kReferenceError);
}
template <typename Impl>
typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::CheckAndRewriteReferenceExpression(ExpressionT expression,
ParserBase<Impl>::RewriteInvalidReferenceExpression(ExpressionT expression,
int beg_pos, int end_pos,
MessageTemplate message,
ParseErrorType type) {
if (V8_LIKELY(IsValidReferenceExpression(expression))) return expression;
DCHECK(!IsValidReferenceExpression(expression));
if (impl()->IsIdentifier(expression)) {
DCHECK(is_strict(language_mode()));
DCHECK(impl()->IsEvalOrArguments(impl()->AsIdentifier(expression)));
......@@ -5557,8 +5562,9 @@ ParserBase<Impl>::ParseForEachStatementWithoutDeclarations(
ForInfo* for_info, ZonePtrList<const AstRawString>* labels,
ZonePtrList<const AstRawString>* own_labels) {
// Initializer is reference followed by in/of.
if (!expression->IsValidPattern()) {
expression = CheckAndRewriteReferenceExpression(
if (V8_UNLIKELY(!expression->IsValidPattern() &&
!IsValidReferenceExpression(expression))) {
expression = RewriteInvalidReferenceExpression(
expression, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
kSyntaxError);
}
......@@ -5762,11 +5768,13 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement(
ValidateAssignmentPattern();
} else {
ValidateExpression();
each_variable = CheckAndRewriteReferenceExpression(
if (V8_UNLIKELY(!IsValidReferenceExpression(lhs))) {
each_variable = RewriteInvalidReferenceExpression(
lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
kSyntaxError);
}
}
}
ExpectContextualKeyword(ast_value_factory()->of_string());
int each_keyword_pos = scanner()->location().beg_pos;
......
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