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 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2336 // that we have only a trivial expression to parse. | 2336 // that we have only a trivial expression to parse. |
2337 ExpressionT expression; | 2337 ExpressionT expression; |
2338 if (IsTrivialExpression()) { | 2338 if (IsTrivialExpression()) { |
2339 expression = this->ParsePrimaryExpression(&arrow_formals_classifier, | 2339 expression = this->ParsePrimaryExpression(&arrow_formals_classifier, |
2340 &is_async, CHECK_OK); | 2340 &is_async, CHECK_OK); |
2341 } else { | 2341 } else { |
2342 expression = this->ParseConditionalExpression( | 2342 expression = this->ParseConditionalExpression( |
2343 accept_IN, &arrow_formals_classifier, CHECK_OK); | 2343 accept_IN, &arrow_formals_classifier, CHECK_OK); |
2344 } | 2344 } |
2345 | 2345 |
2346 if (is_async && this->IsIdentifier(expression) && peek_any_identifier() && | 2346 if (is_async && impl()->IsIdentifier(expression) && peek_any_identifier() && |
2347 PeekAhead() == Token::ARROW) { | 2347 PeekAhead() == Token::ARROW) { |
2348 // async Identifier => AsyncConciseBody | 2348 // async Identifier => AsyncConciseBody |
2349 IdentifierT name = | 2349 IdentifierT name = |
2350 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); | 2350 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); |
2351 expression = this->ExpressionFromIdentifier( | 2351 expression = this->ExpressionFromIdentifier( |
2352 name, position(), scanner()->location().end_pos, InferName::kNo); | 2352 name, position(), scanner()->location().end_pos, InferName::kNo); |
2353 if (fni_) { | 2353 if (fni_) { |
2354 // Remove `async` keyword from inferred name stack. | 2354 // Remove `async` keyword from inferred name stack. |
2355 fni_->RemoveAsyncKeywordFromEnd(); | 2355 fni_->RemoveAsyncKeywordFromEnd(); |
2356 } | 2356 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2397 arrow_formals_classifier.Discard(); | 2397 arrow_formals_classifier.Discard(); |
2398 classifier->RecordPatternError(arrow_loc, | 2398 classifier->RecordPatternError(arrow_loc, |
2399 MessageTemplate::kUnexpectedToken, | 2399 MessageTemplate::kUnexpectedToken, |
2400 Token::String(Token::ARROW)); | 2400 Token::String(Token::ARROW)); |
2401 | 2401 |
2402 if (fni_ != nullptr) fni_->Infer(); | 2402 if (fni_ != nullptr) fni_->Infer(); |
2403 | 2403 |
2404 return expression; | 2404 return expression; |
2405 } | 2405 } |
2406 | 2406 |
2407 if (this->IsValidReferenceExpression(expression)) { | 2407 if (IsValidReferenceExpression(expression)) { |
2408 arrow_formals_classifier.ForgiveAssignmentPatternError(); | 2408 arrow_formals_classifier.ForgiveAssignmentPatternError(); |
2409 } | 2409 } |
2410 | 2410 |
2411 // "expression" was not itself an arrow function parameter list, but it might | 2411 // "expression" was not itself an arrow function parameter list, but it might |
2412 // form part of one. Propagate speculative formal parameter error locations. | 2412 // form part of one. Propagate speculative formal parameter error locations. |
2413 // Do not merge pending non-pattern expressions yet! | 2413 // Do not merge pending non-pattern expressions yet! |
2414 classifier->Accumulate( | 2414 classifier->Accumulate( |
2415 &arrow_formals_classifier, | 2415 &arrow_formals_classifier, |
2416 ExpressionClassifier::ExpressionProductions | | 2416 ExpressionClassifier::ExpressionProductions | |
2417 ExpressionClassifier::PatternProductions | | 2417 ExpressionClassifier::PatternProductions | |
(...skipping 17 matching lines...) Expand all Loading... |
2435 if (IsValidPattern(expression) && peek() == Token::ASSIGN) { | 2435 if (IsValidPattern(expression) && peek() == Token::ASSIGN) { |
2436 classifier->ForgiveObjectLiteralError(); | 2436 classifier->ForgiveObjectLiteralError(); |
2437 ValidateAssignmentPattern(classifier, CHECK_OK); | 2437 ValidateAssignmentPattern(classifier, CHECK_OK); |
2438 is_destructuring_assignment = true; | 2438 is_destructuring_assignment = true; |
2439 } else { | 2439 } else { |
2440 expression = this->CheckAndRewriteReferenceExpression( | 2440 expression = this->CheckAndRewriteReferenceExpression( |
2441 expression, lhs_beg_pos, scanner()->location().end_pos, | 2441 expression, lhs_beg_pos, scanner()->location().end_pos, |
2442 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); | 2442 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); |
2443 } | 2443 } |
2444 | 2444 |
2445 expression = this->MarkExpressionAsAssigned(expression); | 2445 expression = impl()->MarkExpressionAsAssigned(expression); |
2446 | 2446 |
2447 Token::Value op = Next(); // Get assignment operator. | 2447 Token::Value op = Next(); // Get assignment operator. |
2448 if (op != Token::ASSIGN) { | 2448 if (op != Token::ASSIGN) { |
2449 classifier->RecordPatternError(scanner()->location(), | 2449 classifier->RecordPatternError(scanner()->location(), |
2450 MessageTemplate::kUnexpectedToken, | 2450 MessageTemplate::kUnexpectedToken, |
2451 Token::String(op)); | 2451 Token::String(op)); |
2452 } | 2452 } |
2453 int pos = position(); | 2453 int pos = position(); |
2454 | 2454 |
2455 ExpressionClassifier rhs_classifier(this); | 2455 ExpressionClassifier rhs_classifier(this); |
2456 | 2456 |
2457 ExpressionT right = | 2457 ExpressionT right = |
2458 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); | 2458 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); |
2459 CheckNoTailCallExpressions(&rhs_classifier, CHECK_OK); | 2459 CheckNoTailCallExpressions(&rhs_classifier, CHECK_OK); |
2460 impl()->RewriteNonPattern(&rhs_classifier, CHECK_OK); | 2460 impl()->RewriteNonPattern(&rhs_classifier, CHECK_OK); |
2461 classifier->Accumulate( | 2461 classifier->Accumulate( |
2462 &rhs_classifier, | 2462 &rhs_classifier, |
2463 ExpressionClassifier::ExpressionProductions | | 2463 ExpressionClassifier::ExpressionProductions | |
2464 ExpressionClassifier::ObjectLiteralProduction | | 2464 ExpressionClassifier::ObjectLiteralProduction | |
2465 ExpressionClassifier::AsyncArrowFormalParametersProduction); | 2465 ExpressionClassifier::AsyncArrowFormalParametersProduction); |
2466 | 2466 |
2467 // TODO(1231235): We try to estimate the set of properties set by | 2467 // TODO(1231235): We try to estimate the set of properties set by |
2468 // constructors. We define a new property whenever there is an | 2468 // constructors. We define a new property whenever there is an |
2469 // assignment to a property of 'this'. We should probably only add | 2469 // assignment to a property of 'this'. We should probably only add |
2470 // properties if we haven't seen them before. Otherwise we'll | 2470 // properties if we haven't seen them before. Otherwise we'll |
2471 // probably overestimate the number of properties. | 2471 // probably overestimate the number of properties. |
2472 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { | 2472 if (op == Token::ASSIGN && impl()->IsThisProperty(expression)) { |
2473 function_state_->AddProperty(); | 2473 function_state_->AddProperty(); |
2474 } | 2474 } |
2475 | 2475 |
2476 this->CheckAssigningFunctionLiteralToProperty(expression, right); | 2476 impl()->CheckAssigningFunctionLiteralToProperty(expression, right); |
2477 | 2477 |
2478 if (fni_ != NULL) { | 2478 if (fni_ != NULL) { |
2479 // Check if the right hand side is a call to avoid inferring a | 2479 // Check if the right hand side is a call to avoid inferring a |
2480 // name if we're dealing with "a = function(){...}();"-like | 2480 // name if we're dealing with "a = function(){...}();"-like |
2481 // expression. | 2481 // expression. |
2482 if ((op == Token::INIT || op == Token::ASSIGN) && | 2482 if ((op == Token::INIT || op == Token::ASSIGN) && |
2483 (!right->IsCall() && !right->IsCallNew())) { | 2483 (!right->IsCall() && !right->IsCallNew())) { |
2484 fni_->Infer(); | 2484 fni_->Infer(); |
2485 } else { | 2485 } else { |
2486 fni_->RemoveLastFunction(); | 2486 fni_->RemoveLastFunction(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2573 this->ParseLeftHandSideExpression(classifier, CHECK_OK); | 2573 this->ParseLeftHandSideExpression(classifier, CHECK_OK); |
2574 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2574 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2575 | 2575 |
2576 Scanner::Location loc(pos, scanner()->location().end_pos); | 2576 Scanner::Location loc(pos, scanner()->location().end_pos); |
2577 if (!expression->IsCall()) { | 2577 if (!expression->IsCall()) { |
2578 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos); | 2578 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos); |
2579 ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedInsideTailCall); | 2579 ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedInsideTailCall); |
2580 *ok = false; | 2580 *ok = false; |
2581 return Traits::EmptyExpression(); | 2581 return Traits::EmptyExpression(); |
2582 } | 2582 } |
2583 if (Traits::IsDirectEvalCall(expression)) { | 2583 if (impl()->IsDirectEvalCall(expression)) { |
2584 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos); | 2584 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos); |
2585 ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedTailCallOfEval); | 2585 ReportMessageAt(sub_loc, MessageTemplate::kUnexpectedTailCallOfEval); |
2586 *ok = false; | 2586 *ok = false; |
2587 return Traits::EmptyExpression(); | 2587 return Traits::EmptyExpression(); |
2588 } | 2588 } |
2589 if (!is_strict(language_mode())) { | 2589 if (!is_strict(language_mode())) { |
2590 ReportMessageAt(loc, MessageTemplate::kUnexpectedSloppyTailCall); | 2590 ReportMessageAt(loc, MessageTemplate::kUnexpectedSloppyTailCall); |
2591 *ok = false; | 2591 *ok = false; |
2592 return Traits::EmptyExpression(); | 2592 return Traits::EmptyExpression(); |
2593 } | 2593 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2670 | 2670 |
2671 const bool is_right_associative = op == Token::EXP; | 2671 const bool is_right_associative = op == Token::EXP; |
2672 const int next_prec = is_right_associative ? prec1 : prec1 + 1; | 2672 const int next_prec = is_right_associative ? prec1 : prec1 + 1; |
2673 ExpressionT y = | 2673 ExpressionT y = |
2674 ParseBinaryExpression(next_prec, accept_IN, classifier, CHECK_OK); | 2674 ParseBinaryExpression(next_prec, accept_IN, classifier, CHECK_OK); |
2675 if (op != Token::OR && op != Token::AND) { | 2675 if (op != Token::OR && op != Token::AND) { |
2676 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2676 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2677 } | 2677 } |
2678 impl()->RewriteNonPattern(classifier, CHECK_OK); | 2678 impl()->RewriteNonPattern(classifier, CHECK_OK); |
2679 | 2679 |
2680 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, | 2680 if (impl()->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos)) { |
2681 factory())) { | |
2682 continue; | 2681 continue; |
2683 } | 2682 } |
2684 | 2683 |
2685 // For now we distinguish between comparisons and other binary | 2684 // For now we distinguish between comparisons and other binary |
2686 // operations. (We could combine the two and get rid of this | 2685 // operations. (We could combine the two and get rid of this |
2687 // code and AST node eventually.) | 2686 // code and AST node eventually.) |
2688 if (Token::IsCompareOp(op)) { | 2687 if (Token::IsCompareOp(op)) { |
2689 // We have a comparison. | 2688 // We have a comparison. |
2690 Token::Value cmp = op; | 2689 Token::Value cmp = op; |
2691 switch (op) { | 2690 switch (op) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2730 BindingPatternUnexpectedToken(classifier); | 2729 BindingPatternUnexpectedToken(classifier); |
2731 ArrowFormalParametersUnexpectedToken(classifier); | 2730 ArrowFormalParametersUnexpectedToken(classifier); |
2732 | 2731 |
2733 op = Next(); | 2732 op = Next(); |
2734 int pos = position(); | 2733 int pos = position(); |
2735 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); | 2734 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); |
2736 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2735 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2737 impl()->RewriteNonPattern(classifier, CHECK_OK); | 2736 impl()->RewriteNonPattern(classifier, CHECK_OK); |
2738 | 2737 |
2739 if (op == Token::DELETE && is_strict(language_mode())) { | 2738 if (op == Token::DELETE && is_strict(language_mode())) { |
2740 if (this->IsIdentifier(expression)) { | 2739 if (impl()->IsIdentifier(expression)) { |
2741 // "delete identifier" is a syntax error in strict mode. | 2740 // "delete identifier" is a syntax error in strict mode. |
2742 ReportMessage(MessageTemplate::kStrictDelete); | 2741 ReportMessage(MessageTemplate::kStrictDelete); |
2743 *ok = false; | 2742 *ok = false; |
2744 return this->EmptyExpression(); | 2743 return this->EmptyExpression(); |
2745 } | 2744 } |
2746 } | 2745 } |
2747 | 2746 |
2748 if (peek() == Token::EXP) { | 2747 if (peek() == Token::EXP) { |
2749 ReportUnexpectedToken(Next()); | 2748 ReportUnexpectedToken(Next()); |
2750 *ok = false; | 2749 *ok = false; |
2751 return this->EmptyExpression(); | 2750 return this->EmptyExpression(); |
2752 } | 2751 } |
2753 | 2752 |
2754 // Allow Traits do rewrite the expression. | 2753 // Allow Traits do rewrite the expression. |
2755 return this->BuildUnaryExpression(expression, op, pos, factory()); | 2754 return this->BuildUnaryExpression(expression, op, pos, factory()); |
2756 } else if (Token::IsCountOp(op)) { | 2755 } else if (Token::IsCountOp(op)) { |
2757 BindingPatternUnexpectedToken(classifier); | 2756 BindingPatternUnexpectedToken(classifier); |
2758 ArrowFormalParametersUnexpectedToken(classifier); | 2757 ArrowFormalParametersUnexpectedToken(classifier); |
2759 op = Next(); | 2758 op = Next(); |
2760 int beg_pos = peek_position(); | 2759 int beg_pos = peek_position(); |
2761 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); | 2760 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); |
2762 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2761 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2763 expression = this->CheckAndRewriteReferenceExpression( | 2762 expression = this->CheckAndRewriteReferenceExpression( |
2764 expression, beg_pos, scanner()->location().end_pos, | 2763 expression, beg_pos, scanner()->location().end_pos, |
2765 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 2764 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
2766 this->MarkExpressionAsAssigned(expression); | 2765 expression = impl()->MarkExpressionAsAssigned(expression); |
2767 impl()->RewriteNonPattern(classifier, CHECK_OK); | 2766 impl()->RewriteNonPattern(classifier, CHECK_OK); |
2768 | 2767 |
2769 return factory()->NewCountOperation(op, | 2768 return factory()->NewCountOperation(op, |
2770 true /* prefix */, | 2769 true /* prefix */, |
2771 expression, | 2770 expression, |
2772 position()); | 2771 position()); |
2773 | 2772 |
2774 } else if (is_async_function() && peek() == Token::AWAIT) { | 2773 } else if (is_async_function() && peek() == Token::AWAIT) { |
2775 classifier->RecordFormalParameterInitializerError( | 2774 classifier->RecordFormalParameterInitializerError( |
2776 scanner()->peek_location(), | 2775 scanner()->peek_location(), |
(...skipping 21 matching lines...) Expand all Loading... |
2798 this->ParseLeftHandSideExpression(classifier, CHECK_OK); | 2797 this->ParseLeftHandSideExpression(classifier, CHECK_OK); |
2799 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 2798 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
2800 Token::IsCountOp(peek())) { | 2799 Token::IsCountOp(peek())) { |
2801 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2800 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2802 BindingPatternUnexpectedToken(classifier); | 2801 BindingPatternUnexpectedToken(classifier); |
2803 ArrowFormalParametersUnexpectedToken(classifier); | 2802 ArrowFormalParametersUnexpectedToken(classifier); |
2804 | 2803 |
2805 expression = this->CheckAndRewriteReferenceExpression( | 2804 expression = this->CheckAndRewriteReferenceExpression( |
2806 expression, lhs_beg_pos, scanner()->location().end_pos, | 2805 expression, lhs_beg_pos, scanner()->location().end_pos, |
2807 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); | 2806 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); |
2808 expression = this->MarkExpressionAsAssigned(expression); | 2807 expression = impl()->MarkExpressionAsAssigned(expression); |
2809 impl()->RewriteNonPattern(classifier, CHECK_OK); | 2808 impl()->RewriteNonPattern(classifier, CHECK_OK); |
2810 | 2809 |
2811 Token::Value next = Next(); | 2810 Token::Value next = Next(); |
2812 expression = | 2811 expression = |
2813 factory()->NewCountOperation(next, | 2812 factory()->NewCountOperation(next, |
2814 false /* postfix */, | 2813 false /* postfix */, |
2815 expression, | 2814 expression, |
2816 position()); | 2815 position()); |
2817 } | 2816 } |
2818 return expression; | 2817 return expression; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2869 pos = peek_position(); | 2868 pos = peek_position(); |
2870 // Also the trailing parenthesis are a hint that the function will | 2869 // Also the trailing parenthesis are a hint that the function will |
2871 // be called immediately. If we happen to have parsed a preceding | 2870 // be called immediately. If we happen to have parsed a preceding |
2872 // function literal eagerly, we can also compile it eagerly. | 2871 // function literal eagerly, we can also compile it eagerly. |
2873 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 2872 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
2874 result->AsFunctionLiteral()->set_should_eager_compile(); | 2873 result->AsFunctionLiteral()->set_should_eager_compile(); |
2875 } | 2874 } |
2876 } | 2875 } |
2877 Scanner::Location spread_pos; | 2876 Scanner::Location spread_pos; |
2878 typename Traits::Type::ExpressionList args; | 2877 typename Traits::Type::ExpressionList args; |
2879 if (V8_UNLIKELY(is_async && this->IsIdentifier(result))) { | 2878 if (V8_UNLIKELY(is_async && impl()->IsIdentifier(result))) { |
2880 ExpressionClassifier async_classifier(this); | 2879 ExpressionClassifier async_classifier(this); |
2881 args = ParseArguments(&spread_pos, true, &async_classifier, CHECK_OK); | 2880 args = ParseArguments(&spread_pos, true, &async_classifier, CHECK_OK); |
2882 if (peek() == Token::ARROW) { | 2881 if (peek() == Token::ARROW) { |
2883 if (fni_) { | 2882 if (fni_) { |
2884 fni_->RemoveAsyncKeywordFromEnd(); | 2883 fni_->RemoveAsyncKeywordFromEnd(); |
2885 } | 2884 } |
2886 ValidateBindingPattern(&async_classifier, CHECK_OK); | 2885 ValidateBindingPattern(&async_classifier, CHECK_OK); |
2887 if (!async_classifier.is_valid_async_arrow_formal_parameters()) { | 2886 if (!async_classifier.is_valid_async_arrow_formal_parameters()) { |
2888 ReportClassifierError( | 2887 ReportClassifierError( |
2889 async_classifier.async_arrow_formal_parameters_error()); | 2888 async_classifier.async_arrow_formal_parameters_error()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2939 case Token::PERIOD: { | 2938 case Token::PERIOD: { |
2940 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2939 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2941 impl()->RewriteNonPattern(classifier, CHECK_OK); | 2940 impl()->RewriteNonPattern(classifier, CHECK_OK); |
2942 BindingPatternUnexpectedToken(classifier); | 2941 BindingPatternUnexpectedToken(classifier); |
2943 ArrowFormalParametersUnexpectedToken(classifier); | 2942 ArrowFormalParametersUnexpectedToken(classifier); |
2944 Consume(Token::PERIOD); | 2943 Consume(Token::PERIOD); |
2945 int pos = position(); | 2944 int pos = position(); |
2946 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2945 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2947 result = factory()->NewProperty( | 2946 result = factory()->NewProperty( |
2948 result, factory()->NewStringLiteral(name, pos), pos); | 2947 result, factory()->NewStringLiteral(name, pos), pos); |
2949 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 2948 if (fni_ != NULL) impl()->PushLiteralName(fni_, name); |
2950 break; | 2949 break; |
2951 } | 2950 } |
2952 | 2951 |
2953 case Token::TEMPLATE_SPAN: | 2952 case Token::TEMPLATE_SPAN: |
2954 case Token::TEMPLATE_TAIL: { | 2953 case Token::TEMPLATE_TAIL: { |
2955 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2954 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2956 impl()->RewriteNonPattern(classifier, CHECK_OK); | 2955 impl()->RewriteNonPattern(classifier, CHECK_OK); |
2957 BindingPatternUnexpectedToken(classifier); | 2956 BindingPatternUnexpectedToken(classifier); |
2958 ArrowFormalParametersUnexpectedToken(classifier); | 2957 ArrowFormalParametersUnexpectedToken(classifier); |
2959 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); | 2958 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3171 impl()->RewriteNonPattern(classifier, CHECK_OK); | 3170 impl()->RewriteNonPattern(classifier, CHECK_OK); |
3172 BindingPatternUnexpectedToken(classifier); | 3171 BindingPatternUnexpectedToken(classifier); |
3173 ArrowFormalParametersUnexpectedToken(classifier); | 3172 ArrowFormalParametersUnexpectedToken(classifier); |
3174 | 3173 |
3175 Consume(Token::LBRACK); | 3174 Consume(Token::LBRACK); |
3176 int pos = position(); | 3175 int pos = position(); |
3177 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 3176 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
3178 impl()->RewriteNonPattern(classifier, CHECK_OK); | 3177 impl()->RewriteNonPattern(classifier, CHECK_OK); |
3179 expression = factory()->NewProperty(expression, index, pos); | 3178 expression = factory()->NewProperty(expression, index, pos); |
3180 if (fni_ != NULL) { | 3179 if (fni_ != NULL) { |
3181 this->PushPropertyName(fni_, index); | 3180 impl()->PushPropertyName(fni_, index); |
3182 } | 3181 } |
3183 Expect(Token::RBRACK, CHECK_OK); | 3182 Expect(Token::RBRACK, CHECK_OK); |
3184 break; | 3183 break; |
3185 } | 3184 } |
3186 case Token::PERIOD: { | 3185 case Token::PERIOD: { |
3187 *is_async = false; | 3186 *is_async = false; |
3188 impl()->RewriteNonPattern(classifier, CHECK_OK); | 3187 impl()->RewriteNonPattern(classifier, CHECK_OK); |
3189 BindingPatternUnexpectedToken(classifier); | 3188 BindingPatternUnexpectedToken(classifier); |
3190 ArrowFormalParametersUnexpectedToken(classifier); | 3189 ArrowFormalParametersUnexpectedToken(classifier); |
3191 | 3190 |
3192 Consume(Token::PERIOD); | 3191 Consume(Token::PERIOD); |
3193 int pos = position(); | 3192 int pos = position(); |
3194 IdentifierT name = ParseIdentifierName(CHECK_OK); | 3193 IdentifierT name = ParseIdentifierName(CHECK_OK); |
3195 expression = factory()->NewProperty( | 3194 expression = factory()->NewProperty( |
3196 expression, factory()->NewStringLiteral(name, pos), pos); | 3195 expression, factory()->NewStringLiteral(name, pos), pos); |
3197 if (fni_ != NULL) { | 3196 if (fni_ != NULL) { |
3198 this->PushLiteralName(fni_, name); | 3197 impl()->PushLiteralName(fni_, name); |
3199 } | 3198 } |
3200 break; | 3199 break; |
3201 } | 3200 } |
3202 case Token::TEMPLATE_SPAN: | 3201 case Token::TEMPLATE_SPAN: |
3203 case Token::TEMPLATE_TAIL: { | 3202 case Token::TEMPLATE_TAIL: { |
3204 *is_async = false; | 3203 *is_async = false; |
3205 impl()->RewriteNonPattern(classifier, CHECK_OK); | 3204 impl()->RewriteNonPattern(classifier, CHECK_OK); |
3206 BindingPatternUnexpectedToken(classifier); | 3205 BindingPatternUnexpectedToken(classifier); |
3207 ArrowFormalParametersUnexpectedToken(classifier); | 3206 ArrowFormalParametersUnexpectedToken(classifier); |
3208 int pos; | 3207 int pos; |
(...skipping 29 matching lines...) Expand all Loading... |
3238 ExpressionClassifier* classifier, | 3237 ExpressionClassifier* classifier, |
3239 bool* ok) { | 3238 bool* ok) { |
3240 // FormalParameter[Yield,GeneratorParameter] : | 3239 // FormalParameter[Yield,GeneratorParameter] : |
3241 // BindingElement[?Yield, ?GeneratorParameter] | 3240 // BindingElement[?Yield, ?GeneratorParameter] |
3242 bool is_rest = parameters->has_rest; | 3241 bool is_rest = parameters->has_rest; |
3243 | 3242 |
3244 ExpressionT pattern = | 3243 ExpressionT pattern = |
3245 ParsePrimaryExpression(classifier, CHECK_OK_CUSTOM(Void)); | 3244 ParsePrimaryExpression(classifier, CHECK_OK_CUSTOM(Void)); |
3246 ValidateBindingPattern(classifier, CHECK_OK_CUSTOM(Void)); | 3245 ValidateBindingPattern(classifier, CHECK_OK_CUSTOM(Void)); |
3247 | 3246 |
3248 if (!Traits::IsIdentifier(pattern)) { | 3247 if (!impl()->IsIdentifier(pattern)) { |
3249 parameters->is_simple = false; | 3248 parameters->is_simple = false; |
3250 ValidateFormalParameterInitializer(classifier, CHECK_OK_CUSTOM(Void)); | 3249 ValidateFormalParameterInitializer(classifier, CHECK_OK_CUSTOM(Void)); |
3251 classifier->RecordNonSimpleParameter(); | 3250 classifier->RecordNonSimpleParameter(); |
3252 } | 3251 } |
3253 | 3252 |
3254 ExpressionT initializer = Traits::EmptyExpression(); | 3253 ExpressionT initializer = Traits::EmptyExpression(); |
3255 if (!is_rest && Check(Token::ASSIGN)) { | 3254 if (!is_rest && Check(Token::ASSIGN)) { |
3256 ExpressionClassifier init_classifier(this); | 3255 ExpressionClassifier init_classifier(this); |
3257 initializer = ParseAssignmentExpression(true, &init_classifier, | 3256 initializer = ParseAssignmentExpression(true, &init_classifier, |
3258 CHECK_OK_CUSTOM(Void)); | 3257 CHECK_OK_CUSTOM(Void)); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3496 this->EmptyIdentifierString(), formal_parameters.scope, body, | 3495 this->EmptyIdentifierString(), formal_parameters.scope, body, |
3497 materialized_literal_count, expected_property_count, num_parameters, | 3496 materialized_literal_count, expected_property_count, num_parameters, |
3498 FunctionLiteral::kNoDuplicateParameters, | 3497 FunctionLiteral::kNoDuplicateParameters, |
3499 FunctionLiteral::kAnonymousExpression, | 3498 FunctionLiteral::kAnonymousExpression, |
3500 FunctionLiteral::kShouldLazyCompile, arrow_kind, | 3499 FunctionLiteral::kShouldLazyCompile, arrow_kind, |
3501 formal_parameters.scope->start_position()); | 3500 formal_parameters.scope->start_position()); |
3502 | 3501 |
3503 function_literal->set_function_token_position( | 3502 function_literal->set_function_token_position( |
3504 formal_parameters.scope->start_position()); | 3503 formal_parameters.scope->start_position()); |
3505 | 3504 |
3506 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 3505 if (fni_ != NULL) impl()->InferFunctionName(fni_, function_literal); |
3507 | 3506 |
3508 return function_literal; | 3507 return function_literal; |
3509 } | 3508 } |
3510 | 3509 |
3511 template <typename Impl> | 3510 template <typename Impl> |
3512 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( | 3511 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( |
3513 ExpressionT tag, int start, ExpressionClassifier* classifier, bool* ok) { | 3512 ExpressionT tag, int start, ExpressionClassifier* classifier, bool* ok) { |
3514 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal | 3513 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal |
3515 // text followed by a substitution expression), finalized by a single | 3514 // text followed by a substitution expression), finalized by a single |
3516 // TEMPLATE_TAIL. | 3515 // TEMPLATE_TAIL. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3609 MessageTemplate::Template message, bool* ok) { | 3608 MessageTemplate::Template message, bool* ok) { |
3610 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, | 3609 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, |
3611 message, kReferenceError, ok); | 3610 message, kReferenceError, ok); |
3612 } | 3611 } |
3613 | 3612 |
3614 template <typename Impl> | 3613 template <typename Impl> |
3615 typename ParserBase<Impl>::ExpressionT | 3614 typename ParserBase<Impl>::ExpressionT |
3616 ParserBase<Impl>::CheckAndRewriteReferenceExpression( | 3615 ParserBase<Impl>::CheckAndRewriteReferenceExpression( |
3617 ExpressionT expression, int beg_pos, int end_pos, | 3616 ExpressionT expression, int beg_pos, int end_pos, |
3618 MessageTemplate::Template message, ParseErrorType type, bool* ok) { | 3617 MessageTemplate::Template message, ParseErrorType type, bool* ok) { |
3619 if (this->IsIdentifier(expression) && is_strict(language_mode()) && | 3618 if (impl()->IsIdentifier(expression) && is_strict(language_mode()) && |
3620 this->IsEvalOrArguments(this->AsIdentifier(expression))) { | 3619 impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) { |
3621 ReportMessageAt(Scanner::Location(beg_pos, end_pos), | 3620 ReportMessageAt(Scanner::Location(beg_pos, end_pos), |
3622 MessageTemplate::kStrictEvalArguments, kSyntaxError); | 3621 MessageTemplate::kStrictEvalArguments, kSyntaxError); |
3623 *ok = false; | 3622 *ok = false; |
3624 return this->EmptyExpression(); | 3623 return this->EmptyExpression(); |
3625 } | 3624 } |
3626 if (expression->IsValidReferenceExpression()) { | 3625 if (expression->IsValidReferenceExpression()) { |
3627 return expression; | 3626 return expression; |
3628 } | 3627 } |
3629 if (expression->IsCall()) { | 3628 if (expression->IsCall()) { |
3630 // If it is a call, make it a runtime error for legacy web compatibility. | 3629 // If it is a call, make it a runtime error for legacy web compatibility. |
3631 // Rewrite `expr' to `expr[throw ReferenceError]'. | 3630 // Rewrite `expr' to `expr[throw ReferenceError]'. |
3632 ExpressionT error = this->NewThrowReferenceError(message, beg_pos); | 3631 ExpressionT error = this->NewThrowReferenceError(message, beg_pos); |
3633 return factory()->NewProperty(expression, error, beg_pos); | 3632 return factory()->NewProperty(expression, error, beg_pos); |
3634 } | 3633 } |
3635 ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type); | 3634 ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type); |
3636 *ok = false; | 3635 *ok = false; |
3637 return this->EmptyExpression(); | 3636 return this->EmptyExpression(); |
3638 } | 3637 } |
3639 | 3638 |
3640 template <typename Impl> | 3639 template <typename Impl> |
3641 bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) { | 3640 bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) { |
3642 return this->IsAssignableIdentifier(expression) || expression->IsProperty(); | 3641 return IsAssignableIdentifier(expression) || expression->IsProperty(); |
3643 } | 3642 } |
3644 | 3643 |
3645 template <typename Impl> | 3644 template <typename Impl> |
3646 void ParserBase<Impl>::CheckDestructuringElement( | 3645 void ParserBase<Impl>::CheckDestructuringElement( |
3647 ExpressionT expression, ExpressionClassifier* classifier, int begin, | 3646 ExpressionT expression, ExpressionClassifier* classifier, int begin, |
3648 int end) { | 3647 int end) { |
3649 if (!IsValidPattern(expression) && !expression->IsAssignment() && | 3648 if (!IsValidPattern(expression) && !expression->IsAssignment() && |
3650 !IsValidReferenceExpression(expression)) { | 3649 !IsValidReferenceExpression(expression)) { |
3651 classifier->RecordAssignmentPatternError( | 3650 classifier->RecordAssignmentPatternError( |
3652 Scanner::Location(begin, end), | 3651 Scanner::Location(begin, end), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3711 has_seen_constructor_ = true; | 3710 has_seen_constructor_ = true; |
3712 return; | 3711 return; |
3713 } | 3712 } |
3714 } | 3713 } |
3715 | 3714 |
3716 | 3715 |
3717 } // namespace internal | 3716 } // namespace internal |
3718 } // namespace v8 | 3717 } // namespace v8 |
3719 | 3718 |
3720 #endif // V8_PARSING_PARSER_BASE_H | 3719 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |