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/hashmap.h" | 10 #include "src/hashmap.h" |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 ExpressionClassifier* classifier, bool* ok); | 752 ExpressionClassifier* classifier, bool* ok); |
753 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); | 753 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
754 ObjectLiteralPropertyT ParsePropertyDefinition( | 754 ObjectLiteralPropertyT ParsePropertyDefinition( |
755 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 755 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
756 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 756 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
757 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); | 757 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); |
758 typename Traits::Type::ExpressionList ParseArguments( | 758 typename Traits::Type::ExpressionList ParseArguments( |
759 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, | 759 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, |
760 bool* ok); | 760 bool* ok); |
761 | 761 |
762 enum AssignmentExpressionFlags { | |
763 kIsNormalAssignment, | |
764 kIsPossiblePatternElement | |
765 }; | |
766 | |
767 ExpressionT ParseAssignmentExpression(bool accept_IN, | 762 ExpressionT ParseAssignmentExpression(bool accept_IN, |
768 AssignmentExpressionFlags flags, | |
769 ExpressionClassifier* classifier, | 763 ExpressionClassifier* classifier, |
770 bool* ok); | 764 bool* ok); |
771 ExpressionT ParseAssignmentExpression(bool accept_IN, | |
772 ExpressionClassifier* classifier, | |
773 bool* ok) { | |
774 return ParseAssignmentExpression(accept_IN, kIsNormalAssignment, classifier, | |
775 ok); | |
776 } | |
777 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); | 765 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); |
778 ExpressionT ParseConditionalExpression(bool accept_IN, | 766 ExpressionT ParseConditionalExpression(bool accept_IN, |
779 ExpressionClassifier* classifier, | 767 ExpressionClassifier* classifier, |
780 bool* ok); | 768 bool* ok); |
781 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, | 769 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, |
782 ExpressionClassifier* classifier, bool* ok); | 770 ExpressionClassifier* classifier, bool* ok); |
783 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 771 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
784 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 772 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
785 bool* ok); | 773 bool* ok); |
786 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, | 774 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 Traits::IsEvalOrArguments(Traits::AsIdentifier(expression))) { | 825 Traits::IsEvalOrArguments(Traits::AsIdentifier(expression))) { |
838 return false; | 826 return false; |
839 } | 827 } |
840 if (is_strong(language_mode()) && | 828 if (is_strong(language_mode()) && |
841 Traits::IsUndefined(Traits::AsIdentifier(expression))) { | 829 Traits::IsUndefined(Traits::AsIdentifier(expression))) { |
842 return false; | 830 return false; |
843 } | 831 } |
844 return true; | 832 return true; |
845 } | 833 } |
846 | 834 |
| 835 bool IsAssignmentExpression(ExpressionT expression) { |
| 836 return expression->IsAssignment() || |
| 837 expression->IsRewritableAssignmentExpression(); |
| 838 } |
| 839 |
| 840 bool IsValidPattern(ExpressionT expression) { |
| 841 return expression->IsObjectLiteral() || expression->IsArrayLiteral(); |
| 842 } |
| 843 |
847 // Keep track of eval() calls since they disable all local variable | 844 // Keep track of eval() calls since they disable all local variable |
848 // optimizations. This checks if expression is an eval call, and if yes, | 845 // optimizations. This checks if expression is an eval call, and if yes, |
849 // forwards the information to scope. | 846 // forwards the information to scope. |
850 void CheckPossibleEvalCall(ExpressionT expression, Scope* scope) { | 847 void CheckPossibleEvalCall(ExpressionT expression, Scope* scope) { |
851 if (Traits::IsIdentifier(expression) && | 848 if (Traits::IsIdentifier(expression) && |
852 Traits::IsEval(Traits::AsIdentifier(expression))) { | 849 Traits::IsEval(Traits::AsIdentifier(expression))) { |
853 scope->DeclarationScope()->RecordEvalCall(); | 850 scope->DeclarationScope()->RecordEvalCall(); |
854 scope->RecordEvalCall(); | 851 scope->RecordEvalCall(); |
855 } | 852 } |
856 } | 853 } |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 // (...x)=>x. The continuation that looks for the => is in | 1335 // (...x)=>x. The continuation that looks for the => is in |
1339 // ParseAssignmentExpression. | 1336 // ParseAssignmentExpression. |
1340 int ellipsis_pos = position(); | 1337 int ellipsis_pos = position(); |
1341 int expr_pos = peek_position(); | 1338 int expr_pos = peek_position(); |
1342 classifier->RecordExpressionError(scanner()->location(), | 1339 classifier->RecordExpressionError(scanner()->location(), |
1343 MessageTemplate::kUnexpectedToken, | 1340 MessageTemplate::kUnexpectedToken, |
1344 Token::String(Token::ELLIPSIS)); | 1341 Token::String(Token::ELLIPSIS)); |
1345 classifier->RecordNonSimpleParameter(); | 1342 classifier->RecordNonSimpleParameter(); |
1346 ExpressionT expr = | 1343 ExpressionT expr = |
1347 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 1344 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
1348 if (!this->IsIdentifier(expr) && !expr->IsObjectLiteral() && | 1345 if (!this->IsIdentifier(expr) && !IsValidPattern(expr)) { |
1349 !expr->IsArrayLiteral()) { | |
1350 classifier->RecordArrowFormalParametersError( | 1346 classifier->RecordArrowFormalParametersError( |
1351 Scanner::Location(ellipsis_pos, scanner()->location().end_pos), | 1347 Scanner::Location(ellipsis_pos, scanner()->location().end_pos), |
1352 MessageTemplate::kInvalidRestParameter); | 1348 MessageTemplate::kInvalidRestParameter); |
1353 } | 1349 } |
1354 if (peek() == Token::COMMA) { | 1350 if (peek() == Token::COMMA) { |
1355 ReportMessageAt(scanner()->peek_location(), | 1351 ReportMessageAt(scanner()->peek_location(), |
1356 MessageTemplate::kParamAfterRest); | 1352 MessageTemplate::kParamAfterRest); |
1357 *ok = false; | 1353 *ok = false; |
1358 return this->EmptyExpression(); | 1354 return this->EmptyExpression(); |
1359 } | 1355 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 // valid expression or binding pattern. | 1455 // valid expression or binding pattern. |
1460 ExpressionUnexpectedToken(classifier); | 1456 ExpressionUnexpectedToken(classifier); |
1461 BindingPatternUnexpectedToken(classifier); | 1457 BindingPatternUnexpectedToken(classifier); |
1462 Consume(Token::ELLIPSIS); | 1458 Consume(Token::ELLIPSIS); |
1463 seen_rest = is_rest = true; | 1459 seen_rest = is_rest = true; |
1464 } | 1460 } |
1465 int pos = position(), expr_pos = peek_position(); | 1461 int pos = position(), expr_pos = peek_position(); |
1466 ExpressionT right = this->ParseAssignmentExpression( | 1462 ExpressionT right = this->ParseAssignmentExpression( |
1467 accept_IN, &binding_classifier, CHECK_OK); | 1463 accept_IN, &binding_classifier, CHECK_OK); |
1468 if (is_rest) { | 1464 if (is_rest) { |
1469 if (!this->IsIdentifier(right) && !right->IsObjectLiteral() && | 1465 if (!this->IsIdentifier(right) && !IsValidPattern(right)) { |
1470 !right->IsArrayLiteral()) { | |
1471 classifier->RecordArrowFormalParametersError( | 1466 classifier->RecordArrowFormalParametersError( |
1472 Scanner::Location(pos, scanner()->location().end_pos), | 1467 Scanner::Location(pos, scanner()->location().end_pos), |
1473 MessageTemplate::kInvalidRestParameter); | 1468 MessageTemplate::kInvalidRestParameter); |
1474 } | 1469 } |
1475 right = factory()->NewSpread(right, pos, expr_pos); | 1470 right = factory()->NewSpread(right, pos, expr_pos); |
1476 } | 1471 } |
1477 is_simple_parameter_list = | 1472 is_simple_parameter_list = |
1478 is_simple_parameter_list && this->IsIdentifier(right); | 1473 is_simple_parameter_list && this->IsIdentifier(right); |
1479 classifier->Accumulate(binding_classifier, | 1474 classifier->Accumulate(binding_classifier, |
1480 ExpressionClassifier::AllProductions); | 1475 ExpressionClassifier::AllProductions); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 Consume(Token::ELLIPSIS); | 1509 Consume(Token::ELLIPSIS); |
1515 int expr_pos = peek_position(); | 1510 int expr_pos = peek_position(); |
1516 ExpressionT argument = | 1511 ExpressionT argument = |
1517 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 1512 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
1518 elem = factory()->NewSpread(argument, start_pos, expr_pos); | 1513 elem = factory()->NewSpread(argument, start_pos, expr_pos); |
1519 | 1514 |
1520 if (first_spread_index < 0) { | 1515 if (first_spread_index < 0) { |
1521 first_spread_index = values->length(); | 1516 first_spread_index = values->length(); |
1522 } | 1517 } |
1523 | 1518 |
1524 if (argument->IsAssignment()) { | 1519 if (IsAssignmentExpression(argument)) { |
1525 classifier->RecordPatternError( | 1520 classifier->RecordPatternError( |
1526 Scanner::Location(start_pos, scanner()->location().end_pos), | 1521 Scanner::Location(start_pos, scanner()->location().end_pos), |
1527 MessageTemplate::kInvalidDestructuringTarget); | 1522 MessageTemplate::kInvalidDestructuringTarget); |
1528 } else { | 1523 } else { |
1529 CheckDestructuringElement(argument, classifier, start_pos, | 1524 CheckDestructuringElement(argument, classifier, start_pos, |
1530 scanner()->location().end_pos); | 1525 scanner()->location().end_pos); |
1531 } | 1526 } |
1532 | 1527 |
1533 if (peek() == Token::COMMA) { | 1528 if (peek() == Token::COMMA) { |
1534 classifier->RecordPatternError( | 1529 classifier->RecordPatternError( |
1535 Scanner::Location(start_pos, scanner()->location().end_pos), | 1530 Scanner::Location(start_pos, scanner()->location().end_pos), |
1536 MessageTemplate::kElementAfterRest); | 1531 MessageTemplate::kElementAfterRest); |
1537 } | 1532 } |
1538 } else { | 1533 } else { |
1539 elem = this->ParseAssignmentExpression(true, kIsPossiblePatternElement, | 1534 int beg_pos = peek_position(); |
1540 classifier, CHECK_OK); | 1535 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
| 1536 CheckDestructuringElement(elem, classifier, beg_pos, |
| 1537 scanner()->location().end_pos); |
1541 } | 1538 } |
1542 values->Add(elem, zone_); | 1539 values->Add(elem, zone_); |
1543 if (peek() != Token::RBRACK) { | 1540 if (peek() != Token::RBRACK) { |
1544 Expect(Token::COMMA, CHECK_OK); | 1541 Expect(Token::COMMA, CHECK_OK); |
1545 } | 1542 } |
1546 } | 1543 } |
1547 Expect(Token::RBRACK, CHECK_OK); | 1544 Expect(Token::RBRACK, CHECK_OK); |
1548 | 1545 |
1549 // Update the scope information before the pre-parsing bailout. | 1546 // Update the scope information before the pre-parsing bailout. |
1550 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1547 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 DCHECK(!is_static); | 1637 DCHECK(!is_static); |
1641 | 1638 |
1642 if (peek() == Token::COLON) { | 1639 if (peek() == Token::COLON) { |
1643 // PropertyDefinition | 1640 // PropertyDefinition |
1644 // PropertyName ':' AssignmentExpression | 1641 // PropertyName ':' AssignmentExpression |
1645 if (!*is_computed_name) { | 1642 if (!*is_computed_name) { |
1646 checker->CheckProperty(name_token, kValueProperty, false, false, | 1643 checker->CheckProperty(name_token, kValueProperty, false, false, |
1647 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1644 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1648 } | 1645 } |
1649 Consume(Token::COLON); | 1646 Consume(Token::COLON); |
| 1647 int beg_pos = peek_position(); |
1650 value = this->ParseAssignmentExpression( | 1648 value = this->ParseAssignmentExpression( |
1651 true, kIsPossiblePatternElement, classifier, | 1649 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1652 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1650 CheckDestructuringElement(value, classifier, beg_pos, |
| 1651 scanner()->location().end_pos); |
1653 | 1652 |
1654 return factory()->NewObjectLiteralProperty(name_expression, value, false, | 1653 return factory()->NewObjectLiteralProperty(name_expression, value, false, |
1655 *is_computed_name); | 1654 *is_computed_name); |
1656 } | 1655 } |
1657 | 1656 |
1658 if (Token::IsIdentifier(name_token, language_mode(), | 1657 if (Token::IsIdentifier(name_token, language_mode(), |
1659 this->is_generator()) && | 1658 this->is_generator()) && |
1660 (peek() == Token::COMMA || peek() == Token::RBRACE || | 1659 (peek() == Token::COMMA || peek() == Token::RBRACE || |
1661 peek() == Token::ASSIGN)) { | 1660 peek() == Token::ASSIGN)) { |
1662 // PropertyDefinition | 1661 // PropertyDefinition |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); | 1936 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); |
1938 } | 1937 } |
1939 | 1938 |
1940 return result; | 1939 return result; |
1941 } | 1940 } |
1942 | 1941 |
1943 // Precedence = 2 | 1942 // Precedence = 2 |
1944 template <class Traits> | 1943 template <class Traits> |
1945 typename ParserBase<Traits>::ExpressionT | 1944 typename ParserBase<Traits>::ExpressionT |
1946 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, | 1945 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
1947 AssignmentExpressionFlags flags, | |
1948 ExpressionClassifier* classifier, | 1946 ExpressionClassifier* classifier, |
1949 bool* ok) { | 1947 bool* ok) { |
1950 // AssignmentExpression :: | 1948 // AssignmentExpression :: |
1951 // ConditionalExpression | 1949 // ConditionalExpression |
1952 // ArrowFunction | 1950 // ArrowFunction |
1953 // YieldExpression | 1951 // YieldExpression |
1954 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 1952 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
1955 bool maybe_pattern_element = flags == kIsPossiblePatternElement; | |
1956 bool is_destructuring_assignment = false; | 1953 bool is_destructuring_assignment = false; |
1957 int lhs_beg_pos = peek_position(); | 1954 int lhs_beg_pos = peek_position(); |
1958 | 1955 |
1959 if (peek() == Token::YIELD && is_generator()) { | 1956 if (peek() == Token::YIELD && is_generator()) { |
1960 return this->ParseYieldExpression(classifier, ok); | 1957 return this->ParseYieldExpression(classifier, ok); |
1961 } | 1958 } |
1962 | 1959 |
1963 FuncNameInferrer::State fni_state(fni_); | 1960 FuncNameInferrer::State fni_state(fni_); |
1964 ParserBase<Traits>::Checkpoint checkpoint(this); | 1961 ParserBase<Traits>::Checkpoint checkpoint(this); |
1965 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); | 1962 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2011 } | 2008 } |
2012 | 2009 |
2013 // "expression" was not itself an arrow function parameter list, but it might | 2010 // "expression" was not itself an arrow function parameter list, but it might |
2014 // form part of one. Propagate speculative formal parameter error locations. | 2011 // form part of one. Propagate speculative formal parameter error locations. |
2015 classifier->Accumulate( | 2012 classifier->Accumulate( |
2016 arrow_formals_classifier, | 2013 arrow_formals_classifier, |
2017 ExpressionClassifier::StandardProductions | | 2014 ExpressionClassifier::StandardProductions | |
2018 ExpressionClassifier::FormalParametersProductions | | 2015 ExpressionClassifier::FormalParametersProductions | |
2019 ExpressionClassifier::CoverInitializedNameProduction); | 2016 ExpressionClassifier::CoverInitializedNameProduction); |
2020 | 2017 |
2021 bool maybe_pattern = | |
2022 expression->IsObjectLiteral() || expression->IsArrayLiteral(); | |
2023 | |
2024 if (!Token::IsAssignmentOp(peek())) { | 2018 if (!Token::IsAssignmentOp(peek())) { |
2025 // Parsed conditional expression only (no assignment). | 2019 // Parsed conditional expression only (no assignment). |
2026 if (maybe_pattern_element) { | |
2027 CheckDestructuringElement(expression, classifier, lhs_beg_pos, | |
2028 scanner()->location().end_pos); | |
2029 } | |
2030 return expression; | 2020 return expression; |
2031 } | 2021 } |
2032 | 2022 |
2033 if (!(allow_harmony_destructuring_bind() || | 2023 if (!(allow_harmony_destructuring_bind() || |
2034 allow_harmony_default_parameters())) { | 2024 allow_harmony_default_parameters())) { |
2035 BindingPatternUnexpectedToken(classifier); | 2025 BindingPatternUnexpectedToken(classifier); |
2036 } | 2026 } |
2037 | 2027 |
2038 if (allow_harmony_destructuring_assignment() && maybe_pattern && | 2028 if (allow_harmony_destructuring_assignment() && IsValidPattern(expression) && |
2039 peek() == Token::ASSIGN) { | 2029 peek() == Token::ASSIGN) { |
2040 classifier->ForgiveCoverInitializedNameError(); | 2030 classifier->ForgiveCoverInitializedNameError(); |
2041 ValidateAssignmentPattern(classifier, CHECK_OK); | 2031 ValidateAssignmentPattern(classifier, CHECK_OK); |
2042 is_destructuring_assignment = true; | 2032 is_destructuring_assignment = true; |
2043 } else if (allow_harmony_default_parameters() && | 2033 } else if (allow_harmony_default_parameters() && |
2044 !allow_harmony_destructuring_assignment()) { | 2034 !allow_harmony_destructuring_assignment()) { |
2045 // TODO(adamk): This branch should be removed once the destructuring | 2035 // TODO(adamk): This branch should be removed once the destructuring |
2046 // assignment and default parameter flags are removed. | 2036 // assignment and default parameter flags are removed. |
2047 expression = this->ClassifyAndRewriteReferenceExpression( | 2037 expression = this->ClassifyAndRewriteReferenceExpression( |
2048 classifier, expression, lhs_beg_pos, scanner()->location().end_pos, | 2038 classifier, expression, lhs_beg_pos, scanner()->location().end_pos, |
2049 MessageTemplate::kInvalidLhsInAssignment); | 2039 MessageTemplate::kInvalidLhsInAssignment); |
2050 } else { | 2040 } else { |
2051 if (maybe_pattern_element) { | |
2052 CheckDestructuringElement(expression, classifier, lhs_beg_pos, | |
2053 scanner()->location().end_pos); | |
2054 } | |
2055 expression = this->CheckAndRewriteReferenceExpression( | 2041 expression = this->CheckAndRewriteReferenceExpression( |
2056 expression, lhs_beg_pos, scanner()->location().end_pos, | 2042 expression, lhs_beg_pos, scanner()->location().end_pos, |
2057 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); | 2043 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); |
2058 } | 2044 } |
2059 | 2045 |
2060 expression = this->MarkExpressionAsAssigned(expression); | 2046 expression = this->MarkExpressionAsAssigned(expression); |
2061 | 2047 |
2062 Token::Value op = Next(); // Get assignment operator. | 2048 Token::Value op = Next(); // Get assignment operator. |
2063 if (op != Token::ASSIGN) { | 2049 if (op != Token::ASSIGN) { |
2064 classifier->RecordPatternError(scanner()->location(), | 2050 classifier->RecordPatternError(scanner()->location(), |
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3289 template <typename Traits> | 3275 template <typename Traits> |
3290 bool ParserBase<Traits>::IsValidReferenceExpression(ExpressionT expression) { | 3276 bool ParserBase<Traits>::IsValidReferenceExpression(ExpressionT expression) { |
3291 return this->IsAssignableIdentifier(expression) || expression->IsProperty(); | 3277 return this->IsAssignableIdentifier(expression) || expression->IsProperty(); |
3292 } | 3278 } |
3293 | 3279 |
3294 | 3280 |
3295 template <typename Traits> | 3281 template <typename Traits> |
3296 void ParserBase<Traits>::CheckDestructuringElement( | 3282 void ParserBase<Traits>::CheckDestructuringElement( |
3297 ExpressionT expression, ExpressionClassifier* classifier, int begin, | 3283 ExpressionT expression, ExpressionClassifier* classifier, int begin, |
3298 int end) { | 3284 int end) { |
3299 static const MessageTemplate::Template message = | 3285 if (!IsValidPattern(expression) && !IsAssignmentExpression(expression) && |
3300 MessageTemplate::kInvalidDestructuringTarget; | 3286 !IsValidReferenceExpression(expression)) { |
3301 const Scanner::Location location(begin, end); | 3287 classifier->RecordAssignmentPatternError( |
3302 if (expression->IsArrayLiteral() || expression->IsObjectLiteral() || | 3288 Scanner::Location(begin, end), |
3303 expression->IsAssignment()) { | 3289 MessageTemplate::kInvalidDestructuringTarget); |
3304 return; | |
3305 } | |
3306 | |
3307 if (expression->IsProperty()) { | |
3308 classifier->RecordBindingPatternError(location, message); | |
3309 } else if (!this->IsAssignableIdentifier(expression)) { | |
3310 classifier->RecordPatternError(location, message); | |
3311 } | 3290 } |
3312 } | 3291 } |
3313 | 3292 |
3314 | 3293 |
3315 #undef CHECK_OK | 3294 #undef CHECK_OK |
3316 #undef CHECK_OK_CUSTOM | 3295 #undef CHECK_OK_CUSTOM |
3317 | 3296 |
3318 | 3297 |
3319 template <typename Traits> | 3298 template <typename Traits> |
3320 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 3299 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3366 return; | 3345 return; |
3367 } | 3346 } |
3368 has_seen_constructor_ = true; | 3347 has_seen_constructor_ = true; |
3369 return; | 3348 return; |
3370 } | 3349 } |
3371 } | 3350 } |
3372 } // namespace internal | 3351 } // namespace internal |
3373 } // namespace v8 | 3352 } // namespace v8 |
3374 | 3353 |
3375 #endif // V8_PARSING_PARSER_BASE_H | 3354 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |