OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 2303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2314 // that we have only a trivial expression to parse. | 2314 // that we have only a trivial expression to parse. |
2315 ExpressionT expression; | 2315 ExpressionT expression; |
2316 if (IsTrivialExpression()) { | 2316 if (IsTrivialExpression()) { |
2317 expression = this->ParsePrimaryExpression(&arrow_formals_classifier, | 2317 expression = this->ParsePrimaryExpression(&arrow_formals_classifier, |
2318 &is_async, CHECK_OK); | 2318 &is_async, CHECK_OK); |
2319 } else { | 2319 } else { |
2320 expression = this->ParseConditionalExpression( | 2320 expression = this->ParseConditionalExpression( |
2321 accept_IN, &arrow_formals_classifier, CHECK_OK); | 2321 accept_IN, &arrow_formals_classifier, CHECK_OK); |
2322 } | 2322 } |
2323 | 2323 |
2324 if (is_async && peek_any_identifier() && PeekAhead() == Token::ARROW) { | 2324 if (is_async && this->IsIdentifier(expression) && peek_any_identifier() && |
| 2325 PeekAhead() == Token::ARROW) { |
2325 // async Identifier => AsyncConciseBody | 2326 // async Identifier => AsyncConciseBody |
2326 IdentifierT name = | 2327 IdentifierT name = |
2327 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); | 2328 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); |
2328 expression = this->ExpressionFromIdentifier(name, position(), | 2329 expression = this->ExpressionFromIdentifier( |
2329 scanner()->location().end_pos); | 2330 name, position(), scanner()->location().end_pos, InferName::No); |
| 2331 if (fni_) { |
| 2332 // Remove `async` keyword from inferred name stack. |
| 2333 fni_->RemoveAsyncKeywordFromEnd(); |
| 2334 } |
2330 } | 2335 } |
2331 | 2336 |
2332 if (peek() == Token::ARROW) { | 2337 if (peek() == Token::ARROW) { |
2333 Scanner::Location arrow_loc = scanner()->peek_location(); | 2338 Scanner::Location arrow_loc = scanner()->peek_location(); |
2334 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, | 2339 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
2335 parenthesized_formals, is_async, CHECK_OK); | 2340 parenthesized_formals, is_async, CHECK_OK); |
2336 // This reads strangely, but is correct: it checks whether any | 2341 // This reads strangely, but is correct: it checks whether any |
2337 // sub-expression of the parameter list failed to be a valid formal | 2342 // sub-expression of the parameter list failed to be a valid formal |
2338 // parameter initializer. Since YieldExpressions are banned anywhere | 2343 // parameter initializer. Since YieldExpressions are banned anywhere |
2339 // in an arrow parameter list, this is correct. | 2344 // in an arrow parameter list, this is correct. |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2875 pos = peek_position(); | 2880 pos = peek_position(); |
2876 // Also the trailing parenthesis are a hint that the function will | 2881 // Also the trailing parenthesis are a hint that the function will |
2877 // be called immediately. If we happen to have parsed a preceding | 2882 // be called immediately. If we happen to have parsed a preceding |
2878 // function literal eagerly, we can also compile it eagerly. | 2883 // function literal eagerly, we can also compile it eagerly. |
2879 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 2884 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
2880 result->AsFunctionLiteral()->set_should_eager_compile(); | 2885 result->AsFunctionLiteral()->set_should_eager_compile(); |
2881 } | 2886 } |
2882 } | 2887 } |
2883 Scanner::Location spread_pos; | 2888 Scanner::Location spread_pos; |
2884 typename Traits::Type::ExpressionList args; | 2889 typename Traits::Type::ExpressionList args; |
2885 if (V8_UNLIKELY(is_async)) { | 2890 if (V8_UNLIKELY(is_async && this->IsIdentifier(result))) { |
2886 ExpressionClassifier async_classifier(this); | 2891 ExpressionClassifier async_classifier(this); |
2887 args = ParseArguments(&spread_pos, true, &async_classifier, CHECK_OK); | 2892 args = ParseArguments(&spread_pos, true, &async_classifier, CHECK_OK); |
2888 if (peek() == Token::ARROW) { | 2893 if (peek() == Token::ARROW) { |
| 2894 if (fni_) { |
| 2895 fni_->RemoveAsyncKeywordFromEnd(); |
| 2896 } |
2889 ValidateBindingPattern(&async_classifier, CHECK_OK); | 2897 ValidateBindingPattern(&async_classifier, CHECK_OK); |
2890 if (!async_classifier.is_valid_async_arrow_formal_parameters()) { | 2898 if (!async_classifier.is_valid_async_arrow_formal_parameters()) { |
2891 ReportClassifierError( | 2899 ReportClassifierError( |
2892 async_classifier.async_arrow_formal_parameters_error()); | 2900 async_classifier.async_arrow_formal_parameters_error()); |
2893 *ok = false; | 2901 *ok = false; |
2894 return this->EmptyExpression(); | 2902 return this->EmptyExpression(); |
2895 } | 2903 } |
2896 if (args->length()) { | 2904 if (args->length()) { |
2897 // async ( Arguments ) => ... | 2905 // async ( Arguments ) => ... |
2898 return Traits::ExpressionListToExpression(args); | 2906 return Traits::ExpressionListToExpression(args); |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3722 has_seen_constructor_ = true; | 3730 has_seen_constructor_ = true; |
3723 return; | 3731 return; |
3724 } | 3732 } |
3725 } | 3733 } |
3726 | 3734 |
3727 | 3735 |
3728 } // namespace internal | 3736 } // namespace internal |
3729 } // namespace v8 | 3737 } // namespace v8 |
3730 | 3738 |
3731 #endif // V8_PARSING_PARSER_BASE_H | 3739 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |