Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: src/parsing/parser-base.h

Issue 2235423003: [parser] improve inferred function names for async arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: a better/cheaper mechanic Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 && peek_any_identifier() && PeekAhead() == Token::ARROW) {
2325 // async Identifier => AsyncConciseBody 2325 if (this->IsIdentifier(expression)) {
2326 IdentifierT name = 2326 // async Identifier => AsyncConciseBody
2327 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); 2327 IdentifierT name =
2328 expression = this->ExpressionFromIdentifier(name, position(), 2328 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
2329 scanner()->location().end_pos); 2329 expression = this->ExpressionFromIdentifier(
2330 name, position(), scanner()->location().end_pos, InferName::No);
2331 if (fni_) {
2332 // Remove `async` keyword from inferred name stack.
2333 fni_->RemoveAsyncKeywordAtIndex(fni_->LastNameIndex());
2334 }
2335 }
2330 } 2336 }
2331 2337
2332 if (peek() == Token::ARROW) { 2338 if (peek() == Token::ARROW) {
2333 Scanner::Location arrow_loc = scanner()->peek_location(); 2339 Scanner::Location arrow_loc = scanner()->peek_location();
2334 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, 2340 ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
2335 parenthesized_formals, is_async, CHECK_OK); 2341 parenthesized_formals, is_async, CHECK_OK);
2336 // This reads strangely, but is correct: it checks whether any 2342 // This reads strangely, but is correct: it checks whether any
2337 // sub-expression of the parameter list failed to be a valid formal 2343 // sub-expression of the parameter list failed to be a valid formal
2338 // parameter initializer. Since YieldExpressions are banned anywhere 2344 // parameter initializer. Since YieldExpressions are banned anywhere
2339 // in an arrow parameter list, this is correct. 2345 // in an arrow parameter list, this is correct.
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2875 pos = peek_position(); 2881 pos = peek_position();
2876 // Also the trailing parenthesis are a hint that the function will 2882 // Also the trailing parenthesis are a hint that the function will
2877 // be called immediately. If we happen to have parsed a preceding 2883 // be called immediately. If we happen to have parsed a preceding
2878 // function literal eagerly, we can also compile it eagerly. 2884 // function literal eagerly, we can also compile it eagerly.
2879 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { 2885 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
2880 result->AsFunctionLiteral()->set_should_eager_compile(); 2886 result->AsFunctionLiteral()->set_should_eager_compile();
2881 } 2887 }
2882 } 2888 }
2883 Scanner::Location spread_pos; 2889 Scanner::Location spread_pos;
2884 typename Traits::Type::ExpressionList args; 2890 typename Traits::Type::ExpressionList args;
2885 if (V8_UNLIKELY(is_async)) { 2891 if (V8_UNLIKELY(is_async && this->IsIdentifier(result))) {
2892 int async_index = fni_ ? fni_->LastNameIndex() : -1;
2886 ExpressionClassifier async_classifier(this); 2893 ExpressionClassifier async_classifier(this);
2887 args = ParseArguments(&spread_pos, true, &async_classifier, CHECK_OK); 2894 args = ParseArguments(&spread_pos, true, &async_classifier, CHECK_OK);
2888 if (peek() == Token::ARROW) { 2895 if (peek() == Token::ARROW) {
2896 if (fni_) {
2897 fni_->RemoveAsyncKeywordAtIndex(async_index);
2898 }
2889 ValidateBindingPattern(&async_classifier, CHECK_OK); 2899 ValidateBindingPattern(&async_classifier, CHECK_OK);
2890 if (!async_classifier.is_valid_async_arrow_formal_parameters()) { 2900 if (!async_classifier.is_valid_async_arrow_formal_parameters()) {
2891 ReportClassifierError( 2901 ReportClassifierError(
2892 async_classifier.async_arrow_formal_parameters_error()); 2902 async_classifier.async_arrow_formal_parameters_error());
2893 *ok = false; 2903 *ok = false;
2894 return this->EmptyExpression(); 2904 return this->EmptyExpression();
2895 } 2905 }
2896 if (args->length()) { 2906 if (args->length()) {
2897 // async ( Arguments ) => ... 2907 // async ( Arguments ) => ...
2898 return Traits::ExpressionListToExpression(args); 2908 return Traits::ExpressionListToExpression(args);
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
3722 has_seen_constructor_ = true; 3732 has_seen_constructor_ = true;
3723 return; 3733 return;
3724 } 3734 }
3725 } 3735 }
3726 3736
3727 3737
3728 } // namespace internal 3738 } // namespace internal
3729 } // namespace v8 3739 } // namespace v8
3730 3740
3731 #endif // V8_PARSING_PARSER_BASE_H 3741 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698