Commit 26b47aaf authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Simplify detecting async arrow functions

Change-Id: I448110b10bb4dafdfb05983db92e06383c2913a3
Reviewed-on: https://chromium-review.googlesource.com/c/1280203Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56628}
parent cddf5bbd
...@@ -1037,7 +1037,7 @@ class ParserBase { ...@@ -1037,7 +1037,7 @@ class ParserBase {
ExpressionT ParseRegExpLiteral(bool* ok); ExpressionT ParseRegExpLiteral(bool* ok);
ExpressionT ParseBindingPattern(bool* ok); ExpressionT ParseBindingPattern(bool* ok);
ExpressionT ParsePrimaryExpression(bool* is_async, bool* ok); ExpressionT ParsePrimaryExpression(bool* ok);
// Use when parsing an expression that is known to not be a pattern or part // Use when parsing an expression that is known to not be a pattern or part
// of a pattern. // of a pattern.
...@@ -1096,14 +1096,12 @@ class ParserBase { ...@@ -1096,14 +1096,12 @@ class ParserBase {
V8_INLINE ExpressionT ParseUnaryExpression(bool* ok); V8_INLINE ExpressionT ParseUnaryExpression(bool* ok);
V8_INLINE ExpressionT ParsePostfixExpression(bool* ok); V8_INLINE ExpressionT ParsePostfixExpression(bool* ok);
V8_INLINE ExpressionT ParseLeftHandSideExpression(bool* ok); V8_INLINE ExpressionT ParseLeftHandSideExpression(bool* ok);
ExpressionT ParseMemberWithPresentNewPrefixesExpression(bool* is_async, ExpressionT ParseMemberWithPresentNewPrefixesExpression(bool* ok);
bool* ok); V8_INLINE ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok);
V8_INLINE ExpressionT ParseMemberWithNewPrefixesExpression(bool* is_async,
bool* ok);
ExpressionT ParseFunctionExpression(bool* ok); ExpressionT ParseFunctionExpression(bool* ok);
V8_INLINE ExpressionT ParseMemberExpression(bool* is_async, bool* ok); V8_INLINE ExpressionT ParseMemberExpression(bool* ok);
V8_INLINE ExpressionT ParseMemberExpressionContinuation( V8_INLINE ExpressionT
ExpressionT expression, bool* is_async, bool* ok); ParseMemberExpressionContinuation(ExpressionT expression, bool* ok);
// `rewritable_length`: length of the destructuring_assignments_to_rewrite() // `rewritable_length`: length of the destructuring_assignments_to_rewrite()
// queue in the parent function state, prior to parsing of formal parameters. // queue in the parent function state, prior to parsing of formal parameters.
...@@ -1753,7 +1751,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBindingPattern( ...@@ -1753,7 +1751,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBindingPattern(
template <typename Impl> template <typename Impl>
typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
bool* is_async, bool* ok) { bool* ok) {
// PrimaryExpression :: // PrimaryExpression ::
// 'this' // 'this'
// 'null' // 'null'
...@@ -1806,7 +1804,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( ...@@ -1806,7 +1804,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
return ParseAsyncFunctionLiteral(ok); return ParseAsyncFunctionLiteral(ok);
} }
// CoverCallExpressionAndAsyncArrowHead // CoverCallExpressionAndAsyncArrowHead
*is_async = true;
V8_FALLTHROUGH; V8_FALLTHROUGH;
case Token::IDENTIFIER: case Token::IDENTIFIER:
case Token::LET: case Token::LET:
...@@ -3245,9 +3242,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) { ...@@ -3245,9 +3242,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) {
// LeftHandSideExpression :: // LeftHandSideExpression ::
// (NewExpression | MemberExpression) ... // (NewExpression | MemberExpression) ...
bool is_async = false; ExpressionT result = ParseMemberWithNewPrefixesExpression(CHECK_OK);
ExpressionT result =
ParseMemberWithNewPrefixesExpression(&is_async, CHECK_OK);
while (true) { while (true) {
switch (peek()) { switch (peek()) {
...@@ -3291,7 +3286,8 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) { ...@@ -3291,7 +3286,8 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) {
} }
Scanner::Location spread_pos; Scanner::Location spread_pos;
ExpressionListT args; ExpressionListT args;
if (V8_UNLIKELY(is_async && impl()->IsIdentifier(result))) { if (impl()->IsIdentifier(result) &&
impl()->IsAsync(impl()->AsIdentifier(result))) {
ExpressionClassifier async_classifier(this); ExpressionClassifier async_classifier(this);
bool is_simple_parameter_list = true; bool is_simple_parameter_list = true;
args = ParseArguments(&spread_pos, true, &is_simple_parameter_list, args = ParseArguments(&spread_pos, true, &is_simple_parameter_list,
...@@ -3372,8 +3368,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) { ...@@ -3372,8 +3368,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) {
template <typename Impl> template <typename Impl>
typename ParserBase<Impl>::ExpressionT typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* is_async, ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* ok) {
bool* ok) {
// NewExpression :: // NewExpression ::
// ('new')+ MemberExpression // ('new')+ MemberExpression
// //
...@@ -3408,11 +3403,10 @@ ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* is_async, ...@@ -3408,11 +3403,10 @@ ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* is_async,
*ok = false; *ok = false;
return impl()->NullExpression(); return impl()->NullExpression();
} else if (peek() == Token::PERIOD) { } else if (peek() == Token::PERIOD) {
*is_async = false;
result = ParseNewTargetExpression(CHECK_OK); result = ParseNewTargetExpression(CHECK_OK);
return ParseMemberExpressionContinuation(result, is_async, ok); return ParseMemberExpressionContinuation(result, ok);
} else { } else {
result = ParseMemberWithNewPrefixesExpression(is_async, CHECK_OK); result = ParseMemberWithNewPrefixesExpression(CHECK_OK);
} }
ValidateExpression(CHECK_OK); ValidateExpression(CHECK_OK);
if (peek() == Token::LPAREN) { if (peek() == Token::LPAREN) {
...@@ -3426,7 +3420,7 @@ ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* is_async, ...@@ -3426,7 +3420,7 @@ ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* is_async,
result = factory()->NewCallNew(result, args, new_pos); result = factory()->NewCallNew(result, args, new_pos);
} }
// The expression can still continue with . or [ after the arguments. // The expression can still continue with . or [ after the arguments.
return ParseMemberExpressionContinuation(result, is_async, ok); return ParseMemberExpressionContinuation(result, ok);
} }
// NewExpression without arguments. // NewExpression without arguments.
return factory()->NewCallNew(result, impl()->NewExpressionList(0), new_pos); return factory()->NewCallNew(result, impl()->NewExpressionList(0), new_pos);
...@@ -3434,11 +3428,9 @@ ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* is_async, ...@@ -3434,11 +3428,9 @@ ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* is_async,
template <typename Impl> template <typename Impl>
typename ParserBase<Impl>::ExpressionT typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::ParseMemberWithNewPrefixesExpression(bool* is_async, ParserBase<Impl>::ParseMemberWithNewPrefixesExpression(bool* ok) {
bool* ok) { return peek() == Token::NEW ? ParseMemberWithPresentNewPrefixesExpression(ok)
return peek() == Token::NEW : ParseMemberExpression(ok);
? ParseMemberWithPresentNewPrefixesExpression(is_async, ok)
: ParseMemberExpression(is_async, ok);
} }
template <typename Impl> template <typename Impl>
...@@ -3484,7 +3476,7 @@ ParserBase<Impl>::ParseFunctionExpression(bool* ok) { ...@@ -3484,7 +3476,7 @@ ParserBase<Impl>::ParseFunctionExpression(bool* ok) {
template <typename Impl> template <typename Impl>
typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression( typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression(
bool* is_async, bool* ok) { bool* ok) {
// MemberExpression :: // MemberExpression ::
// (PrimaryExpression | FunctionLiteral | ClassLiteral) // (PrimaryExpression | FunctionLiteral | ClassLiteral)
// ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)*
...@@ -3507,10 +3499,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression( ...@@ -3507,10 +3499,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression(
} else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT) { } else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT) {
result = ParseImportExpressions(CHECK_OK); result = ParseImportExpressions(CHECK_OK);
} else { } else {
result = ParsePrimaryExpression(is_async, CHECK_OK); result = ParsePrimaryExpression(CHECK_OK);
} }
return ParseMemberExpressionContinuation(result, is_async, ok); return ParseMemberExpressionContinuation(result, ok);
} }
template <typename Impl> template <typename Impl>
...@@ -3613,13 +3605,12 @@ ParserBase<Impl>::ParseNewTargetExpression(bool* ok) { ...@@ -3613,13 +3605,12 @@ ParserBase<Impl>::ParseNewTargetExpression(bool* ok) {
template <typename Impl> template <typename Impl>
typename ParserBase<Impl>::ExpressionT typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression, ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression,
bool* is_async, bool* ok) { bool* ok) {
// Parses this part of MemberExpression: // Parses this part of MemberExpression:
// ('[' Expression ']' | '.' Identifier | TemplateLiteral)* // ('[' Expression ']' | '.' Identifier | TemplateLiteral)*
while (true) { while (true) {
switch (peek()) { switch (peek()) {
case Token::LBRACK: { case Token::LBRACK: {
*is_async = false;
ValidateExpression(CHECK_OK); ValidateExpression(CHECK_OK);
BindingPatternUnexpectedToken(); BindingPatternUnexpectedToken();
ArrowFormalParametersUnexpectedToken(); ArrowFormalParametersUnexpectedToken();
...@@ -3634,7 +3625,6 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression, ...@@ -3634,7 +3625,6 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression,
break; break;
} }
case Token::PERIOD: { case Token::PERIOD: {
*is_async = false;
ValidateExpression(CHECK_OK); ValidateExpression(CHECK_OK);
BindingPatternUnexpectedToken(); BindingPatternUnexpectedToken();
ArrowFormalParametersUnexpectedToken(); ArrowFormalParametersUnexpectedToken();
...@@ -3647,7 +3637,6 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression, ...@@ -3647,7 +3637,6 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression,
} }
case Token::TEMPLATE_SPAN: case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL: { case Token::TEMPLATE_TAIL: {
*is_async = false;
ValidateExpression(CHECK_OK); ValidateExpression(CHECK_OK);
BindingPatternUnexpectedToken(); BindingPatternUnexpectedToken();
ArrowFormalParametersUnexpectedToken(); ArrowFormalParametersUnexpectedToken();
......
...@@ -587,6 +587,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -587,6 +587,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
return identifier == ast_value_factory()->eval_string(); return identifier == ast_value_factory()->eval_string();
} }
V8_INLINE bool IsAsync(const AstRawString* identifier) const {
return identifier == ast_value_factory()->async_string();
}
V8_INLINE bool IsArguments(const AstRawString* identifier) const { V8_INLINE bool IsArguments(const AstRawString* identifier) const {
return identifier == ast_value_factory()->arguments_string(); return identifier == ast_value_factory()->arguments_string();
} }
......
...@@ -56,6 +56,7 @@ class PreParserIdentifier { ...@@ -56,6 +56,7 @@ class PreParserIdentifier {
} }
bool IsNull() const { return type_ == kNullIdentifier; } bool IsNull() const { return type_ == kNullIdentifier; }
bool IsEval() const { return type_ == kEvalIdentifier; } bool IsEval() const { return type_ == kEvalIdentifier; }
bool IsAsync() const { return type_ == kAsyncIdentifier; }
bool IsArguments() const { return type_ == kArgumentsIdentifier; } bool IsArguments() const { return type_ == kArgumentsIdentifier; }
bool IsEvalOrArguments() const { return IsEval() || IsArguments(); } bool IsEvalOrArguments() const { return IsEval() || IsArguments(); }
bool IsConstructor() const { return type_ == kConstructorIdentifier; } bool IsConstructor() const { return type_ == kConstructorIdentifier; }
...@@ -1289,6 +1290,10 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1289,6 +1290,10 @@ class PreParser : public ParserBase<PreParser> {
return identifier.IsEval(); return identifier.IsEval();
} }
V8_INLINE bool IsAsync(const PreParserIdentifier& identifier) const {
return identifier.IsAsync();
}
V8_INLINE bool IsArguments(const PreParserIdentifier& identifier) const { V8_INLINE bool IsArguments(const PreParserIdentifier& identifier) const {
return identifier.IsArguments(); return identifier.IsArguments();
} }
......
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