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

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

Issue 2258313002: [async functions] Disallow 'await' in arrow params inside async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Different approach with more tests 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 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 void ValidateFormalParameterInitializer( 926 void ValidateFormalParameterInitializer(
927 const ExpressionClassifier* classifier, bool* ok) { 927 const ExpressionClassifier* classifier, bool* ok) {
928 if (!classifier->is_valid_formal_parameter_initializer()) { 928 if (!classifier->is_valid_formal_parameter_initializer()) {
929 ReportClassifierError(classifier->formal_parameter_initializer_error()); 929 ReportClassifierError(classifier->formal_parameter_initializer_error());
930 *ok = false; 930 *ok = false;
931 } 931 }
932 } 932 }
933 933
934 void ValidateBindingPattern(const ExpressionClassifier* classifier, 934 void ValidateBindingPattern(const ExpressionClassifier* classifier,
935 bool* ok) { 935 bool* ok) {
936 if (!classifier->is_valid_binding_pattern() || 936 if (!classifier->is_valid_binding_pattern()) {
937 !classifier->is_valid_async_binding_pattern()) { 937 ReportClassifierError(classifier->binding_pattern_error());
938 const Scanner::Location& a = classifier->binding_pattern_error().location;
939 const Scanner::Location& b =
940 classifier->async_binding_pattern_error().location;
941 if (a.beg_pos < 0 || (b.beg_pos >= 0 && a.beg_pos > b.beg_pos)) {
942 ReportClassifierError(classifier->async_binding_pattern_error());
943 } else {
944 ReportClassifierError(classifier->binding_pattern_error());
945 }
946 *ok = false; 938 *ok = false;
947 } 939 }
948 } 940 }
949 941
950 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, 942 void ValidateAssignmentPattern(const ExpressionClassifier* classifier,
951 bool* ok) { 943 bool* ok) {
952 if (!classifier->is_valid_assignment_pattern()) { 944 if (!classifier->is_valid_assignment_pattern()) {
953 ReportClassifierError(classifier->assignment_pattern_error()); 945 ReportClassifierError(classifier->assignment_pattern_error());
954 *ok = false; 946 *ok = false;
955 } 947 }
(...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after
2771 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); 2763 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK);
2772 this->MarkExpressionAsAssigned(expression); 2764 this->MarkExpressionAsAssigned(expression);
2773 Traits::RewriteNonPattern(classifier, CHECK_OK); 2765 Traits::RewriteNonPattern(classifier, CHECK_OK);
2774 2766
2775 return factory()->NewCountOperation(op, 2767 return factory()->NewCountOperation(op,
2776 true /* prefix */, 2768 true /* prefix */,
2777 expression, 2769 expression,
2778 position()); 2770 position());
2779 2771
2780 } else if (is_async_function() && peek() == Token::AWAIT) { 2772 } else if (is_async_function() && peek() == Token::AWAIT) {
2781 int beg_pos = peek_position(); 2773 classifier->RecordFormalParameterInitializerError(
2782 switch (PeekAhead()) { 2774 scanner()->peek_location(),
2783 case Token::RPAREN: 2775 MessageTemplate::kAwaitExpressionFormalParameter);
2784 case Token::RBRACK:
2785 case Token::RBRACE:
2786 case Token::ASSIGN:
2787 case Token::COMMA: {
2788 Next();
2789 IdentifierT name = this->GetSymbol(scanner());
2790
2791 // Possibly async arrow formals --- record ExpressionError just in case.
2792 ExpressionUnexpectedToken(classifier);
2793 classifier->RecordAsyncBindingPatternError(
2794 Scanner::Location(beg_pos, scanner()->location().end_pos),
2795 MessageTemplate::kAwaitBindingIdentifier);
2796 classifier->RecordAsyncArrowFormalParametersError(
2797 Scanner::Location(beg_pos, scanner()->location().end_pos),
2798 MessageTemplate::kAwaitBindingIdentifier);
2799
2800 return this->ExpressionFromIdentifier(name, beg_pos,
2801 scanner()->location().end_pos);
2802 }
2803 default:
2804 break;
2805 }
2806 2776
2807 int await_pos = peek_position(); 2777 int await_pos = peek_position();
2808 Consume(Token::AWAIT); 2778 Consume(Token::AWAIT);
2809 2779
2810 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK); 2780 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK);
2811 2781
2812 classifier->RecordFormalParameterInitializerError(
2813 Scanner::Location(beg_pos, scanner()->location().end_pos),
2814 MessageTemplate::kAwaitExpressionFormalParameter);
2815 return Traits::RewriteAwaitExpression(value, await_pos); 2782 return Traits::RewriteAwaitExpression(value, await_pos);
2816 } else { 2783 } else {
2817 return this->ParsePostfixExpression(classifier, ok); 2784 return this->ParsePostfixExpression(classifier, ok);
2818 } 2785 }
2819 } 2786 }
2820 2787
2821 2788
2822 template <class Traits> 2789 template <class Traits>
2823 typename ParserBase<Traits>::ExpressionT 2790 typename ParserBase<Traits>::ExpressionT
2824 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, 2791 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier,
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
3753 has_seen_constructor_ = true; 3720 has_seen_constructor_ = true;
3754 return; 3721 return;
3755 } 3722 }
3756 } 3723 }
3757 3724
3758 3725
3759 } // namespace internal 3726 } // namespace internal
3760 } // namespace v8 3727 } // namespace v8
3761 3728
3762 #endif // V8_PARSING_PARSER_BASE_H 3729 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698