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,12 +1194,12 @@ class ParserBase { ...@@ -1194,12 +1194,12 @@ class ParserBase {
// left-hand side of assignments). Although ruled out by ECMA as early errors, // 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. // we allow calls for web compatibility and rewrite them to a runtime throw.
V8_INLINE ExpressionT V8_INLINE ExpressionT
CheckAndRewriteReferenceExpression(ExpressionT expression, int beg_pos, RewriteInvalidReferenceExpression(ExpressionT expression, int beg_pos,
int end_pos, MessageTemplate message); int end_pos, MessageTemplate message);
ExpressionT CheckAndRewriteReferenceExpression(ExpressionT expression, ExpressionT RewriteInvalidReferenceExpression(ExpressionT expression,
int beg_pos, int end_pos, int beg_pos, int end_pos,
MessageTemplate message, MessageTemplate message,
ParseErrorType type); ParseErrorType type);
bool IsValidReferenceExpression(ExpressionT expression); bool IsValidReferenceExpression(ExpressionT expression);
...@@ -2733,9 +2733,11 @@ ParserBase<Impl>::ParseAssignmentExpression() { ...@@ -2733,9 +2733,11 @@ ParserBase<Impl>::ParseAssignmentExpression() {
// assignment pattern-related errors. // assignment pattern-related errors.
Accumulate(~ExpressionClassifier::AssignmentPatternProduction); Accumulate(~ExpressionClassifier::AssignmentPatternProduction);
expression = CheckAndRewriteReferenceExpression( if (V8_UNLIKELY(!IsValidReferenceExpression(expression))) {
expression, lhs_beg_pos, end_position(), expression = RewriteInvalidReferenceExpression(
MessageTemplate::kInvalidLhsInAssignment); expression, lhs_beg_pos, end_position(),
MessageTemplate::kInvalidLhsInAssignment);
}
impl()->MarkExpressionAsAssigned(expression); impl()->MarkExpressionAsAssigned(expression);
Consume(op); Consume(op);
...@@ -2999,9 +3001,11 @@ ParserBase<Impl>::ParsePrefixExpression() { ...@@ -2999,9 +3001,11 @@ ParserBase<Impl>::ParsePrefixExpression() {
CheckStackOverflow(); CheckStackOverflow();
ExpressionT expression = ParseUnaryExpression(); ExpressionT expression = ParseUnaryExpression();
expression = CheckAndRewriteReferenceExpression( if (V8_UNLIKELY(!IsValidReferenceExpression(expression))) {
expression, beg_pos, end_position(), expression = RewriteInvalidReferenceExpression(
MessageTemplate::kInvalidLhsInPrefixOp); expression, beg_pos, end_position(),
MessageTemplate::kInvalidLhsInPrefixOp);
}
impl()->MarkExpressionAsAssigned(expression); impl()->MarkExpressionAsAssigned(expression);
return factory()->NewCountOperation(op, true /* prefix */, expression, return factory()->NewCountOperation(op, true /* prefix */, expression,
...@@ -3067,9 +3071,11 @@ ParserBase<Impl>::ParsePostfixExpression() { ...@@ -3067,9 +3071,11 @@ ParserBase<Impl>::ParsePostfixExpression() {
if (!scanner()->HasLineTerminatorBeforeNext() && Token::IsCountOp(peek())) { if (!scanner()->HasLineTerminatorBeforeNext() && Token::IsCountOp(peek())) {
BindingPatternUnexpectedToken(); BindingPatternUnexpectedToken();
expression = CheckAndRewriteReferenceExpression( if (V8_UNLIKELY(!IsValidReferenceExpression(expression))) {
expression, lhs_beg_pos, end_position(), expression = RewriteInvalidReferenceExpression(
MessageTemplate::kInvalidLhsInPostfixOp); expression, lhs_beg_pos, end_position(),
MessageTemplate::kInvalidLhsInPostfixOp);
}
impl()->MarkExpressionAsAssigned(expression); impl()->MarkExpressionAsAssigned(expression);
Token::Value next = Next(); Token::Value next = Next();
...@@ -4424,21 +4430,20 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( ...@@ -4424,21 +4430,20 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
template <typename Impl> template <typename Impl>
typename ParserBase<Impl>::ExpressionT typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::CheckAndRewriteReferenceExpression(ExpressionT expression, ParserBase<Impl>::RewriteInvalidReferenceExpression(ExpressionT expression,
int beg_pos, int end_pos, int beg_pos, int end_pos,
MessageTemplate message) { MessageTemplate message) {
return CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, return RewriteInvalidReferenceExpression(expression, beg_pos, end_pos,
message, kReferenceError); message, kReferenceError);
} }
template <typename Impl> template <typename Impl>
typename ParserBase<Impl>::ExpressionT typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::CheckAndRewriteReferenceExpression(ExpressionT expression, ParserBase<Impl>::RewriteInvalidReferenceExpression(ExpressionT expression,
int beg_pos, int end_pos, int beg_pos, int end_pos,
MessageTemplate message, MessageTemplate message,
ParseErrorType type) { ParseErrorType type) {
if (V8_LIKELY(IsValidReferenceExpression(expression))) return expression; DCHECK(!IsValidReferenceExpression(expression));
if (impl()->IsIdentifier(expression)) { if (impl()->IsIdentifier(expression)) {
DCHECK(is_strict(language_mode())); DCHECK(is_strict(language_mode()));
DCHECK(impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))); DCHECK(impl()->IsEvalOrArguments(impl()->AsIdentifier(expression)));
...@@ -5557,8 +5562,9 @@ ParserBase<Impl>::ParseForEachStatementWithoutDeclarations( ...@@ -5557,8 +5562,9 @@ ParserBase<Impl>::ParseForEachStatementWithoutDeclarations(
ForInfo* for_info, ZonePtrList<const AstRawString>* labels, ForInfo* for_info, ZonePtrList<const AstRawString>* labels,
ZonePtrList<const AstRawString>* own_labels) { ZonePtrList<const AstRawString>* own_labels) {
// Initializer is reference followed by in/of. // Initializer is reference followed by in/of.
if (!expression->IsValidPattern()) { if (V8_UNLIKELY(!expression->IsValidPattern() &&
expression = CheckAndRewriteReferenceExpression( !IsValidReferenceExpression(expression))) {
expression = RewriteInvalidReferenceExpression(
expression, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, expression, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
kSyntaxError); kSyntaxError);
} }
...@@ -5762,9 +5768,11 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement( ...@@ -5762,9 +5768,11 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement(
ValidateAssignmentPattern(); ValidateAssignmentPattern();
} else { } else {
ValidateExpression(); ValidateExpression();
each_variable = CheckAndRewriteReferenceExpression( if (V8_UNLIKELY(!IsValidReferenceExpression(lhs))) {
lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, each_variable = RewriteInvalidReferenceExpression(
kSyntaxError); lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
kSyntaxError);
}
} }
} }
......
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