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

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

Issue 2273693002: [parser] Clean up (pre)parser traits, part 2 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@nickie-2267783002-ref-traits
Patch Set: Rebase Created 4 years, 3 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
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 852
853 // Checking the name of a function literal. This has to be done after parsing 853 // Checking the name of a function literal. This has to be done after parsing
854 // the function, since the function can declare itself strict. 854 // the function, since the function can declare itself strict.
855 void CheckFunctionName(LanguageMode language_mode, IdentifierT function_name, 855 void CheckFunctionName(LanguageMode language_mode, IdentifierT function_name,
856 FunctionNameValidity function_name_validity, 856 FunctionNameValidity function_name_validity,
857 const Scanner::Location& function_name_loc, bool* ok) { 857 const Scanner::Location& function_name_loc, bool* ok) {
858 if (function_name_validity == kSkipFunctionNameCheck) return; 858 if (function_name_validity == kSkipFunctionNameCheck) return;
859 // The function name needs to be checked in strict mode. 859 // The function name needs to be checked in strict mode.
860 if (is_sloppy(language_mode)) return; 860 if (is_sloppy(language_mode)) return;
861 861
862 if (this->IsEvalOrArguments(function_name)) { 862 if (impl()->IsEvalOrArguments(function_name)) {
863 Traits::ReportMessageAt(function_name_loc, 863 Traits::ReportMessageAt(function_name_loc,
864 MessageTemplate::kStrictEvalArguments); 864 MessageTemplate::kStrictEvalArguments);
865 *ok = false; 865 *ok = false;
866 return; 866 return;
867 } 867 }
868 if (function_name_validity == kFunctionNameIsStrictReserved) { 868 if (function_name_validity == kFunctionNameIsStrictReserved) {
869 Traits::ReportMessageAt(function_name_loc, 869 Traits::ReportMessageAt(function_name_loc,
870 MessageTemplate::kUnexpectedStrictReserved); 870 MessageTemplate::kUnexpectedStrictReserved);
871 *ok = false; 871 *ok = false;
872 return; 872 return;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 bool IsValidArrowFormalParametersStart(Token::Value token) { 998 bool IsValidArrowFormalParametersStart(Token::Value token) {
999 return is_any_identifier(token) || token == Token::LPAREN; 999 return is_any_identifier(token) || token == Token::LPAREN;
1000 } 1000 }
1001 1001
1002 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, 1002 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier,
1003 ExpressionT expr, 1003 ExpressionT expr,
1004 bool parenthesized_formals, bool is_async, 1004 bool parenthesized_formals, bool is_async,
1005 bool* ok) { 1005 bool* ok) {
1006 if (classifier->is_valid_binding_pattern()) { 1006 if (classifier->is_valid_binding_pattern()) {
1007 // A simple arrow formal parameter: IDENTIFIER => BODY. 1007 // A simple arrow formal parameter: IDENTIFIER => BODY.
1008 if (!this->IsIdentifier(expr)) { 1008 if (!impl()->IsIdentifier(expr)) {
1009 Traits::ReportMessageAt(scanner()->location(), 1009 Traits::ReportMessageAt(scanner()->location(),
1010 MessageTemplate::kUnexpectedToken, 1010 MessageTemplate::kUnexpectedToken,
1011 Token::String(scanner()->current_token())); 1011 Token::String(scanner()->current_token()));
1012 *ok = false; 1012 *ok = false;
1013 } 1013 }
1014 } else if (!classifier->is_valid_arrow_formal_parameters()) { 1014 } else if (!classifier->is_valid_arrow_formal_parameters()) {
1015 // If after parsing the expr, we see an error but the expression is 1015 // If after parsing the expr, we see an error but the expression is
1016 // neither a valid binding pattern nor a valid parenthesized formal 1016 // neither a valid binding pattern nor a valid parenthesized formal
1017 // parameter list, show the "arrow formal parameters" error if the formals 1017 // parameter list, show the "arrow formal parameters" error if the formals
1018 // started with a parenthesis, and the binding pattern error otherwise. 1018 // started with a parenthesis, and the binding pattern error otherwise.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 ExpressionT CheckAndRewriteReferenceExpression( 1177 ExpressionT CheckAndRewriteReferenceExpression(
1178 ExpressionT expression, int beg_pos, int end_pos, 1178 ExpressionT expression, int beg_pos, int end_pos,
1179 MessageTemplate::Template message, bool* ok); 1179 MessageTemplate::Template message, bool* ok);
1180 ExpressionT CheckAndRewriteReferenceExpression( 1180 ExpressionT CheckAndRewriteReferenceExpression(
1181 ExpressionT expression, int beg_pos, int end_pos, 1181 ExpressionT expression, int beg_pos, int end_pos,
1182 MessageTemplate::Template message, ParseErrorType type, bool* ok); 1182 MessageTemplate::Template message, ParseErrorType type, bool* ok);
1183 1183
1184 bool IsValidReferenceExpression(ExpressionT expression); 1184 bool IsValidReferenceExpression(ExpressionT expression);
1185 1185
1186 bool IsAssignableIdentifier(ExpressionT expression) { 1186 bool IsAssignableIdentifier(ExpressionT expression) {
1187 if (!Traits::IsIdentifier(expression)) return false; 1187 if (!impl()->IsIdentifier(expression)) return false;
1188 if (is_strict(language_mode()) && 1188 if (is_strict(language_mode()) &&
1189 Traits::IsEvalOrArguments(Traits::AsIdentifier(expression))) { 1189 impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) {
1190 return false; 1190 return false;
1191 } 1191 }
1192 return true; 1192 return true;
1193 } 1193 }
1194 1194
1195 bool IsValidPattern(ExpressionT expression) { 1195 bool IsValidPattern(ExpressionT expression) {
1196 return expression->IsObjectLiteral() || expression->IsArrayLiteral(); 1196 return expression->IsObjectLiteral() || expression->IsArrayLiteral();
1197 } 1197 }
1198 1198
1199 // Keep track of eval() calls since they disable all local variable 1199 // Keep track of eval() calls since they disable all local variable
1200 // optimizations. This checks if expression is an eval call, and if yes, 1200 // optimizations. This checks if expression is an eval call, and if yes,
1201 // forwards the information to scope. 1201 // forwards the information to scope.
1202 Call::PossiblyEval CheckPossibleEvalCall(ExpressionT expression, 1202 Call::PossiblyEval CheckPossibleEvalCall(ExpressionT expression,
1203 Scope* scope) { 1203 Scope* scope) {
1204 if (Traits::IsIdentifier(expression) && 1204 if (impl()->IsIdentifier(expression) &&
1205 Traits::IsEval(Traits::AsIdentifier(expression))) { 1205 impl()->IsEval(impl()->AsIdentifier(expression))) {
1206 scope->RecordEvalCall(); 1206 scope->RecordEvalCall();
1207 if (is_sloppy(scope->language_mode())) { 1207 if (is_sloppy(scope->language_mode())) {
1208 // For sloppy scopes we also have to record the call at function level, 1208 // For sloppy scopes we also have to record the call at function level,
1209 // in case it includes declarations that will be hoisted. 1209 // in case it includes declarations that will be hoisted.
1210 scope->GetDeclarationScope()->RecordEvalCall(); 1210 scope->GetDeclarationScope()->RecordEvalCall();
1211 } 1211 }
1212 return Call::IS_POSSIBLY_EVAL; 1212 return Call::IS_POSSIBLY_EVAL;
1213 } 1213 }
1214 return Call::NOT_EVAL; 1214 return Call::NOT_EVAL;
1215 } 1215 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 Token::Value next = Next(); 1438 Token::Value next = Next();
1439 if (next == Token::IDENTIFIER || next == Token::ASYNC || 1439 if (next == Token::IDENTIFIER || next == Token::ASYNC ||
1440 (next == Token::AWAIT && !parsing_module_ && !is_async_function())) { 1440 (next == Token::AWAIT && !parsing_module_ && !is_async_function())) {
1441 IdentifierT name = this->GetSymbol(scanner()); 1441 IdentifierT name = this->GetSymbol(scanner());
1442 // When this function is used to read a formal parameter, we don't always 1442 // When this function is used to read a formal parameter, we don't always
1443 // know whether the function is going to be strict or sloppy. Indeed for 1443 // know whether the function is going to be strict or sloppy. Indeed for
1444 // arrow functions we don't always know that the identifier we are reading 1444 // arrow functions we don't always know that the identifier we are reading
1445 // is actually a formal parameter. Therefore besides the errors that we 1445 // is actually a formal parameter. Therefore besides the errors that we
1446 // must detect because we know we're in strict mode, we also record any 1446 // must detect because we know we're in strict mode, we also record any
1447 // error that we might make in the future once we know the language mode. 1447 // error that we might make in the future once we know the language mode.
1448 if (this->IsEvalOrArguments(name)) { 1448 if (impl()->IsEvalOrArguments(name)) {
1449 classifier->RecordStrictModeFormalParameterError( 1449 classifier->RecordStrictModeFormalParameterError(
1450 scanner()->location(), MessageTemplate::kStrictEvalArguments); 1450 scanner()->location(), MessageTemplate::kStrictEvalArguments);
1451 if (is_strict(language_mode())) { 1451 if (is_strict(language_mode())) {
1452 classifier->RecordBindingPatternError( 1452 classifier->RecordBindingPatternError(
1453 scanner()->location(), MessageTemplate::kStrictEvalArguments); 1453 scanner()->location(), MessageTemplate::kStrictEvalArguments);
1454 } 1454 }
1455 } else if (next == Token::AWAIT) { 1455 } else if (next == Token::AWAIT) {
1456 classifier->RecordAsyncArrowFormalParametersError( 1456 classifier->RecordAsyncArrowFormalParametersError(
1457 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier); 1457 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier);
1458 } 1458 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 int expr_pos = peek_position(); 1658 int expr_pos = peek_position();
1659 classifier->RecordExpressionError(scanner()->location(), 1659 classifier->RecordExpressionError(scanner()->location(),
1660 MessageTemplate::kUnexpectedToken, 1660 MessageTemplate::kUnexpectedToken,
1661 Token::String(Token::ELLIPSIS)); 1661 Token::String(Token::ELLIPSIS));
1662 classifier->RecordNonSimpleParameter(); 1662 classifier->RecordNonSimpleParameter();
1663 ExpressionClassifier binding_classifier(this); 1663 ExpressionClassifier binding_classifier(this);
1664 ExpressionT expr = this->ParseAssignmentExpression( 1664 ExpressionT expr = this->ParseAssignmentExpression(
1665 true, &binding_classifier, CHECK_OK); 1665 true, &binding_classifier, CHECK_OK);
1666 classifier->Accumulate(&binding_classifier, 1666 classifier->Accumulate(&binding_classifier,
1667 ExpressionClassifier::AllProductions); 1667 ExpressionClassifier::AllProductions);
1668 if (!this->IsIdentifier(expr) && !IsValidPattern(expr)) { 1668 if (!impl()->IsIdentifier(expr) && !IsValidPattern(expr)) {
1669 classifier->RecordArrowFormalParametersError( 1669 classifier->RecordArrowFormalParametersError(
1670 Scanner::Location(ellipsis_pos, scanner()->location().end_pos), 1670 Scanner::Location(ellipsis_pos, scanner()->location().end_pos),
1671 MessageTemplate::kInvalidRestParameter); 1671 MessageTemplate::kInvalidRestParameter);
1672 } 1672 }
1673 if (peek() == Token::COMMA) { 1673 if (peek() == Token::COMMA) {
1674 ReportMessageAt(scanner()->peek_location(), 1674 ReportMessageAt(scanner()->peek_location(),
1675 MessageTemplate::kParamAfterRest); 1675 MessageTemplate::kParamAfterRest);
1676 *ok = false; 1676 *ok = false;
1677 return this->EmptyExpression(); 1677 return this->EmptyExpression();
1678 } 1678 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 // Expression ',' AssignmentExpression 1751 // Expression ',' AssignmentExpression
1752 1752
1753 ExpressionT result; 1753 ExpressionT result;
1754 { 1754 {
1755 ExpressionClassifier binding_classifier(this); 1755 ExpressionClassifier binding_classifier(this);
1756 result = this->ParseAssignmentExpression(accept_IN, &binding_classifier, 1756 result = this->ParseAssignmentExpression(accept_IN, &binding_classifier,
1757 CHECK_OK); 1757 CHECK_OK);
1758 classifier->Accumulate(&binding_classifier, 1758 classifier->Accumulate(&binding_classifier,
1759 ExpressionClassifier::AllProductions); 1759 ExpressionClassifier::AllProductions);
1760 } 1760 }
1761 bool is_simple_parameter_list = this->IsIdentifier(result); 1761 bool is_simple_parameter_list = impl()->IsIdentifier(result);
1762 bool seen_rest = false; 1762 bool seen_rest = false;
1763 while (peek() == Token::COMMA) { 1763 while (peek() == Token::COMMA) {
1764 CheckNoTailCallExpressions(classifier, CHECK_OK); 1764 CheckNoTailCallExpressions(classifier, CHECK_OK);
1765 if (seen_rest) { 1765 if (seen_rest) {
1766 // At this point the production can't possibly be valid, but we don't know 1766 // At this point the production can't possibly be valid, but we don't know
1767 // which error to signal. 1767 // which error to signal.
1768 classifier->RecordArrowFormalParametersError( 1768 classifier->RecordArrowFormalParametersError(
1769 scanner()->peek_location(), MessageTemplate::kParamAfterRest); 1769 scanner()->peek_location(), MessageTemplate::kParamAfterRest);
1770 } 1770 }
1771 Consume(Token::COMMA); 1771 Consume(Token::COMMA);
(...skipping 11 matching lines...) Expand all
1783 Consume(Token::ELLIPSIS); 1783 Consume(Token::ELLIPSIS);
1784 seen_rest = is_rest = true; 1784 seen_rest = is_rest = true;
1785 } 1785 }
1786 int pos = position(), expr_pos = peek_position(); 1786 int pos = position(), expr_pos = peek_position();
1787 ExpressionClassifier binding_classifier(this); 1787 ExpressionClassifier binding_classifier(this);
1788 ExpressionT right = this->ParseAssignmentExpression( 1788 ExpressionT right = this->ParseAssignmentExpression(
1789 accept_IN, &binding_classifier, CHECK_OK); 1789 accept_IN, &binding_classifier, CHECK_OK);
1790 classifier->Accumulate(&binding_classifier, 1790 classifier->Accumulate(&binding_classifier,
1791 ExpressionClassifier::AllProductions); 1791 ExpressionClassifier::AllProductions);
1792 if (is_rest) { 1792 if (is_rest) {
1793 if (!this->IsIdentifier(right) && !IsValidPattern(right)) { 1793 if (!impl()->IsIdentifier(right) && !IsValidPattern(right)) {
1794 classifier->RecordArrowFormalParametersError( 1794 classifier->RecordArrowFormalParametersError(
1795 Scanner::Location(pos, scanner()->location().end_pos), 1795 Scanner::Location(pos, scanner()->location().end_pos),
1796 MessageTemplate::kInvalidRestParameter); 1796 MessageTemplate::kInvalidRestParameter);
1797 } 1797 }
1798 right = factory()->NewSpread(right, pos, expr_pos); 1798 right = factory()->NewSpread(right, pos, expr_pos);
1799 } 1799 }
1800 is_simple_parameter_list = 1800 is_simple_parameter_list =
1801 is_simple_parameter_list && this->IsIdentifier(right); 1801 is_simple_parameter_list && impl()->IsIdentifier(right);
1802 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); 1802 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos);
1803 } 1803 }
1804 if (!is_simple_parameter_list || seen_rest) { 1804 if (!is_simple_parameter_list || seen_rest) {
1805 classifier->RecordNonSimpleParameter(); 1805 classifier->RecordNonSimpleParameter();
1806 } 1806 }
1807 1807
1808 return result; 1808 return result;
1809 } 1809 }
1810 1810
1811 template <typename Impl> 1811 template <typename Impl>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 return expression; 1929 return expression;
1930 } 1930 }
1931 1931
1932 default: 1932 default:
1933 *name = ParseIdentifierName(CHECK_OK); 1933 *name = ParseIdentifierName(CHECK_OK);
1934 scanner()->IsGetOrSet(is_get, is_set); 1934 scanner()->IsGetOrSet(is_get, is_set);
1935 break; 1935 break;
1936 } 1936 }
1937 1937
1938 uint32_t index; 1938 uint32_t index;
1939 return this->IsArrayIndex(*name, &index) 1939 return impl()->IsArrayIndex(*name, &index)
1940 ? factory()->NewNumberLiteral(index, pos) 1940 ? factory()->NewNumberLiteral(index, pos)
1941 : factory()->NewStringLiteral(*name, pos); 1941 : factory()->NewStringLiteral(*name, pos);
1942 } 1942 }
1943 1943
1944 template <typename Impl> 1944 template <typename Impl>
1945 typename ParserBase<Impl>::ObjectLiteralPropertyT 1945 typename ParserBase<Impl>::ObjectLiteralPropertyT
1946 ParserBase<Impl>::ParsePropertyDefinition( 1946 ParserBase<Impl>::ParsePropertyDefinition(
1947 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, 1947 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends,
1948 MethodKind method_kind, bool* is_computed_name, bool* has_seen_constructor, 1948 MethodKind method_kind, bool* is_computed_name, bool* has_seen_constructor,
1949 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { 1949 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) {
(...skipping 15 matching lines...) Expand all
1965 is_async = true; 1965 is_async = true;
1966 } 1966 }
1967 1967
1968 int next_beg_pos = scanner()->peek_location().beg_pos; 1968 int next_beg_pos = scanner()->peek_location().beg_pos;
1969 int next_end_pos = scanner()->peek_location().end_pos; 1969 int next_end_pos = scanner()->peek_location().end_pos;
1970 ExpressionT name_expression = 1970 ExpressionT name_expression =
1971 ParsePropertyName(name, &is_get, &is_set, is_computed_name, classifier, 1971 ParsePropertyName(name, &is_get, &is_set, is_computed_name, classifier,
1972 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1972 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1973 1973
1974 if (fni_ != nullptr && !*is_computed_name) { 1974 if (fni_ != nullptr && !*is_computed_name) {
1975 this->PushLiteralName(fni_, *name); 1975 impl()->PushLiteralName(fni_, *name);
1976 } 1976 }
1977 1977
1978 if (!in_class && !is_generator) { 1978 if (!in_class && !is_generator) {
1979 DCHECK(!IsStaticMethod(method_kind)); 1979 DCHECK(!IsStaticMethod(method_kind));
1980 if (peek() == Token::COLON) { 1980 if (peek() == Token::COLON) {
1981 // PropertyDefinition 1981 // PropertyDefinition
1982 // PropertyName ':' AssignmentExpression 1982 // PropertyName ':' AssignmentExpression
1983 if (!*is_computed_name) { 1983 if (!*is_computed_name) {
1984 checker->CheckProperty(name_token, kValueProperty, MethodKind::kNormal, 1984 checker->CheckProperty(name_token, kValueProperty, MethodKind::kNormal,
1985 classifier, 1985 classifier,
(...skipping 18 matching lines...) Expand all
2004 // IdentifierReference 2004 // IdentifierReference
2005 // CoverInitializedName 2005 // CoverInitializedName
2006 // 2006 //
2007 // CoverInitializedName 2007 // CoverInitializedName
2008 // IdentifierReference Initializer? 2008 // IdentifierReference Initializer?
2009 if (classifier->duplicate_finder() != nullptr && 2009 if (classifier->duplicate_finder() != nullptr &&
2010 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { 2010 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) {
2011 classifier->RecordDuplicateFormalParameterError(scanner()->location()); 2011 classifier->RecordDuplicateFormalParameterError(scanner()->location());
2012 } 2012 }
2013 2013
2014 if (this->IsEvalOrArguments(*name) && is_strict(language_mode())) { 2014 if (impl()->IsEvalOrArguments(*name) && is_strict(language_mode())) {
2015 classifier->RecordBindingPatternError( 2015 classifier->RecordBindingPatternError(
2016 scanner()->location(), MessageTemplate::kStrictEvalArguments); 2016 scanner()->location(), MessageTemplate::kStrictEvalArguments);
2017 } 2017 }
2018 2018
2019 if (name_token == Token::LET) { 2019 if (name_token == Token::LET) {
2020 classifier->RecordLetPatternError( 2020 classifier->RecordLetPatternError(
2021 scanner()->location(), MessageTemplate::kLetInLexicalBinding); 2021 scanner()->location(), MessageTemplate::kLetInLexicalBinding);
2022 } 2022 }
2023 if (name_token == Token::AWAIT) { 2023 if (name_token == Token::AWAIT) {
2024 DCHECK(!is_async_function()); 2024 DCHECK(!is_async_function());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 classifier, 2081 classifier,
2082 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2082 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2083 } 2083 }
2084 2084
2085 FunctionKind kind = is_generator 2085 FunctionKind kind = is_generator
2086 ? FunctionKind::kConciseGeneratorMethod 2086 ? FunctionKind::kConciseGeneratorMethod
2087 : is_async ? FunctionKind::kAsyncConciseMethod 2087 : is_async ? FunctionKind::kAsyncConciseMethod
2088 : FunctionKind::kConciseMethod; 2088 : FunctionKind::kConciseMethod;
2089 2089
2090 if (in_class && !IsStaticMethod(method_kind) && 2090 if (in_class && !IsStaticMethod(method_kind) &&
2091 this->IsConstructor(*name)) { 2091 impl()->IsConstructor(*name)) {
2092 *has_seen_constructor = true; 2092 *has_seen_constructor = true;
2093 kind = has_extends ? FunctionKind::kSubclassConstructor 2093 kind = has_extends ? FunctionKind::kSubclassConstructor
2094 : FunctionKind::kBaseConstructor; 2094 : FunctionKind::kBaseConstructor;
2095 } 2095 }
2096 2096
2097 ExpressionT value = impl()->ParseFunctionLiteral( 2097 ExpressionT value = impl()->ParseFunctionLiteral(
2098 *name, scanner()->location(), kSkipFunctionNameCheck, kind, 2098 *name, scanner()->location(), kSkipFunctionNameCheck, kind,
2099 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, language_mode(), 2099 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, language_mode(),
2100 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2100 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2101 2101
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2183 IdentifierT name = this->EmptyIdentifier(); 2183 IdentifierT name = this->EmptyIdentifier();
2184 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( 2184 ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
2185 &checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name, 2185 &checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name,
2186 NULL, classifier, &name, CHECK_OK); 2186 NULL, classifier, &name, CHECK_OK);
2187 2187
2188 if (is_computed_name) { 2188 if (is_computed_name) {
2189 has_computed_names = true; 2189 has_computed_names = true;
2190 } 2190 }
2191 2191
2192 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. 2192 // Count CONSTANT or COMPUTED properties to maintain the enumeration order.
2193 if (!has_computed_names && this->IsBoilerplateProperty(property)) { 2193 if (!has_computed_names && impl()->IsBoilerplateProperty(property)) {
2194 number_of_boilerplate_properties++; 2194 number_of_boilerplate_properties++;
2195 } 2195 }
2196 properties->Add(property, zone()); 2196 properties->Add(property, zone());
2197 2197
2198 if (peek() != Token::RBRACE) { 2198 if (peek() != Token::RBRACE) {
2199 // Need {} because of the CHECK_OK macro. 2199 // Need {} because of the CHECK_OK macro.
2200 Expect(Token::COMMA, CHECK_OK); 2200 Expect(Token::COMMA, CHECK_OK);
2201 } 2201 }
2202 2202
2203 if (fni_ != nullptr) fni_->Infer(); 2203 if (fni_ != nullptr) fni_->Infer();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2335 // that we have only a trivial expression to parse. 2335 // that we have only a trivial expression to parse.
2336 ExpressionT expression; 2336 ExpressionT expression;
2337 if (IsTrivialExpression()) { 2337 if (IsTrivialExpression()) {
2338 expression = this->ParsePrimaryExpression(&arrow_formals_classifier, 2338 expression = this->ParsePrimaryExpression(&arrow_formals_classifier,
2339 &is_async, CHECK_OK); 2339 &is_async, CHECK_OK);
2340 } else { 2340 } else {
2341 expression = this->ParseConditionalExpression( 2341 expression = this->ParseConditionalExpression(
2342 accept_IN, &arrow_formals_classifier, CHECK_OK); 2342 accept_IN, &arrow_formals_classifier, CHECK_OK);
2343 } 2343 }
2344 2344
2345 if (is_async && this->IsIdentifier(expression) && peek_any_identifier() && 2345 if (is_async && impl()->IsIdentifier(expression) && peek_any_identifier() &&
2346 PeekAhead() == Token::ARROW) { 2346 PeekAhead() == Token::ARROW) {
2347 // async Identifier => AsyncConciseBody 2347 // async Identifier => AsyncConciseBody
2348 IdentifierT name = 2348 IdentifierT name =
2349 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); 2349 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
2350 expression = this->ExpressionFromIdentifier( 2350 expression = this->ExpressionFromIdentifier(
2351 name, position(), scanner()->location().end_pos, InferName::kNo); 2351 name, position(), scanner()->location().end_pos, InferName::kNo);
2352 if (fni_) { 2352 if (fni_) {
2353 // Remove `async` keyword from inferred name stack. 2353 // Remove `async` keyword from inferred name stack.
2354 fni_->RemoveAsyncKeywordFromEnd(); 2354 fni_->RemoveAsyncKeywordFromEnd();
2355 } 2355 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 // Do not merge pending non-pattern expressions yet! 2410 // Do not merge pending non-pattern expressions yet!
2411 unsigned productions = 2411 unsigned productions =
2412 ExpressionClassifier::FormalParametersProductions | 2412 ExpressionClassifier::FormalParametersProductions |
2413 ExpressionClassifier::AsyncArrowFormalParametersProduction | 2413 ExpressionClassifier::AsyncArrowFormalParametersProduction |
2414 ExpressionClassifier::FormalParameterInitializerProduction; 2414 ExpressionClassifier::FormalParameterInitializerProduction;
2415 2415
2416 // Parenthesized identifiers and property references are allowed as part 2416 // Parenthesized identifiers and property references are allowed as part
2417 // of a larger binding pattern, even though parenthesized patterns 2417 // of a larger binding pattern, even though parenthesized patterns
2418 // themselves are not allowed, e.g., "[(x)] = []". Only accumulate 2418 // themselves are not allowed, e.g., "[(x)] = []". Only accumulate
2419 // assignment pattern errors if the parsed expression is more complex. 2419 // assignment pattern errors if the parsed expression is more complex.
2420 if (this->IsValidReferenceExpression(expression)) { 2420 if (IsValidReferenceExpression(expression)) {
2421 productions |= ExpressionClassifier::PatternProductions & 2421 productions |= ExpressionClassifier::PatternProductions &
2422 ~ExpressionClassifier::AssignmentPatternProduction; 2422 ~ExpressionClassifier::AssignmentPatternProduction;
2423 } else { 2423 } else {
2424 productions |= ExpressionClassifier::PatternProductions; 2424 productions |= ExpressionClassifier::PatternProductions;
2425 } 2425 }
2426 2426
2427 const bool is_destructuring_assignment = 2427 const bool is_destructuring_assignment =
2428 IsValidPattern(expression) && peek() == Token::ASSIGN; 2428 IsValidPattern(expression) && peek() == Token::ASSIGN;
2429 if (!is_destructuring_assignment) { 2429 if (!is_destructuring_assignment) {
2430 // This may be an expression or a pattern, so we must continue to 2430 // This may be an expression or a pattern, so we must continue to
(...skipping 17 matching lines...) Expand all
2448 CheckNoTailCallExpressions(classifier, CHECK_OK); 2448 CheckNoTailCallExpressions(classifier, CHECK_OK);
2449 2449
2450 if (is_destructuring_assignment) { 2450 if (is_destructuring_assignment) {
2451 ValidateAssignmentPattern(classifier, CHECK_OK); 2451 ValidateAssignmentPattern(classifier, CHECK_OK);
2452 } else { 2452 } else {
2453 expression = this->CheckAndRewriteReferenceExpression( 2453 expression = this->CheckAndRewriteReferenceExpression(
2454 expression, lhs_beg_pos, scanner()->location().end_pos, 2454 expression, lhs_beg_pos, scanner()->location().end_pos,
2455 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); 2455 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK);
2456 } 2456 }
2457 2457
2458 expression = this->MarkExpressionAsAssigned(expression); 2458 expression = impl()->MarkExpressionAsAssigned(expression);
2459 2459
2460 Token::Value op = Next(); // Get assignment operator. 2460 Token::Value op = Next(); // Get assignment operator.
2461 if (op != Token::ASSIGN) { 2461 if (op != Token::ASSIGN) {
2462 classifier->RecordPatternError(scanner()->location(), 2462 classifier->RecordPatternError(scanner()->location(),
2463 MessageTemplate::kUnexpectedToken, 2463 MessageTemplate::kUnexpectedToken,
2464 Token::String(op)); 2464 Token::String(op));
2465 } 2465 }
2466 int pos = position(); 2466 int pos = position();
2467 2467
2468 ExpressionClassifier rhs_classifier(this); 2468 ExpressionClassifier rhs_classifier(this);
2469 2469
2470 ExpressionT right = 2470 ExpressionT right =
2471 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); 2471 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK);
2472 CheckNoTailCallExpressions(&rhs_classifier, CHECK_OK); 2472 CheckNoTailCallExpressions(&rhs_classifier, CHECK_OK);
2473 impl()->RewriteNonPattern(&rhs_classifier, CHECK_OK); 2473 impl()->RewriteNonPattern(&rhs_classifier, CHECK_OK);
2474 classifier->Accumulate( 2474 classifier->Accumulate(
2475 &rhs_classifier, 2475 &rhs_classifier,
2476 ExpressionClassifier::ExpressionProductions | 2476 ExpressionClassifier::ExpressionProductions |
2477 ExpressionClassifier::ObjectLiteralProduction | 2477 ExpressionClassifier::ObjectLiteralProduction |
2478 ExpressionClassifier::AsyncArrowFormalParametersProduction); 2478 ExpressionClassifier::AsyncArrowFormalParametersProduction);
2479 2479
2480 // TODO(1231235): We try to estimate the set of properties set by 2480 // TODO(1231235): We try to estimate the set of properties set by
2481 // constructors. We define a new property whenever there is an 2481 // constructors. We define a new property whenever there is an
2482 // assignment to a property of 'this'. We should probably only add 2482 // assignment to a property of 'this'. We should probably only add
2483 // properties if we haven't seen them before. Otherwise we'll 2483 // properties if we haven't seen them before. Otherwise we'll
2484 // probably overestimate the number of properties. 2484 // probably overestimate the number of properties.
2485 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { 2485 if (op == Token::ASSIGN && impl()->IsThisProperty(expression)) {
2486 function_state_->AddProperty(); 2486 function_state_->AddProperty();
2487 } 2487 }
2488 2488
2489 this->CheckAssigningFunctionLiteralToProperty(expression, right); 2489 impl()->CheckAssigningFunctionLiteralToProperty(expression, right);
2490 2490
2491 if (fni_ != NULL) { 2491 if (fni_ != NULL) {
2492 // Check if the right hand side is a call to avoid inferring a 2492 // Check if the right hand side is a call to avoid inferring a
2493 // name if we're dealing with "a = function(){...}();"-like 2493 // name if we're dealing with "a = function(){...}();"-like
2494 // expression. 2494 // expression.
2495 if ((op == Token::INIT || op == Token::ASSIGN) && 2495 if ((op == Token::INIT || op == Token::ASSIGN) &&
2496 (!right->IsCall() && !right->IsCallNew())) { 2496 (!right->IsCall() && !right->IsCallNew())) {
2497 fni_->Infer(); 2497 fni_->Infer();
2498 } else { 2498 } else {
2499 fni_->RemoveLastFunction(); 2499 fni_->RemoveLastFunction();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 this->ParseLeftHandSideExpression(classifier, CHECK_OK); 2586 this->ParseLeftHandSideExpression(classifier, CHECK_OK);
2587 CheckNoTailCallExpressions(classifier, CHECK_OK); 2587 CheckNoTailCallExpressions(classifier, CHECK_OK);
2588 2588
2589 Scanner::Location loc(pos, scanner()->location().end_pos); 2589 Scanner::Location loc(pos, scanner()->location().end_pos);
2590 if (!expression->IsCall()) { 2590 if (!expression->IsCall()) {
2591 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos); 2591 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos);
2592 ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedInsideTailCall); 2592 ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedInsideTailCall);
2593 *ok = false; 2593 *ok = false;
2594 return Traits::EmptyExpression(); 2594 return Traits::EmptyExpression();
2595 } 2595 }
2596 if (Traits::IsDirectEvalCall(expression)) { 2596 if (impl()->IsDirectEvalCall(expression)) {
2597 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos); 2597 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos);
2598 ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedTailCallOfEval); 2598 ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedTailCallOfEval);
2599 *ok = false; 2599 *ok = false;
2600 return Traits::EmptyExpression(); 2600 return Traits::EmptyExpression();
2601 } 2601 }
2602 if (!is_strict(language_mode())) { 2602 if (!is_strict(language_mode())) {
2603 ReportMessageAt(loc, MessageTemplate::kUnexpectedSloppyTailCall); 2603 ReportMessageAt(loc, MessageTemplate::kUnexpectedSloppyTailCall);
2604 *ok = false; 2604 *ok = false;
2605 return Traits::EmptyExpression(); 2605 return Traits::EmptyExpression();
2606 } 2606 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 2683
2684 const bool is_right_associative = op == Token::EXP; 2684 const bool is_right_associative = op == Token::EXP;
2685 const int next_prec = is_right_associative ? prec1 : prec1 + 1; 2685 const int next_prec = is_right_associative ? prec1 : prec1 + 1;
2686 ExpressionT y = 2686 ExpressionT y =
2687 ParseBinaryExpression(next_prec, accept_IN, classifier, CHECK_OK); 2687 ParseBinaryExpression(next_prec, accept_IN, classifier, CHECK_OK);
2688 if (op != Token::OR && op != Token::AND) { 2688 if (op != Token::OR && op != Token::AND) {
2689 CheckNoTailCallExpressions(classifier, CHECK_OK); 2689 CheckNoTailCallExpressions(classifier, CHECK_OK);
2690 } 2690 }
2691 impl()->RewriteNonPattern(classifier, CHECK_OK); 2691 impl()->RewriteNonPattern(classifier, CHECK_OK);
2692 2692
2693 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, 2693 if (impl()->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos)) {
2694 factory())) {
2695 continue; 2694 continue;
2696 } 2695 }
2697 2696
2698 // For now we distinguish between comparisons and other binary 2697 // For now we distinguish between comparisons and other binary
2699 // operations. (We could combine the two and get rid of this 2698 // operations. (We could combine the two and get rid of this
2700 // code and AST node eventually.) 2699 // code and AST node eventually.)
2701 if (Token::IsCompareOp(op)) { 2700 if (Token::IsCompareOp(op)) {
2702 // We have a comparison. 2701 // We have a comparison.
2703 Token::Value cmp = op; 2702 Token::Value cmp = op;
2704 switch (op) { 2703 switch (op) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 BindingPatternUnexpectedToken(classifier); 2742 BindingPatternUnexpectedToken(classifier);
2744 ArrowFormalParametersUnexpectedToken(classifier); 2743 ArrowFormalParametersUnexpectedToken(classifier);
2745 2744
2746 op = Next(); 2745 op = Next();
2747 int pos = position(); 2746 int pos = position();
2748 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); 2747 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK);
2749 CheckNoTailCallExpressions(classifier, CHECK_OK); 2748 CheckNoTailCallExpressions(classifier, CHECK_OK);
2750 impl()->RewriteNonPattern(classifier, CHECK_OK); 2749 impl()->RewriteNonPattern(classifier, CHECK_OK);
2751 2750
2752 if (op == Token::DELETE && is_strict(language_mode())) { 2751 if (op == Token::DELETE && is_strict(language_mode())) {
2753 if (this->IsIdentifier(expression)) { 2752 if (impl()->IsIdentifier(expression)) {
2754 // "delete identifier" is a syntax error in strict mode. 2753 // "delete identifier" is a syntax error in strict mode.
2755 ReportMessage(MessageTemplate::kStrictDelete); 2754 ReportMessage(MessageTemplate::kStrictDelete);
2756 *ok = false; 2755 *ok = false;
2757 return this->EmptyExpression(); 2756 return this->EmptyExpression();
2758 } 2757 }
2759 } 2758 }
2760 2759
2761 if (peek() == Token::EXP) { 2760 if (peek() == Token::EXP) {
2762 ReportUnexpectedToken(Next()); 2761 ReportUnexpectedToken(Next());
2763 *ok = false; 2762 *ok = false;
2764 return this->EmptyExpression(); 2763 return this->EmptyExpression();
2765 } 2764 }
2766 2765
2767 // Allow Traits do rewrite the expression. 2766 // Allow Traits do rewrite the expression.
2768 return this->BuildUnaryExpression(expression, op, pos, factory()); 2767 return this->BuildUnaryExpression(expression, op, pos, factory());
2769 } else if (Token::IsCountOp(op)) { 2768 } else if (Token::IsCountOp(op)) {
2770 BindingPatternUnexpectedToken(classifier); 2769 BindingPatternUnexpectedToken(classifier);
2771 ArrowFormalParametersUnexpectedToken(classifier); 2770 ArrowFormalParametersUnexpectedToken(classifier);
2772 op = Next(); 2771 op = Next();
2773 int beg_pos = peek_position(); 2772 int beg_pos = peek_position();
2774 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); 2773 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK);
2775 CheckNoTailCallExpressions(classifier, CHECK_OK); 2774 CheckNoTailCallExpressions(classifier, CHECK_OK);
2776 expression = this->CheckAndRewriteReferenceExpression( 2775 expression = this->CheckAndRewriteReferenceExpression(
2777 expression, beg_pos, scanner()->location().end_pos, 2776 expression, beg_pos, scanner()->location().end_pos,
2778 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); 2777 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK);
2779 this->MarkExpressionAsAssigned(expression); 2778 expression = impl()->MarkExpressionAsAssigned(expression);
2780 impl()->RewriteNonPattern(classifier, CHECK_OK); 2779 impl()->RewriteNonPattern(classifier, CHECK_OK);
2781 2780
2782 return factory()->NewCountOperation(op, 2781 return factory()->NewCountOperation(op,
2783 true /* prefix */, 2782 true /* prefix */,
2784 expression, 2783 expression,
2785 position()); 2784 position());
2786 2785
2787 } else if (is_async_function() && peek() == Token::AWAIT) { 2786 } else if (is_async_function() && peek() == Token::AWAIT) {
2788 classifier->RecordFormalParameterInitializerError( 2787 classifier->RecordFormalParameterInitializerError(
2789 scanner()->peek_location(), 2788 scanner()->peek_location(),
(...skipping 21 matching lines...) Expand all
2811 this->ParseLeftHandSideExpression(classifier, CHECK_OK); 2810 this->ParseLeftHandSideExpression(classifier, CHECK_OK);
2812 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 2811 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
2813 Token::IsCountOp(peek())) { 2812 Token::IsCountOp(peek())) {
2814 CheckNoTailCallExpressions(classifier, CHECK_OK); 2813 CheckNoTailCallExpressions(classifier, CHECK_OK);
2815 BindingPatternUnexpectedToken(classifier); 2814 BindingPatternUnexpectedToken(classifier);
2816 ArrowFormalParametersUnexpectedToken(classifier); 2815 ArrowFormalParametersUnexpectedToken(classifier);
2817 2816
2818 expression = this->CheckAndRewriteReferenceExpression( 2817 expression = this->CheckAndRewriteReferenceExpression(
2819 expression, lhs_beg_pos, scanner()->location().end_pos, 2818 expression, lhs_beg_pos, scanner()->location().end_pos,
2820 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); 2819 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK);
2821 expression = this->MarkExpressionAsAssigned(expression); 2820 expression = impl()->MarkExpressionAsAssigned(expression);
2822 impl()->RewriteNonPattern(classifier, CHECK_OK); 2821 impl()->RewriteNonPattern(classifier, CHECK_OK);
2823 2822
2824 Token::Value next = Next(); 2823 Token::Value next = Next();
2825 expression = 2824 expression =
2826 factory()->NewCountOperation(next, 2825 factory()->NewCountOperation(next,
2827 false /* postfix */, 2826 false /* postfix */,
2828 expression, 2827 expression,
2829 position()); 2828 position());
2830 } 2829 }
2831 return expression; 2830 return expression;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2882 pos = peek_position(); 2881 pos = peek_position();
2883 // Also the trailing parenthesis are a hint that the function will 2882 // Also the trailing parenthesis are a hint that the function will
2884 // be called immediately. If we happen to have parsed a preceding 2883 // be called immediately. If we happen to have parsed a preceding
2885 // function literal eagerly, we can also compile it eagerly. 2884 // function literal eagerly, we can also compile it eagerly.
2886 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { 2885 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
2887 result->AsFunctionLiteral()->set_should_eager_compile(); 2886 result->AsFunctionLiteral()->set_should_eager_compile();
2888 } 2887 }
2889 } 2888 }
2890 Scanner::Location spread_pos; 2889 Scanner::Location spread_pos;
2891 typename Traits::Type::ExpressionList args; 2890 typename Traits::Type::ExpressionList args;
2892 if (V8_UNLIKELY(is_async && this->IsIdentifier(result))) { 2891 if (V8_UNLIKELY(is_async && impl()->IsIdentifier(result))) {
2893 ExpressionClassifier async_classifier(this); 2892 ExpressionClassifier async_classifier(this);
2894 args = ParseArguments(&spread_pos, true, &async_classifier, CHECK_OK); 2893 args = ParseArguments(&spread_pos, true, &async_classifier, CHECK_OK);
2895 if (peek() == Token::ARROW) { 2894 if (peek() == Token::ARROW) {
2896 if (fni_) { 2895 if (fni_) {
2897 fni_->RemoveAsyncKeywordFromEnd(); 2896 fni_->RemoveAsyncKeywordFromEnd();
2898 } 2897 }
2899 ValidateBindingPattern(&async_classifier, CHECK_OK); 2898 ValidateBindingPattern(&async_classifier, CHECK_OK);
2900 ValidateFormalParameterInitializer(&async_classifier, CHECK_OK); 2899 ValidateFormalParameterInitializer(&async_classifier, CHECK_OK);
2901 if (!async_classifier.is_valid_async_arrow_formal_parameters()) { 2900 if (!async_classifier.is_valid_async_arrow_formal_parameters()) {
2902 ReportClassifierError( 2901 ReportClassifierError(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2953 case Token::PERIOD: { 2952 case Token::PERIOD: {
2954 CheckNoTailCallExpressions(classifier, CHECK_OK); 2953 CheckNoTailCallExpressions(classifier, CHECK_OK);
2955 impl()->RewriteNonPattern(classifier, CHECK_OK); 2954 impl()->RewriteNonPattern(classifier, CHECK_OK);
2956 BindingPatternUnexpectedToken(classifier); 2955 BindingPatternUnexpectedToken(classifier);
2957 ArrowFormalParametersUnexpectedToken(classifier); 2956 ArrowFormalParametersUnexpectedToken(classifier);
2958 Consume(Token::PERIOD); 2957 Consume(Token::PERIOD);
2959 int pos = position(); 2958 int pos = position();
2960 IdentifierT name = ParseIdentifierName(CHECK_OK); 2959 IdentifierT name = ParseIdentifierName(CHECK_OK);
2961 result = factory()->NewProperty( 2960 result = factory()->NewProperty(
2962 result, factory()->NewStringLiteral(name, pos), pos); 2961 result, factory()->NewStringLiteral(name, pos), pos);
2963 if (fni_ != NULL) this->PushLiteralName(fni_, name); 2962 if (fni_ != NULL) impl()->PushLiteralName(fni_, name);
2964 break; 2963 break;
2965 } 2964 }
2966 2965
2967 case Token::TEMPLATE_SPAN: 2966 case Token::TEMPLATE_SPAN:
2968 case Token::TEMPLATE_TAIL: { 2967 case Token::TEMPLATE_TAIL: {
2969 CheckNoTailCallExpressions(classifier, CHECK_OK); 2968 CheckNoTailCallExpressions(classifier, CHECK_OK);
2970 impl()->RewriteNonPattern(classifier, CHECK_OK); 2969 impl()->RewriteNonPattern(classifier, CHECK_OK);
2971 BindingPatternUnexpectedToken(classifier); 2970 BindingPatternUnexpectedToken(classifier);
2972 ArrowFormalParametersUnexpectedToken(classifier); 2971 ArrowFormalParametersUnexpectedToken(classifier);
2973 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); 2972 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
3185 impl()->RewriteNonPattern(classifier, CHECK_OK); 3184 impl()->RewriteNonPattern(classifier, CHECK_OK);
3186 BindingPatternUnexpectedToken(classifier); 3185 BindingPatternUnexpectedToken(classifier);
3187 ArrowFormalParametersUnexpectedToken(classifier); 3186 ArrowFormalParametersUnexpectedToken(classifier);
3188 3187
3189 Consume(Token::LBRACK); 3188 Consume(Token::LBRACK);
3190 int pos = position(); 3189 int pos = position();
3191 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); 3190 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK);
3192 impl()->RewriteNonPattern(classifier, CHECK_OK); 3191 impl()->RewriteNonPattern(classifier, CHECK_OK);
3193 expression = factory()->NewProperty(expression, index, pos); 3192 expression = factory()->NewProperty(expression, index, pos);
3194 if (fni_ != NULL) { 3193 if (fni_ != NULL) {
3195 this->PushPropertyName(fni_, index); 3194 impl()->PushPropertyName(fni_, index);
3196 } 3195 }
3197 Expect(Token::RBRACK, CHECK_OK); 3196 Expect(Token::RBRACK, CHECK_OK);
3198 break; 3197 break;
3199 } 3198 }
3200 case Token::PERIOD: { 3199 case Token::PERIOD: {
3201 *is_async = false; 3200 *is_async = false;
3202 impl()->RewriteNonPattern(classifier, CHECK_OK); 3201 impl()->RewriteNonPattern(classifier, CHECK_OK);
3203 BindingPatternUnexpectedToken(classifier); 3202 BindingPatternUnexpectedToken(classifier);
3204 ArrowFormalParametersUnexpectedToken(classifier); 3203 ArrowFormalParametersUnexpectedToken(classifier);
3205 3204
3206 Consume(Token::PERIOD); 3205 Consume(Token::PERIOD);
3207 int pos = position(); 3206 int pos = position();
3208 IdentifierT name = ParseIdentifierName(CHECK_OK); 3207 IdentifierT name = ParseIdentifierName(CHECK_OK);
3209 expression = factory()->NewProperty( 3208 expression = factory()->NewProperty(
3210 expression, factory()->NewStringLiteral(name, pos), pos); 3209 expression, factory()->NewStringLiteral(name, pos), pos);
3211 if (fni_ != NULL) { 3210 if (fni_ != NULL) {
3212 this->PushLiteralName(fni_, name); 3211 impl()->PushLiteralName(fni_, name);
3213 } 3212 }
3214 break; 3213 break;
3215 } 3214 }
3216 case Token::TEMPLATE_SPAN: 3215 case Token::TEMPLATE_SPAN:
3217 case Token::TEMPLATE_TAIL: { 3216 case Token::TEMPLATE_TAIL: {
3218 *is_async = false; 3217 *is_async = false;
3219 impl()->RewriteNonPattern(classifier, CHECK_OK); 3218 impl()->RewriteNonPattern(classifier, CHECK_OK);
3220 BindingPatternUnexpectedToken(classifier); 3219 BindingPatternUnexpectedToken(classifier);
3221 ArrowFormalParametersUnexpectedToken(classifier); 3220 ArrowFormalParametersUnexpectedToken(classifier);
3222 int pos; 3221 int pos;
(...skipping 29 matching lines...) Expand all
3252 ExpressionClassifier* classifier, 3251 ExpressionClassifier* classifier,
3253 bool* ok) { 3252 bool* ok) {
3254 // FormalParameter[Yield,GeneratorParameter] : 3253 // FormalParameter[Yield,GeneratorParameter] :
3255 // BindingElement[?Yield, ?GeneratorParameter] 3254 // BindingElement[?Yield, ?GeneratorParameter]
3256 bool is_rest = parameters->has_rest; 3255 bool is_rest = parameters->has_rest;
3257 3256
3258 ExpressionT pattern = 3257 ExpressionT pattern =
3259 ParsePrimaryExpression(classifier, CHECK_OK_CUSTOM(Void)); 3258 ParsePrimaryExpression(classifier, CHECK_OK_CUSTOM(Void));
3260 ValidateBindingPattern(classifier, CHECK_OK_CUSTOM(Void)); 3259 ValidateBindingPattern(classifier, CHECK_OK_CUSTOM(Void));
3261 3260
3262 if (!Traits::IsIdentifier(pattern)) { 3261 if (!impl()->IsIdentifier(pattern)) {
3263 parameters->is_simple = false; 3262 parameters->is_simple = false;
3264 ValidateFormalParameterInitializer(classifier, CHECK_OK_CUSTOM(Void)); 3263 ValidateFormalParameterInitializer(classifier, CHECK_OK_CUSTOM(Void));
3265 classifier->RecordNonSimpleParameter(); 3264 classifier->RecordNonSimpleParameter();
3266 } 3265 }
3267 3266
3268 ExpressionT initializer = Traits::EmptyExpression(); 3267 ExpressionT initializer = Traits::EmptyExpression();
3269 if (!is_rest && Check(Token::ASSIGN)) { 3268 if (!is_rest && Check(Token::ASSIGN)) {
3270 ExpressionClassifier init_classifier(this); 3269 ExpressionClassifier init_classifier(this);
3271 initializer = ParseAssignmentExpression(true, &init_classifier, 3270 initializer = ParseAssignmentExpression(true, &init_classifier,
3272 CHECK_OK_CUSTOM(Void)); 3271 CHECK_OK_CUSTOM(Void));
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3510 this->EmptyIdentifierString(), formal_parameters.scope, body, 3509 this->EmptyIdentifierString(), formal_parameters.scope, body,
3511 materialized_literal_count, expected_property_count, num_parameters, 3510 materialized_literal_count, expected_property_count, num_parameters,
3512 FunctionLiteral::kNoDuplicateParameters, 3511 FunctionLiteral::kNoDuplicateParameters,
3513 FunctionLiteral::kAnonymousExpression, 3512 FunctionLiteral::kAnonymousExpression,
3514 FunctionLiteral::kShouldLazyCompile, arrow_kind, 3513 FunctionLiteral::kShouldLazyCompile, arrow_kind,
3515 formal_parameters.scope->start_position()); 3514 formal_parameters.scope->start_position());
3516 3515
3517 function_literal->set_function_token_position( 3516 function_literal->set_function_token_position(
3518 formal_parameters.scope->start_position()); 3517 formal_parameters.scope->start_position());
3519 3518
3520 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); 3519 if (fni_ != NULL) impl()->InferFunctionName(fni_, function_literal);
3521 3520
3522 return function_literal; 3521 return function_literal;
3523 } 3522 }
3524 3523
3525 template <typename Impl> 3524 template <typename Impl>
3526 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( 3525 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
3527 ExpressionT tag, int start, ExpressionClassifier* classifier, bool* ok) { 3526 ExpressionT tag, int start, ExpressionClassifier* classifier, bool* ok) {
3528 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal 3527 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal
3529 // text followed by a substitution expression), finalized by a single 3528 // text followed by a substitution expression), finalized by a single
3530 // TEMPLATE_TAIL. 3529 // TEMPLATE_TAIL.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3623 MessageTemplate::Template message, bool* ok) { 3622 MessageTemplate::Template message, bool* ok) {
3624 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, 3623 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos,
3625 message, kReferenceError, ok); 3624 message, kReferenceError, ok);
3626 } 3625 }
3627 3626
3628 template <typename Impl> 3627 template <typename Impl>
3629 typename ParserBase<Impl>::ExpressionT 3628 typename ParserBase<Impl>::ExpressionT
3630 ParserBase<Impl>::CheckAndRewriteReferenceExpression( 3629 ParserBase<Impl>::CheckAndRewriteReferenceExpression(
3631 ExpressionT expression, int beg_pos, int end_pos, 3630 ExpressionT expression, int beg_pos, int end_pos,
3632 MessageTemplate::Template message, ParseErrorType type, bool* ok) { 3631 MessageTemplate::Template message, ParseErrorType type, bool* ok) {
3633 if (this->IsIdentifier(expression) && is_strict(language_mode()) && 3632 if (impl()->IsIdentifier(expression) && is_strict(language_mode()) &&
3634 this->IsEvalOrArguments(this->AsIdentifier(expression))) { 3633 impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) {
3635 ReportMessageAt(Scanner::Location(beg_pos, end_pos), 3634 ReportMessageAt(Scanner::Location(beg_pos, end_pos),
3636 MessageTemplate::kStrictEvalArguments, kSyntaxError); 3635 MessageTemplate::kStrictEvalArguments, kSyntaxError);
3637 *ok = false; 3636 *ok = false;
3638 return this->EmptyExpression(); 3637 return this->EmptyExpression();
3639 } 3638 }
3640 if (expression->IsValidReferenceExpression()) { 3639 if (expression->IsValidReferenceExpression()) {
3641 return expression; 3640 return expression;
3642 } 3641 }
3643 if (expression->IsCall()) { 3642 if (expression->IsCall()) {
3644 // If it is a call, make it a runtime error for legacy web compatibility. 3643 // If it is a call, make it a runtime error for legacy web compatibility.
3645 // Rewrite `expr' to `expr[throw ReferenceError]'. 3644 // Rewrite `expr' to `expr[throw ReferenceError]'.
3646 ExpressionT error = this->NewThrowReferenceError(message, beg_pos); 3645 ExpressionT error = this->NewThrowReferenceError(message, beg_pos);
3647 return factory()->NewProperty(expression, error, beg_pos); 3646 return factory()->NewProperty(expression, error, beg_pos);
3648 } 3647 }
3649 ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type); 3648 ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type);
3650 *ok = false; 3649 *ok = false;
3651 return this->EmptyExpression(); 3650 return this->EmptyExpression();
3652 } 3651 }
3653 3652
3654 template <typename Impl> 3653 template <typename Impl>
3655 bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) { 3654 bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) {
3656 return this->IsAssignableIdentifier(expression) || expression->IsProperty(); 3655 return IsAssignableIdentifier(expression) || expression->IsProperty();
3657 } 3656 }
3658 3657
3659 template <typename Impl> 3658 template <typename Impl>
3660 void ParserBase<Impl>::CheckDestructuringElement( 3659 void ParserBase<Impl>::CheckDestructuringElement(
3661 ExpressionT expression, ExpressionClassifier* classifier, int begin, 3660 ExpressionT expression, ExpressionClassifier* classifier, int begin,
3662 int end) { 3661 int end) {
3663 if (!IsValidPattern(expression) && !expression->IsAssignment() && 3662 if (!IsValidPattern(expression) && !expression->IsAssignment() &&
3664 !IsValidReferenceExpression(expression)) { 3663 !IsValidReferenceExpression(expression)) {
3665 classifier->RecordAssignmentPatternError( 3664 classifier->RecordAssignmentPatternError(
3666 Scanner::Location(begin, end), 3665 Scanner::Location(begin, end),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3725 has_seen_constructor_ = true; 3724 has_seen_constructor_ = true;
3726 return; 3725 return;
3727 } 3726 }
3728 } 3727 }
3729 3728
3730 3729
3731 } // namespace internal 3730 } // namespace internal
3732 } // namespace v8 3731 } // namespace v8
3733 3732
3734 #endif // V8_PARSING_PARSER_BASE_H 3733 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698