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_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
11 #include "src/func-name-inferrer.h" | 11 #include "src/func-name-inferrer.h" |
12 #include "src/hashmap.h" | 12 #include "src/hashmap.h" |
13 #include "src/scanner.h" | 13 #include "src/scanner.h" |
14 #include "src/scopes.h" | 14 #include "src/scopes.h" |
15 #include "src/token.h" | 15 #include "src/token.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 | 19 |
20 | 20 |
21 // When parsing the formal parameters of a function, we usually don't yet know | |
22 // if the function will be strict, so we cannot yet produce errors for | |
23 // parameter names or duplicates. Instead, we remember the locations of these | |
24 // errors if they occur and produce the errors later. | |
25 class FormalParameterErrorLocations BASE_EMBEDDED { | |
26 public: | |
27 FormalParameterErrorLocations() | |
28 : eval_or_arguments(Scanner::Location::invalid()), | |
29 undefined(Scanner::Location::invalid()), | |
30 duplicate(Scanner::Location::invalid()), | |
31 reserved(Scanner::Location::invalid()) {} | |
32 | |
33 Scanner::Location eval_or_arguments; | |
34 Scanner::Location undefined; | |
35 Scanner::Location duplicate; | |
36 Scanner::Location reserved; | |
37 }; | |
38 | |
39 | |
40 // Common base class shared between parser and pre-parser. Traits encapsulate | 21 // Common base class shared between parser and pre-parser. Traits encapsulate |
41 // the differences between Parser and PreParser: | 22 // the differences between Parser and PreParser: |
42 | 23 |
43 // - Return types: For example, Parser functions return Expression* and | 24 // - Return types: For example, Parser functions return Expression* and |
44 // PreParser functions return PreParserExpression. | 25 // PreParser functions return PreParserExpression. |
45 | 26 |
46 // - Creating parse tree nodes: Parser generates an AST during the recursive | 27 // - Creating parse tree nodes: Parser generates an AST during the recursive |
47 // descent. PreParser doesn't create a tree. Instead, it passes around minimal | 28 // descent. PreParser doesn't create a tree. Instead, it passes around minimal |
48 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain | 29 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain |
49 // just enough data for the upper layer functions. PreParserFactory is | 30 // just enough data for the upper layer functions. PreParserFactory is |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 *ok = false; | 501 *ok = false; |
521 return; | 502 return; |
522 } | 503 } |
523 if (is_strong(language_mode) && this->IsUndefined(function_name)) { | 504 if (is_strong(language_mode) && this->IsUndefined(function_name)) { |
524 Traits::ReportMessageAt(function_name_loc, "strong_undefined"); | 505 Traits::ReportMessageAt(function_name_loc, "strong_undefined"); |
525 *ok = false; | 506 *ok = false; |
526 return; | 507 return; |
527 } | 508 } |
528 } | 509 } |
529 | 510 |
530 // Checking the parameter names of a function literal. This has to be done | |
531 // after parsing the function, since the function can declare itself strict. | |
532 void CheckFunctionParameterNames(LanguageMode language_mode, | |
533 bool strict_params, | |
534 const FormalParameterErrorLocations& locs, | |
535 bool* ok) { | |
536 if (is_sloppy(language_mode) && !strict_params) return; | |
537 if (is_strict(language_mode) && locs.eval_or_arguments.IsValid()) { | |
538 Traits::ReportMessageAt(locs.eval_or_arguments, "strict_eval_arguments"); | |
539 *ok = false; | |
540 return; | |
541 } | |
542 if (is_strict(language_mode) && locs.reserved.IsValid()) { | |
543 Traits::ReportMessageAt(locs.reserved, "unexpected_strict_reserved"); | |
544 *ok = false; | |
545 return; | |
546 } | |
547 if (is_strong(language_mode) && locs.undefined.IsValid()) { | |
548 Traits::ReportMessageAt(locs.undefined, "strong_undefined"); | |
549 *ok = false; | |
550 return; | |
551 } | |
552 // TODO(arv): When we add support for destructuring in setters we also need | |
553 // to check for duplicate names. | |
554 if (locs.duplicate.IsValid()) { | |
555 Traits::ReportMessageAt(locs.duplicate, "strict_param_dupe"); | |
556 *ok = false; | |
557 return; | |
558 } | |
559 } | |
560 | |
561 // Determine precedence of given token. | 511 // Determine precedence of given token. |
562 static int Precedence(Token::Value token, bool accept_IN) { | 512 static int Precedence(Token::Value token, bool accept_IN) { |
563 if (token == Token::IN && !accept_IN) | 513 if (token == Token::IN && !accept_IN) |
564 return 0; // 0 precedence will terminate binary expression parsing | 514 return 0; // 0 precedence will terminate binary expression parsing |
565 return Token::Precedence(token); | 515 return Token::Precedence(token); |
566 } | 516 } |
567 | 517 |
568 typename Traits::Type::Factory* factory() { | 518 typename Traits::Type::Factory* factory() { |
569 return function_state_->factory(); | 519 return function_state_->factory(); |
570 } | 520 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 bool is_valid_expression() const { return !expression_error_.HasError(); } | 558 bool is_valid_expression() const { return !expression_error_.HasError(); } |
609 | 559 |
610 bool is_valid_binding_pattern() const { | 560 bool is_valid_binding_pattern() const { |
611 return !binding_pattern_error_.HasError(); | 561 return !binding_pattern_error_.HasError(); |
612 } | 562 } |
613 | 563 |
614 bool is_valid_assignment_pattern() const { | 564 bool is_valid_assignment_pattern() const { |
615 return !assignment_pattern_error_.HasError(); | 565 return !assignment_pattern_error_.HasError(); |
616 } | 566 } |
617 | 567 |
| 568 bool is_valid_arrow_formal_parameters() const { |
| 569 return !arrow_formal_parameters_error_.HasError(); |
| 570 } |
| 571 |
| 572 bool is_valid_formal_parameter_list_without_duplicates() const { |
| 573 return !duplicate_formal_parameter_error_.HasError(); |
| 574 } |
| 575 |
| 576 // Note: callers should also check |
| 577 // is_valid_formal_parameter_list_without_duplicates(). |
| 578 bool is_valid_strict_mode_formal_parameters() const { |
| 579 return !strict_mode_formal_parameter_error_.HasError(); |
| 580 } |
| 581 |
| 582 // Note: callers should also check is_valid_strict_mode_formal_parameters() |
| 583 // and is_valid_formal_parameter_list_without_duplicates(). |
| 584 bool is_valid_strong_mode_formal_parameters() const { |
| 585 return !strong_mode_formal_parameter_error_.HasError(); |
| 586 } |
| 587 |
618 const Error& expression_error() const { return expression_error_; } | 588 const Error& expression_error() const { return expression_error_; } |
619 | 589 |
620 const Error& binding_pattern_error() const { | 590 const Error& binding_pattern_error() const { |
621 return binding_pattern_error_; | 591 return binding_pattern_error_; |
622 } | 592 } |
623 | 593 |
624 const Error& assignment_pattern_error() const { | 594 const Error& assignment_pattern_error() const { |
625 return assignment_pattern_error_; | 595 return assignment_pattern_error_; |
626 } | 596 } |
627 | 597 |
| 598 const Error& arrow_formal_parameters_error() const { |
| 599 return arrow_formal_parameters_error_; |
| 600 } |
| 601 |
| 602 const Error& duplicate_formal_parameter_error() const { |
| 603 return duplicate_formal_parameter_error_; |
| 604 } |
| 605 |
| 606 const Error& strict_mode_formal_parameter_error() const { |
| 607 return strict_mode_formal_parameter_error_; |
| 608 } |
| 609 |
| 610 const Error& strong_mode_formal_parameter_error() const { |
| 611 return strong_mode_formal_parameter_error_; |
| 612 } |
| 613 |
628 void RecordExpressionError(const Scanner::Location& loc, | 614 void RecordExpressionError(const Scanner::Location& loc, |
629 const char* message, const char* arg = nullptr) { | 615 const char* message, const char* arg = nullptr) { |
630 if (!is_valid_expression()) return; | 616 if (!is_valid_expression()) return; |
631 expression_error_.location = loc; | 617 expression_error_.location = loc; |
632 expression_error_.message = message; | 618 expression_error_.message = message; |
633 expression_error_.arg = arg; | 619 expression_error_.arg = arg; |
634 } | 620 } |
635 | 621 |
636 void RecordBindingPatternError(const Scanner::Location& loc, | 622 void RecordBindingPatternError(const Scanner::Location& loc, |
637 const char* message, | 623 const char* message, |
638 const char* arg = nullptr) { | 624 const char* arg = nullptr) { |
639 if (!is_valid_binding_pattern()) return; | 625 if (!is_valid_binding_pattern()) return; |
640 binding_pattern_error_.location = loc; | 626 binding_pattern_error_.location = loc; |
641 binding_pattern_error_.message = message; | 627 binding_pattern_error_.message = message; |
642 binding_pattern_error_.arg = arg; | 628 binding_pattern_error_.arg = arg; |
643 } | 629 } |
644 | 630 |
645 void RecordAssignmentPatternError(const Scanner::Location& loc, | 631 void RecordAssignmentPatternError(const Scanner::Location& loc, |
646 const char* message, | 632 const char* message, |
647 const char* arg = nullptr) { | 633 const char* arg = nullptr) { |
648 if (!is_valid_assignment_pattern()) return; | 634 if (!is_valid_assignment_pattern()) return; |
649 assignment_pattern_error_.location = loc; | 635 assignment_pattern_error_.location = loc; |
650 assignment_pattern_error_.message = message; | 636 assignment_pattern_error_.message = message; |
651 assignment_pattern_error_.arg = arg; | 637 assignment_pattern_error_.arg = arg; |
652 } | 638 } |
653 | 639 |
| 640 void RecordArrowFormalParametersError(const Scanner::Location& loc, |
| 641 const char* message, |
| 642 const char* arg = nullptr) { |
| 643 if (!is_valid_arrow_formal_parameters()) return; |
| 644 arrow_formal_parameters_error_.location = loc; |
| 645 arrow_formal_parameters_error_.message = message; |
| 646 arrow_formal_parameters_error_.arg = arg; |
| 647 } |
| 648 |
| 649 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { |
| 650 if (!is_valid_formal_parameter_list_without_duplicates()) return; |
| 651 duplicate_formal_parameter_error_.location = loc; |
| 652 duplicate_formal_parameter_error_.message = "strict_param_dupe"; |
| 653 duplicate_formal_parameter_error_.arg = nullptr; |
| 654 } |
| 655 |
| 656 // Record a binding that would be invalid in strict mode. Confusingly this |
| 657 // is not the same as StrictFormalParameterList, which simply forbids |
| 658 // duplicate bindings. |
| 659 void RecordStrictModeFormalParameterError(const Scanner::Location& loc, |
| 660 const char* message, |
| 661 const char* arg = nullptr) { |
| 662 if (!is_valid_strict_mode_formal_parameters()) return; |
| 663 strict_mode_formal_parameter_error_.location = loc; |
| 664 strict_mode_formal_parameter_error_.message = message; |
| 665 strict_mode_formal_parameter_error_.arg = arg; |
| 666 } |
| 667 |
| 668 void RecordStrongModeFormalParameterError(const Scanner::Location& loc, |
| 669 const char* message, |
| 670 const char* arg = nullptr) { |
| 671 if (!is_valid_strong_mode_formal_parameters()) return; |
| 672 strong_mode_formal_parameter_error_.location = loc; |
| 673 strong_mode_formal_parameter_error_.message = message; |
| 674 strong_mode_formal_parameter_error_.arg = arg; |
| 675 } |
| 676 |
| 677 enum TargetProduction { |
| 678 ExpressionProduction = 1 << 0, |
| 679 BindingPatternProduction = 1 << 1, |
| 680 AssignmentPatternProduction = 1 << 2, |
| 681 FormalParametersProduction = 1 << 3, |
| 682 ArrowFormalParametersProduction = 1 << 4, |
| 683 StandardProductions = (ExpressionProduction | BindingPatternProduction | |
| 684 AssignmentPatternProduction), |
| 685 AllProductions = (StandardProductions | FormalParametersProduction | |
| 686 ArrowFormalParametersProduction) |
| 687 }; |
| 688 |
| 689 void Accumulate(const ExpressionClassifier& inner, |
| 690 unsigned productions = StandardProductions) { |
| 691 if (productions & ExpressionProduction && is_valid_expression()) { |
| 692 expression_error_ = inner.expression_error_; |
| 693 } |
| 694 if (productions & BindingPatternProduction && |
| 695 is_valid_binding_pattern()) { |
| 696 binding_pattern_error_ = inner.binding_pattern_error_; |
| 697 } |
| 698 if (productions & AssignmentPatternProduction && |
| 699 is_valid_assignment_pattern()) { |
| 700 assignment_pattern_error_ = inner.assignment_pattern_error_; |
| 701 } |
| 702 if (productions & FormalParametersProduction) { |
| 703 if (is_valid_formal_parameter_list_without_duplicates()) { |
| 704 duplicate_formal_parameter_error_ = |
| 705 inner.duplicate_formal_parameter_error_; |
| 706 } |
| 707 if (is_valid_strict_mode_formal_parameters()) { |
| 708 strict_mode_formal_parameter_error_ = |
| 709 inner.strict_mode_formal_parameter_error_; |
| 710 } |
| 711 if (is_valid_strong_mode_formal_parameters()) { |
| 712 strong_mode_formal_parameter_error_ = |
| 713 inner.strong_mode_formal_parameter_error_; |
| 714 } |
| 715 } |
| 716 if (productions & ArrowFormalParametersProduction && |
| 717 is_valid_arrow_formal_parameters()) { |
| 718 // The result continues to be a valid arrow formal parameters if the |
| 719 // inner expression is a valid binding pattern. |
| 720 arrow_formal_parameters_error_ = inner.binding_pattern_error_; |
| 721 } |
| 722 } |
| 723 |
654 private: | 724 private: |
655 Error expression_error_; | 725 Error expression_error_; |
656 Error binding_pattern_error_; | 726 Error binding_pattern_error_; |
657 Error assignment_pattern_error_; | 727 Error assignment_pattern_error_; |
| 728 Error arrow_formal_parameters_error_; |
| 729 Error duplicate_formal_parameter_error_; |
| 730 Error strict_mode_formal_parameter_error_; |
| 731 Error strong_mode_formal_parameter_error_; |
658 }; | 732 }; |
659 | 733 |
660 void ReportClassifierError( | 734 void ReportClassifierError( |
661 const typename ExpressionClassifier::Error& error) { | 735 const typename ExpressionClassifier::Error& error) { |
662 Traits::ReportMessageAt(error.location, error.message, error.arg, | 736 Traits::ReportMessageAt(error.location, error.message, error.arg, |
663 kSyntaxError); | 737 kSyntaxError); |
664 } | 738 } |
665 | 739 |
666 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) { | 740 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) { |
667 if (!classifier->is_valid_expression()) { | 741 if (!classifier->is_valid_expression()) { |
(...skipping 11 matching lines...) Expand all Loading... |
679 } | 753 } |
680 | 754 |
681 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, | 755 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, |
682 bool* ok) { | 756 bool* ok) { |
683 if (!classifier->is_valid_assignment_pattern()) { | 757 if (!classifier->is_valid_assignment_pattern()) { |
684 ReportClassifierError(classifier->assignment_pattern_error()); | 758 ReportClassifierError(classifier->assignment_pattern_error()); |
685 *ok = false; | 759 *ok = false; |
686 } | 760 } |
687 } | 761 } |
688 | 762 |
| 763 void ValidateFormalParameters(const ExpressionClassifier* classifier, |
| 764 LanguageMode language_mode, |
| 765 bool allow_duplicates, bool* ok) { |
| 766 if (!allow_duplicates && |
| 767 !classifier->is_valid_formal_parameter_list_without_duplicates()) { |
| 768 ReportClassifierError(classifier->duplicate_formal_parameter_error()); |
| 769 *ok = false; |
| 770 } else if (is_strict(language_mode) && |
| 771 !classifier->is_valid_strict_mode_formal_parameters()) { |
| 772 ReportClassifierError(classifier->strict_mode_formal_parameter_error()); |
| 773 *ok = false; |
| 774 } else if (is_strong(language_mode) && |
| 775 !classifier->is_valid_strong_mode_formal_parameters()) { |
| 776 ReportClassifierError(classifier->strong_mode_formal_parameter_error()); |
| 777 *ok = false; |
| 778 } |
| 779 } |
| 780 |
| 781 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, |
| 782 ExpressionT expr, bool* ok) { |
| 783 if (classifier->is_valid_binding_pattern()) { |
| 784 // A simple arrow formal parameter: IDENTIFIER => BODY. |
| 785 if (!this->IsIdentifier(expr)) { |
| 786 Traits::ReportMessageAt(scanner()->location(), "unexpected_token", |
| 787 Token::String(scanner()->current_token())); |
| 788 *ok = false; |
| 789 } |
| 790 } else if (!classifier->is_valid_arrow_formal_parameters()) { |
| 791 ReportClassifierError(classifier->arrow_formal_parameters_error()); |
| 792 *ok = false; |
| 793 } |
| 794 } |
| 795 |
689 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) { | 796 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) { |
690 classifier->RecordBindingPatternError( | 797 classifier->RecordBindingPatternError( |
691 scanner()->location(), "unexpected_token", Token::String(peek())); | 798 scanner()->peek_location(), "unexpected_token", Token::String(peek())); |
| 799 } |
| 800 |
| 801 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) { |
| 802 classifier->RecordArrowFormalParametersError( |
| 803 scanner()->peek_location(), "unexpected_token", Token::String(peek())); |
692 } | 804 } |
693 | 805 |
694 // Recursive descent functions: | 806 // Recursive descent functions: |
695 | 807 |
696 // Parses an identifier that is valid for the current scope, in particular it | 808 // Parses an identifier that is valid for the current scope, in particular it |
697 // fails on strict mode future reserved keywords in a strict scope. If | 809 // fails on strict mode future reserved keywords in a strict scope. If |
698 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or | 810 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or |
699 // "arguments" as identifier even in strict mode (this is needed in cases like | 811 // "arguments" as identifier even in strict mode (this is needed in cases like |
700 // "var foo = eval;"). | 812 // "var foo = eval;"). |
701 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); | 813 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 855 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
744 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 856 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
745 bool* ok); | 857 bool* ok); |
746 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, | 858 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
747 bool* ok); | 859 bool* ok); |
748 ExpressionT ParseMemberWithNewPrefixesExpression( | 860 ExpressionT ParseMemberWithNewPrefixesExpression( |
749 ExpressionClassifier* classifier, bool* ok); | 861 ExpressionClassifier* classifier, bool* ok); |
750 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); | 862 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); |
751 ExpressionT ParseMemberExpressionContinuation( | 863 ExpressionT ParseMemberExpressionContinuation( |
752 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); | 864 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); |
753 ExpressionT ParseArrowFunctionLiteral( | 865 ExpressionT ParseArrowFunctionLiteral(Scope* function_scope, bool has_rest, |
754 Scope* function_scope, const FormalParameterErrorLocations& error_locs, | 866 const ExpressionClassifier& classifier, |
755 bool has_rest, ExpressionClassifier* classifier, bool* ok); | 867 bool* ok); |
756 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, | 868 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, |
757 ExpressionClassifier* classifier, bool* ok); | 869 ExpressionClassifier* classifier, bool* ok); |
758 void AddTemplateExpression(ExpressionT); | 870 void AddTemplateExpression(ExpressionT); |
759 ExpressionT ParseSuperExpression(bool is_new, | 871 ExpressionT ParseSuperExpression(bool is_new, |
760 ExpressionClassifier* classifier, bool* ok); | 872 ExpressionClassifier* classifier, bool* ok); |
761 ExpressionT ParseStrongInitializationExpression( | 873 ExpressionT ParseStrongInitializationExpression( |
762 ExpressionClassifier* classifier, bool* ok); | 874 ExpressionClassifier* classifier, bool* ok); |
763 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, | 875 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, |
764 bool* ok); | 876 bool* ok); |
765 | 877 |
766 void ParseFormalParameter(FormalParameterScopeT* scope, | 878 void ParseFormalParameter(FormalParameterScopeT* scope, bool is_rest, |
767 FormalParameterErrorLocations* locs, bool is_rest, | 879 ExpressionClassifier* classifier, bool* ok); |
768 bool* ok); | 880 int ParseFormalParameterList(FormalParameterScopeT* scope, bool* has_rest, |
769 int ParseFormalParameterList(FormalParameterScopeT* scope, | 881 ExpressionClassifier* classifier, bool* ok); |
770 FormalParameterErrorLocations* locs, | |
771 bool* has_rest, bool* ok); | |
772 void CheckArityRestrictions( | 882 void CheckArityRestrictions( |
773 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 883 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
774 int formals_start_pos, int formals_end_pos, bool* ok); | 884 int formals_start_pos, int formals_end_pos, bool* ok); |
775 | 885 |
776 // Checks if the expression is a valid reference expression (e.g., on the | 886 // Checks if the expression is a valid reference expression (e.g., on the |
777 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 887 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
778 // we allow calls for web compatibility and rewrite them to a runtime throw. | 888 // we allow calls for web compatibility and rewrite them to a runtime throw. |
779 ExpressionT CheckAndRewriteReferenceExpression( | 889 ExpressionT CheckAndRewriteReferenceExpression( |
780 ExpressionT expression, | 890 ExpressionT expression, |
781 Scanner::Location location, const char* message, bool* ok); | 891 Scanner::Location location, const char* message, bool* ok); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 } | 1076 } |
967 | 1077 |
968 static PreParserExpression FromIdentifier(PreParserIdentifier id) { | 1078 static PreParserExpression FromIdentifier(PreParserIdentifier id) { |
969 return PreParserExpression(TypeField::encode(kIdentifierExpression) | | 1079 return PreParserExpression(TypeField::encode(kIdentifierExpression) | |
970 IdentifierTypeField::encode(id.type_)); | 1080 IdentifierTypeField::encode(id.type_)); |
971 } | 1081 } |
972 | 1082 |
973 static PreParserExpression BinaryOperation(PreParserExpression left, | 1083 static PreParserExpression BinaryOperation(PreParserExpression left, |
974 Token::Value op, | 1084 Token::Value op, |
975 PreParserExpression right) { | 1085 PreParserExpression right) { |
976 ValidArrowParam valid_arrow_param_list = | 1086 return PreParserExpression(TypeField::encode(kBinaryOperationExpression)); |
977 (op == Token::COMMA && !left.is_single_parenthesized() && | |
978 !right.is_single_parenthesized()) | |
979 ? std::min(left.ValidateArrowParams(), right.ValidateArrowParams()) | |
980 : kInvalidArrowParam; | |
981 return PreParserExpression( | |
982 TypeField::encode(kBinaryOperationExpression) | | |
983 IsValidArrowParamListField::encode(valid_arrow_param_list)); | |
984 } | 1087 } |
985 | 1088 |
986 static PreParserExpression StringLiteral() { | 1089 static PreParserExpression StringLiteral() { |
987 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); | 1090 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); |
988 } | 1091 } |
989 | 1092 |
990 static PreParserExpression UseStrictStringLiteral() { | 1093 static PreParserExpression UseStrictStringLiteral() { |
991 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 1094 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
992 IsUseStrictField::encode(true)); | 1095 IsUseStrictField::encode(true)); |
993 } | 1096 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 | 1169 |
1067 bool IsCall() const { | 1170 bool IsCall() const { |
1068 return TypeField::decode(code_) == kExpression && | 1171 return TypeField::decode(code_) == kExpression && |
1069 ExpressionTypeField::decode(code_) == kCallExpression; | 1172 ExpressionTypeField::decode(code_) == kCallExpression; |
1070 } | 1173 } |
1071 | 1174 |
1072 bool IsValidReferenceExpression() const { | 1175 bool IsValidReferenceExpression() const { |
1073 return IsIdentifier() || IsProperty(); | 1176 return IsIdentifier() || IsProperty(); |
1074 } | 1177 } |
1075 | 1178 |
1076 bool IsValidArrowParamList(FormalParameterErrorLocations* locs, | |
1077 const Scanner::Location& params_loc) const { | |
1078 ValidArrowParam valid = ValidateArrowParams(); | |
1079 if (ParenthesizationField::decode(code_) == kMultiParenthesizedExpression) { | |
1080 return false; | |
1081 } | |
1082 switch (valid) { | |
1083 case kInvalidArrowParam: | |
1084 return false; | |
1085 case kInvalidStrongArrowParam: | |
1086 locs->undefined = params_loc; | |
1087 return true; | |
1088 case kInvalidStrictReservedArrowParam: | |
1089 locs->reserved = params_loc; | |
1090 return true; | |
1091 case kInvalidStrictEvalArgumentsArrowParam: | |
1092 locs->eval_or_arguments = params_loc; | |
1093 return true; | |
1094 default: | |
1095 DCHECK_EQ(valid, kValidArrowParam); | |
1096 return true; | |
1097 } | |
1098 } | |
1099 | |
1100 // At the moment PreParser doesn't track these expression types. | 1179 // At the moment PreParser doesn't track these expression types. |
1101 bool IsFunctionLiteral() const { return false; } | 1180 bool IsFunctionLiteral() const { return false; } |
1102 bool IsCallNew() const { return false; } | 1181 bool IsCallNew() const { return false; } |
1103 | 1182 |
1104 bool IsNoTemplateTag() const { | 1183 bool IsNoTemplateTag() const { |
1105 return TypeField::decode(code_) == kExpression && | 1184 return TypeField::decode(code_) == kExpression && |
1106 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; | 1185 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; |
1107 } | 1186 } |
1108 | 1187 |
1109 bool IsSpreadExpression() const { | 1188 bool IsSpreadExpression() const { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 }; | 1232 }; |
1154 | 1233 |
1155 enum ExpressionType { | 1234 enum ExpressionType { |
1156 kThisExpression, | 1235 kThisExpression, |
1157 kThisPropertyExpression, | 1236 kThisPropertyExpression, |
1158 kPropertyExpression, | 1237 kPropertyExpression, |
1159 kCallExpression, | 1238 kCallExpression, |
1160 kNoTemplateTagExpression | 1239 kNoTemplateTagExpression |
1161 }; | 1240 }; |
1162 | 1241 |
1163 // These validity constraints are ordered such that a value of N implies lack | |
1164 // of errors M < N. | |
1165 enum ValidArrowParam { | |
1166 kInvalidArrowParam, | |
1167 kInvalidStrictEvalArgumentsArrowParam, | |
1168 kInvalidStrictReservedArrowParam, | |
1169 kInvalidStrongArrowParam, | |
1170 kValidArrowParam | |
1171 }; | |
1172 | |
1173 explicit PreParserExpression(uint32_t expression_code) | 1242 explicit PreParserExpression(uint32_t expression_code) |
1174 : code_(expression_code) {} | 1243 : code_(expression_code) {} |
1175 | 1244 |
1176 V8_INLINE ValidArrowParam ValidateArrowParams() const { | |
1177 if (IsBinaryOperation()) { | |
1178 return IsValidArrowParamListField::decode(code_); | |
1179 } | |
1180 if (!IsIdentifier()) { | |
1181 return kInvalidArrowParam; | |
1182 } | |
1183 PreParserIdentifier ident = AsIdentifier(); | |
1184 // In strict mode, eval and arguments are not valid formal parameter names. | |
1185 if (ident.IsEval() || ident.IsArguments()) { | |
1186 return kInvalidStrictEvalArgumentsArrowParam; | |
1187 } | |
1188 // In strict mode, future reserved words are not valid either, and as they | |
1189 // produce different errors we allot them their own error code. | |
1190 if (ident.IsFutureStrictReserved()) { | |
1191 return kInvalidStrictReservedArrowParam; | |
1192 } | |
1193 // In strong mode, 'undefined' isn't a valid formal parameter name either. | |
1194 if (ident.IsUndefined()) { | |
1195 return kInvalidStrongArrowParam; | |
1196 } | |
1197 return kValidArrowParam; | |
1198 } | |
1199 | |
1200 // The first five bits are for the Type and Parenthesization. | 1245 // The first five bits are for the Type and Parenthesization. |
1201 typedef BitField<Type, 0, 3> TypeField; | 1246 typedef BitField<Type, 0, 3> TypeField; |
1202 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; | 1247 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; |
1203 | 1248 |
1204 // The rest of the bits are interpreted depending on the value | 1249 // The rest of the bits are interpreted depending on the value |
1205 // of the Type field, so they can share the storage. | 1250 // of the Type field, so they can share the storage. |
1206 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> | 1251 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> |
1207 ExpressionTypeField; | 1252 ExpressionTypeField; |
1208 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; | 1253 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; |
1209 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; | 1254 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; |
1210 typedef BitField<ValidArrowParam, ParenthesizationField::kNext, 3> | |
1211 IsValidArrowParamListField; | |
1212 typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10> | 1255 typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10> |
1213 IdentifierTypeField; | 1256 IdentifierTypeField; |
1214 | 1257 |
1215 uint32_t code_; | 1258 uint32_t code_; |
1216 }; | 1259 }; |
1217 | 1260 |
1218 | 1261 |
1219 // The pre-parser doesn't need to build lists of expressions, identifiers, or | 1262 // The pre-parser doesn't need to build lists of expressions, identifiers, or |
1220 // the like. | 1263 // the like. |
1221 template <typename T> | 1264 template <typename T> |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 UNREACHABLE(); | 1732 UNREACHABLE(); |
1690 } | 1733 } |
1691 | 1734 |
1692 V8_INLINE PreParserStatementList | 1735 V8_INLINE PreParserStatementList |
1693 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, | 1736 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, |
1694 Variable* fvar, Token::Value fvar_init_op, | 1737 Variable* fvar, Token::Value fvar_init_op, |
1695 FunctionKind kind, bool* ok); | 1738 FunctionKind kind, bool* ok); |
1696 | 1739 |
1697 V8_INLINE void ParseArrowFunctionFormalParameters( | 1740 V8_INLINE void ParseArrowFunctionFormalParameters( |
1698 Scope* scope, PreParserExpression expression, | 1741 Scope* scope, PreParserExpression expression, |
1699 const Scanner::Location& params_loc, | 1742 const Scanner::Location& params_loc, bool* is_rest, |
1700 FormalParameterErrorLocations* error_locs, bool* is_rest, bool* ok); | 1743 Scanner::Location* duplicate_loc, bool* ok); |
1701 | 1744 |
1702 struct TemplateLiteralState {}; | 1745 struct TemplateLiteralState {}; |
1703 | 1746 |
1704 TemplateLiteralState OpenTemplateLiteral(int pos) { | 1747 TemplateLiteralState OpenTemplateLiteral(int pos) { |
1705 return TemplateLiteralState(); | 1748 return TemplateLiteralState(); |
1706 } | 1749 } |
1707 void AddTemplateSpan(TemplateLiteralState*, bool) {} | 1750 void AddTemplateSpan(TemplateLiteralState*, bool) {} |
1708 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} | 1751 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} |
1709 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, | 1752 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, |
1710 PreParserExpression tag) { | 1753 PreParserExpression tag) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1921 | 1964 |
1922 bool PreParserTraits::DeclareFormalParameter( | 1965 bool PreParserTraits::DeclareFormalParameter( |
1923 DuplicateFinder* duplicate_finder, PreParserIdentifier current_identifier, | 1966 DuplicateFinder* duplicate_finder, PreParserIdentifier current_identifier, |
1924 bool is_rest) { | 1967 bool is_rest) { |
1925 return pre_parser_->scanner()->FindSymbol(duplicate_finder, 1) != 0; | 1968 return pre_parser_->scanner()->FindSymbol(duplicate_finder, 1) != 0; |
1926 } | 1969 } |
1927 | 1970 |
1928 | 1971 |
1929 void PreParserTraits::ParseArrowFunctionFormalParameters( | 1972 void PreParserTraits::ParseArrowFunctionFormalParameters( |
1930 Scope* scope, PreParserExpression params, | 1973 Scope* scope, PreParserExpression params, |
1931 const Scanner::Location& params_loc, | 1974 const Scanner::Location& params_loc, bool* is_rest, |
1932 FormalParameterErrorLocations* error_locs, bool* is_rest, bool* ok) { | 1975 Scanner::Location* duplicate_loc, bool* ok) { |
1933 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1976 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
1934 // lists that are too long. | 1977 // lists that are too long. |
1935 if (!params.IsValidArrowParamList(error_locs, params_loc)) { | |
1936 *ok = false; | |
1937 ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list"); | |
1938 return; | |
1939 } | |
1940 } | 1978 } |
1941 | 1979 |
1942 | 1980 |
1943 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1981 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1944 PreParserIdentifier function_name, int pos, Variable* fvar, | 1982 PreParserIdentifier function_name, int pos, Variable* fvar, |
1945 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 1983 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
1946 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1984 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
1947 | 1985 |
1948 ParseStatementList(Token::RBRACE, ok); | 1986 ParseStatementList(Token::RBRACE, ok); |
1949 if (!*ok) return PreParserStatementList(); | 1987 if (!*ok) return PreParserStatementList(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2054 } | 2092 } |
2055 | 2093 |
2056 | 2094 |
2057 template <class Traits> | 2095 template <class Traits> |
2058 typename ParserBase<Traits>::IdentifierT | 2096 typename ParserBase<Traits>::IdentifierT |
2059 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, | 2097 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, |
2060 bool* ok) { | 2098 bool* ok) { |
2061 Token::Value next = Next(); | 2099 Token::Value next = Next(); |
2062 if (next == Token::IDENTIFIER) { | 2100 if (next == Token::IDENTIFIER) { |
2063 IdentifierT name = this->GetSymbol(scanner()); | 2101 IdentifierT name = this->GetSymbol(scanner()); |
2064 if (is_strict(language_mode()) && this->IsEvalOrArguments(name)) { | 2102 // When this function is used to read a formal parameter, we don't always |
2065 classifier->RecordBindingPatternError(scanner()->location(), | 2103 // know whether the function is going to be strict or sloppy. Indeed for |
2066 "strict_eval_arguments"); | 2104 // arrow functions we don't always know that the identifier we are reading |
| 2105 // is actually a formal parameter. Therefore besides the errors that we |
| 2106 // must detect because we know we're in strict mode, we also record any |
| 2107 // error that we might make in the future once we know the language mode. |
| 2108 if (this->IsEval(name)) { |
| 2109 classifier->RecordStrictModeFormalParameterError(scanner()->location(), |
| 2110 "strict_eval_arguments"); |
| 2111 if (is_strict(language_mode())) { |
| 2112 classifier->RecordBindingPatternError(scanner()->location(), |
| 2113 "strict_eval_arguments"); |
| 2114 } |
2067 } | 2115 } |
2068 if (is_strong(language_mode()) && this->IsUndefined(name)) { | 2116 if (this->IsArguments(name)) { |
2069 // TODO(dslomov): allow 'undefined' in nested patterns. | 2117 scope_->RecordArgumentsUsage(); |
2070 classifier->RecordBindingPatternError(scanner()->location(), | 2118 classifier->RecordStrictModeFormalParameterError(scanner()->location(), |
2071 "strong_undefined"); | 2119 "strict_eval_arguments"); |
2072 classifier->RecordAssignmentPatternError(scanner()->location(), | 2120 if (is_strict(language_mode())) { |
2073 "strong_undefined"); | 2121 classifier->RecordBindingPatternError(scanner()->location(), |
| 2122 "strict_eval_arguments"); |
| 2123 } |
| 2124 if (is_strong(language_mode())) { |
| 2125 classifier->RecordExpressionError(scanner()->location(), |
| 2126 "strong_arguments"); |
| 2127 } |
2074 } | 2128 } |
2075 if (is_strong(language_mode()) && this->IsArguments(name)) { | 2129 if (this->IsUndefined(name)) { |
2076 classifier->RecordExpressionError(scanner()->location(), | 2130 classifier->RecordStrongModeFormalParameterError(scanner()->location(), |
2077 "strong_arguments"); | 2131 "strong_undefined"); |
| 2132 if (is_strong(language_mode())) { |
| 2133 // TODO(dslomov): allow 'undefined' in nested patterns. |
| 2134 classifier->RecordBindingPatternError(scanner()->location(), |
| 2135 "strong_undefined"); |
| 2136 classifier->RecordAssignmentPatternError(scanner()->location(), |
| 2137 "strong_undefined"); |
| 2138 } |
2078 } | 2139 } |
2079 if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); | |
2080 return name; | 2140 return name; |
2081 } else if (is_sloppy(language_mode()) && | 2141 } else if (is_sloppy(language_mode()) && |
2082 (next == Token::FUTURE_STRICT_RESERVED_WORD || | 2142 (next == Token::FUTURE_STRICT_RESERVED_WORD || |
2083 next == Token::LET || next == Token::STATIC || | 2143 next == Token::LET || next == Token::STATIC || |
2084 (next == Token::YIELD && !is_generator()))) { | 2144 (next == Token::YIELD && !is_generator()))) { |
| 2145 classifier->RecordStrictModeFormalParameterError( |
| 2146 scanner()->location(), "unexpected_strict_reserved"); |
2085 return this->GetSymbol(scanner()); | 2147 return this->GetSymbol(scanner()); |
2086 } else { | 2148 } else { |
2087 this->ReportUnexpectedToken(next); | 2149 this->ReportUnexpectedToken(next); |
2088 *ok = false; | 2150 *ok = false; |
2089 return Traits::EmptyIdentifier(); | 2151 return Traits::EmptyIdentifier(); |
2090 } | 2152 } |
2091 } | 2153 } |
2092 | 2154 |
2093 | 2155 |
2094 template <class Traits> | 2156 template <class Traits> |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2263 | 2325 |
2264 case Token::ASSIGN_DIV: | 2326 case Token::ASSIGN_DIV: |
2265 result = this->ParseRegExpLiteral(true, classifier, CHECK_OK); | 2327 result = this->ParseRegExpLiteral(true, classifier, CHECK_OK); |
2266 break; | 2328 break; |
2267 | 2329 |
2268 case Token::DIV: | 2330 case Token::DIV: |
2269 result = this->ParseRegExpLiteral(false, classifier, CHECK_OK); | 2331 result = this->ParseRegExpLiteral(false, classifier, CHECK_OK); |
2270 break; | 2332 break; |
2271 | 2333 |
2272 case Token::LBRACK: | 2334 case Token::LBRACK: |
| 2335 if (!allow_harmony_destructuring()) { |
| 2336 BindingPatternUnexpectedToken(classifier); |
| 2337 } |
2273 result = this->ParseArrayLiteral(classifier, CHECK_OK); | 2338 result = this->ParseArrayLiteral(classifier, CHECK_OK); |
2274 break; | 2339 break; |
2275 | 2340 |
2276 case Token::LBRACE: | 2341 case Token::LBRACE: |
| 2342 if (!allow_harmony_destructuring()) { |
| 2343 BindingPatternUnexpectedToken(classifier); |
| 2344 } |
2277 result = this->ParseObjectLiteral(classifier, CHECK_OK); | 2345 result = this->ParseObjectLiteral(classifier, CHECK_OK); |
2278 break; | 2346 break; |
2279 | 2347 |
2280 case Token::LPAREN: | 2348 case Token::LPAREN: |
| 2349 // Arrow function formal parameters are either a single identifier or a |
| 2350 // list of BindingPattern productions enclosed in parentheses. |
| 2351 // Parentheses are not valid on the LHS of a BindingPattern, so we use the |
| 2352 // is_valid_binding_pattern() check to detect multiple levels of |
| 2353 // parenthesization. |
| 2354 if (!classifier->is_valid_binding_pattern()) { |
| 2355 ArrowFormalParametersUnexpectedToken(classifier); |
| 2356 } |
2281 BindingPatternUnexpectedToken(classifier); | 2357 BindingPatternUnexpectedToken(classifier); |
2282 Consume(Token::LPAREN); | 2358 Consume(Token::LPAREN); |
2283 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { | 2359 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { |
2284 // As a primary expression, the only thing that can follow "()" is "=>". | 2360 // As a primary expression, the only thing that can follow "()" is "=>". |
| 2361 classifier->RecordBindingPatternError(scanner()->location(), |
| 2362 "unexpected_token", |
| 2363 Token::String(Token::RPAREN)); |
2285 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); | 2364 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); |
2286 scope->set_start_position(beg_pos); | 2365 scope->set_start_position(beg_pos); |
2287 FormalParameterErrorLocations error_locs; | 2366 ExpressionClassifier args_classifier; |
2288 bool has_rest = false; | 2367 bool has_rest = false; |
2289 result = this->ParseArrowFunctionLiteral(scope, error_locs, has_rest, | 2368 result = this->ParseArrowFunctionLiteral(scope, has_rest, |
2290 classifier, CHECK_OK); | 2369 args_classifier, CHECK_OK); |
2291 } else { | 2370 } else { |
2292 // Heuristically try to detect immediately called functions before | 2371 // Heuristically try to detect immediately called functions before |
2293 // seeing the call parentheses. | 2372 // seeing the call parentheses. |
2294 parenthesized_function_ = (peek() == Token::FUNCTION); | 2373 parenthesized_function_ = (peek() == Token::FUNCTION); |
2295 result = this->ParseExpression(true, classifier, CHECK_OK); | 2374 result = this->ParseExpression(true, classifier, CHECK_OK); |
2296 result->increase_parenthesization_level(); | 2375 result->increase_parenthesization_level(); |
2297 Expect(Token::RPAREN, CHECK_OK); | 2376 Expect(Token::RPAREN, CHECK_OK); |
2298 } | 2377 } |
2299 break; | 2378 break; |
2300 | 2379 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2357 | 2436 |
2358 | 2437 |
2359 // Precedence = 1 | 2438 // Precedence = 1 |
2360 template <class Traits> | 2439 template <class Traits> |
2361 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 2440 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
2362 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { | 2441 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
2363 // Expression :: | 2442 // Expression :: |
2364 // AssignmentExpression | 2443 // AssignmentExpression |
2365 // Expression ',' AssignmentExpression | 2444 // Expression ',' AssignmentExpression |
2366 | 2445 |
| 2446 ExpressionClassifier binding_classifier; |
2367 ExpressionT result = | 2447 ExpressionT result = |
2368 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); | 2448 this->ParseAssignmentExpression(accept_IN, &binding_classifier, CHECK_OK); |
| 2449 classifier->Accumulate(binding_classifier, |
| 2450 ExpressionClassifier::AllProductions); |
2369 while (peek() == Token::COMMA) { | 2451 while (peek() == Token::COMMA) { |
2370 Expect(Token::COMMA, CHECK_OK); | 2452 Expect(Token::COMMA, CHECK_OK); |
2371 int pos = position(); | 2453 int pos = position(); |
2372 ExpressionT right = | 2454 ExpressionT right = this->ParseAssignmentExpression( |
2373 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); | 2455 accept_IN, &binding_classifier, CHECK_OK); |
| 2456 classifier->Accumulate(binding_classifier, |
| 2457 ExpressionClassifier::AllProductions); |
2374 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); | 2458 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); |
2375 } | 2459 } |
2376 return result; | 2460 return result; |
2377 } | 2461 } |
2378 | 2462 |
2379 | 2463 |
2380 template <class Traits> | 2464 template <class Traits> |
2381 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral( | 2465 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral( |
2382 ExpressionClassifier* classifier, bool* ok) { | 2466 ExpressionClassifier* classifier, bool* ok) { |
2383 // ArrayLiteral :: | 2467 // ArrayLiteral :: |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2749 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 2833 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
2750 | 2834 |
2751 Scanner::Location lhs_location = scanner()->peek_location(); | 2835 Scanner::Location lhs_location = scanner()->peek_location(); |
2752 | 2836 |
2753 if (peek() == Token::YIELD && is_generator()) { | 2837 if (peek() == Token::YIELD && is_generator()) { |
2754 return this->ParseYieldExpression(classifier, ok); | 2838 return this->ParseYieldExpression(classifier, ok); |
2755 } | 2839 } |
2756 | 2840 |
2757 if (fni_ != NULL) fni_->Enter(); | 2841 if (fni_ != NULL) fni_->Enter(); |
2758 ParserBase<Traits>::Checkpoint checkpoint(this); | 2842 ParserBase<Traits>::Checkpoint checkpoint(this); |
2759 ExpressionT expression = | 2843 ExpressionClassifier arrow_formals_classifier; |
2760 this->ParseConditionalExpression(accept_IN, classifier, CHECK_OK); | 2844 if (peek() != Token::LPAREN) { |
| 2845 // The expression we are going to read is not a parenthesized arrow function |
| 2846 // formal parameter list. |
| 2847 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
| 2848 } |
| 2849 ExpressionT expression = this->ParseConditionalExpression( |
| 2850 accept_IN, &arrow_formals_classifier, CHECK_OK); |
| 2851 classifier->Accumulate(arrow_formals_classifier); |
2761 | 2852 |
2762 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { | 2853 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { |
2763 checkpoint.Restore(); | 2854 checkpoint.Restore(); |
2764 FormalParameterErrorLocations error_locs; | 2855 BindingPatternUnexpectedToken(classifier); |
| 2856 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
| 2857 CHECK_OK); |
2765 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); | 2858 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); |
2766 bool has_rest = false; | 2859 bool has_rest = false; |
2767 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); | 2860 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); |
2768 scope->set_start_position(lhs_location.beg_pos); | 2861 scope->set_start_position(lhs_location.beg_pos); |
2769 this->ParseArrowFunctionFormalParameters(scope, expression, loc, | 2862 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
2770 &error_locs, &has_rest, CHECK_OK); | 2863 this->ParseArrowFunctionFormalParameters(scope, expression, loc, &has_rest, |
2771 expression = this->ParseArrowFunctionLiteral(scope, error_locs, has_rest, | 2864 &duplicate_loc, CHECK_OK); |
2772 classifier, CHECK_OK); | 2865 if (duplicate_loc.IsValid()) { |
| 2866 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
| 2867 duplicate_loc); |
| 2868 } |
| 2869 expression = this->ParseArrowFunctionLiteral( |
| 2870 scope, has_rest, arrow_formals_classifier, CHECK_OK); |
2773 return expression; | 2871 return expression; |
2774 } | 2872 } |
2775 | 2873 |
| 2874 // "expression" was not itself an arrow function parameter list, but it might |
| 2875 // form part of one. Propagate speculative formal parameter error locations. |
| 2876 classifier->Accumulate(arrow_formals_classifier, |
| 2877 ExpressionClassifier::FormalParametersProduction); |
| 2878 |
2776 if (!Token::IsAssignmentOp(peek())) { | 2879 if (!Token::IsAssignmentOp(peek())) { |
2777 if (fni_ != NULL) fni_->Leave(); | 2880 if (fni_ != NULL) fni_->Leave(); |
2778 // Parsed conditional expression only (no assignment). | 2881 // Parsed conditional expression only (no assignment). |
2779 return expression; | 2882 return expression; |
2780 } | 2883 } |
2781 | 2884 |
| 2885 if (!allow_harmony_destructuring()) { |
| 2886 BindingPatternUnexpectedToken(classifier); |
| 2887 } |
| 2888 |
2782 expression = this->CheckAndRewriteReferenceExpression( | 2889 expression = this->CheckAndRewriteReferenceExpression( |
2783 expression, lhs_location, "invalid_lhs_in_assignment", CHECK_OK); | 2890 expression, lhs_location, "invalid_lhs_in_assignment", CHECK_OK); |
2784 expression = this->MarkExpressionAsAssigned(expression); | 2891 expression = this->MarkExpressionAsAssigned(expression); |
2785 | 2892 |
2786 Token::Value op = Next(); // Get assignment operator. | 2893 Token::Value op = Next(); // Get assignment operator. |
2787 int pos = position(); | 2894 int pos = position(); |
2788 ExpressionT right = | 2895 ExpressionT right = |
2789 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); | 2896 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); |
2790 | 2897 |
2791 // TODO(1231235): We try to estimate the set of properties set by | 2898 // TODO(1231235): We try to estimate the set of properties set by |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2873 bool* ok) { | 2980 bool* ok) { |
2874 // ConditionalExpression :: | 2981 // ConditionalExpression :: |
2875 // LogicalOrExpression | 2982 // LogicalOrExpression |
2876 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression | 2983 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression |
2877 | 2984 |
2878 int pos = peek_position(); | 2985 int pos = peek_position(); |
2879 // We start using the binary expression parser for prec >= 4 only! | 2986 // We start using the binary expression parser for prec >= 4 only! |
2880 ExpressionT expression = | 2987 ExpressionT expression = |
2881 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); | 2988 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); |
2882 if (peek() != Token::CONDITIONAL) return expression; | 2989 if (peek() != Token::CONDITIONAL) return expression; |
| 2990 BindingPatternUnexpectedToken(classifier); |
2883 Consume(Token::CONDITIONAL); | 2991 Consume(Token::CONDITIONAL); |
2884 // In parsing the first assignment expression in conditional | 2992 // In parsing the first assignment expression in conditional |
2885 // expressions we always accept the 'in' keyword; see ECMA-262, | 2993 // expressions we always accept the 'in' keyword; see ECMA-262, |
2886 // section 11.12, page 58. | 2994 // section 11.12, page 58. |
2887 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); | 2995 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); |
2888 Expect(Token::COLON, CHECK_OK); | 2996 Expect(Token::COLON, CHECK_OK); |
2889 ExpressionT right = | 2997 ExpressionT right = |
2890 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); | 2998 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); |
2891 return factory()->NewConditional(expression, left, right, pos); | 2999 return factory()->NewConditional(expression, left, right, pos); |
2892 } | 3000 } |
2893 | 3001 |
2894 | 3002 |
2895 // Precedence >= 4 | 3003 // Precedence >= 4 |
2896 template <class Traits> | 3004 template <class Traits> |
2897 typename ParserBase<Traits>::ExpressionT | 3005 typename ParserBase<Traits>::ExpressionT |
2898 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, | 3006 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, |
2899 ExpressionClassifier* classifier, | 3007 ExpressionClassifier* classifier, |
2900 bool* ok) { | 3008 bool* ok) { |
2901 DCHECK(prec >= 4); | 3009 DCHECK(prec >= 4); |
2902 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); | 3010 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); |
2903 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 3011 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
2904 // prec1 >= 4 | 3012 // prec1 >= 4 |
2905 while (Precedence(peek(), accept_IN) == prec1) { | 3013 while (Precedence(peek(), accept_IN) == prec1) { |
| 3014 BindingPatternUnexpectedToken(classifier); |
2906 Token::Value op = Next(); | 3015 Token::Value op = Next(); |
2907 Scanner::Location op_location = scanner()->location(); | 3016 Scanner::Location op_location = scanner()->location(); |
2908 int pos = position(); | 3017 int pos = position(); |
2909 ExpressionT y = | 3018 ExpressionT y = |
2910 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); | 3019 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); |
2911 | 3020 |
2912 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, | 3021 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, |
2913 factory())) { | 3022 factory())) { |
2914 continue; | 3023 continue; |
2915 } | 3024 } |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3462 default: | 3571 default: |
3463 return expression; | 3572 return expression; |
3464 } | 3573 } |
3465 } | 3574 } |
3466 DCHECK(false); | 3575 DCHECK(false); |
3467 return this->EmptyExpression(); | 3576 return this->EmptyExpression(); |
3468 } | 3577 } |
3469 | 3578 |
3470 | 3579 |
3471 template <class Traits> | 3580 template <class Traits> |
3472 void ParserBase<Traits>::ParseFormalParameter( | 3581 void ParserBase<Traits>::ParseFormalParameter(FormalParameterScopeT* scope, |
3473 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, | 3582 bool is_rest, |
3474 bool is_rest, bool* ok) { | 3583 ExpressionClassifier* classifier, |
| 3584 bool* ok) { |
3475 // FormalParameter[Yield,GeneratorParameter] : | 3585 // FormalParameter[Yield,GeneratorParameter] : |
3476 // BindingElement[?Yield, ?GeneratorParameter] | 3586 // BindingElement[?Yield, ?GeneratorParameter] |
3477 bool is_strict_reserved; | 3587 IdentifierT name = ParseAndClassifyIdentifier(classifier, ok); |
3478 IdentifierT name = | |
3479 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok); | |
3480 if (!*ok) return; | 3588 if (!*ok) return; |
3481 | 3589 |
3482 // Store locations for possible future error reports. | |
3483 if (!locs->eval_or_arguments.IsValid() && this->IsEvalOrArguments(name)) { | |
3484 locs->eval_or_arguments = scanner()->location(); | |
3485 } | |
3486 if (!locs->undefined.IsValid() && this->IsUndefined(name)) { | |
3487 locs->undefined = scanner()->location(); | |
3488 } | |
3489 if (!locs->reserved.IsValid() && is_strict_reserved) { | |
3490 locs->reserved = scanner()->location(); | |
3491 } | |
3492 bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest); | 3590 bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest); |
3493 if (!locs->duplicate.IsValid() && was_declared) { | 3591 if (was_declared) { |
3494 locs->duplicate = scanner()->location(); | 3592 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
3495 } | 3593 } |
3496 } | 3594 } |
3497 | 3595 |
3498 | 3596 |
3499 template <class Traits> | 3597 template <class Traits> |
3500 int ParserBase<Traits>::ParseFormalParameterList( | 3598 int ParserBase<Traits>::ParseFormalParameterList( |
3501 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, | 3599 FormalParameterScopeT* scope, bool* is_rest, |
3502 bool* is_rest, bool* ok) { | 3600 ExpressionClassifier* classifier, bool* ok) { |
3503 // FormalParameters[Yield,GeneratorParameter] : | 3601 // FormalParameters[Yield,GeneratorParameter] : |
3504 // [empty] | 3602 // [empty] |
3505 // FormalParameterList[?Yield, ?GeneratorParameter] | 3603 // FormalParameterList[?Yield, ?GeneratorParameter] |
3506 // | 3604 // |
3507 // FormalParameterList[Yield,GeneratorParameter] : | 3605 // FormalParameterList[Yield,GeneratorParameter] : |
3508 // FunctionRestParameter[?Yield] | 3606 // FunctionRestParameter[?Yield] |
3509 // FormalsList[?Yield, ?GeneratorParameter] | 3607 // FormalsList[?Yield, ?GeneratorParameter] |
3510 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] | 3608 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] |
3511 // | 3609 // |
3512 // FormalsList[Yield,GeneratorParameter] : | 3610 // FormalsList[Yield,GeneratorParameter] : |
3513 // FormalParameter[?Yield, ?GeneratorParameter] | 3611 // FormalParameter[?Yield, ?GeneratorParameter] |
3514 // FormalsList[?Yield, ?GeneratorParameter] , | 3612 // FormalsList[?Yield, ?GeneratorParameter] , |
3515 // FormalParameter[?Yield,?GeneratorParameter] | 3613 // FormalParameter[?Yield,?GeneratorParameter] |
3516 | 3614 |
3517 int parameter_count = 0; | 3615 int parameter_count = 0; |
3518 | 3616 |
3519 if (peek() != Token::RPAREN) { | 3617 if (peek() != Token::RPAREN) { |
3520 do { | 3618 do { |
3521 if (++parameter_count > Code::kMaxArguments) { | 3619 if (++parameter_count > Code::kMaxArguments) { |
3522 ReportMessage("too_many_parameters"); | 3620 ReportMessage("too_many_parameters"); |
3523 *ok = false; | 3621 *ok = false; |
3524 return -1; | 3622 return -1; |
3525 } | 3623 } |
3526 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); | 3624 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); |
3527 ParseFormalParameter(scope, locs, *is_rest, ok); | 3625 ParseFormalParameter(scope, *is_rest, classifier, ok); |
3528 if (!*ok) return -1; | 3626 if (!*ok) return -1; |
3529 } while (!*is_rest && Check(Token::COMMA)); | 3627 } while (!*is_rest && Check(Token::COMMA)); |
3530 | 3628 |
3531 if (*is_rest && peek() == Token::COMMA) { | 3629 if (*is_rest && peek() == Token::COMMA) { |
3532 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); | 3630 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); |
3533 *ok = false; | 3631 *ok = false; |
3534 return -1; | 3632 return -1; |
3535 } | 3633 } |
3536 } | 3634 } |
3537 | 3635 |
(...skipping 22 matching lines...) Expand all Loading... |
3560 break; | 3658 break; |
3561 default: | 3659 default: |
3562 break; | 3660 break; |
3563 } | 3661 } |
3564 } | 3662 } |
3565 | 3663 |
3566 | 3664 |
3567 template <class Traits> | 3665 template <class Traits> |
3568 typename ParserBase<Traits>::ExpressionT | 3666 typename ParserBase<Traits>::ExpressionT |
3569 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3667 ParserBase<Traits>::ParseArrowFunctionLiteral( |
3570 Scope* scope, const FormalParameterErrorLocations& error_locs, | 3668 Scope* scope, bool has_rest, const ExpressionClassifier& formals_classifier, |
3571 bool has_rest, ExpressionClassifier* classifier, bool* ok) { | 3669 bool* ok) { |
3572 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3670 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
3573 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3671 // ASI inserts `;` after arrow parameters if a line terminator is found. |
3574 // `=> ...` is never a valid expression, so report as syntax error. | 3672 // `=> ...` is never a valid expression, so report as syntax error. |
3575 // If next token is not `=>`, it's a syntax error anyways. | 3673 // If next token is not `=>`, it's a syntax error anyways. |
3576 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3674 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
3577 *ok = false; | 3675 *ok = false; |
3578 return this->EmptyExpression(); | 3676 return this->EmptyExpression(); |
3579 } | 3677 } |
3580 | 3678 |
3581 typename Traits::Type::StatementList body; | 3679 typename Traits::Type::StatementList body; |
3582 int num_parameters = scope->num_parameters(); | 3680 int num_parameters = scope->num_parameters(); |
3583 int materialized_literal_count = -1; | 3681 int materialized_literal_count = -1; |
3584 int expected_property_count = -1; | 3682 int expected_property_count = -1; |
3585 int handler_count = 0; | 3683 int handler_count = 0; |
3586 Scanner::Location super_loc; | 3684 Scanner::Location super_loc; |
3587 | 3685 |
3588 { | 3686 { |
3589 typename Traits::Type::Factory function_factory(ast_value_factory()); | 3687 typename Traits::Type::Factory function_factory(ast_value_factory()); |
3590 FunctionState function_state(&function_state_, &scope_, scope, | 3688 FunctionState function_state(&function_state_, &scope_, scope, |
3591 kArrowFunction, &function_factory); | 3689 kArrowFunction, &function_factory); |
3592 | 3690 |
3593 if (peek() == Token::ARROW) { | |
3594 BindingPatternUnexpectedToken(classifier); | |
3595 } | |
3596 Expect(Token::ARROW, CHECK_OK); | 3691 Expect(Token::ARROW, CHECK_OK); |
3597 | 3692 |
3598 if (peek() == Token::LBRACE) { | 3693 if (peek() == Token::LBRACE) { |
3599 // Multiple statement body | 3694 // Multiple statement body |
3600 Consume(Token::LBRACE); | 3695 Consume(Token::LBRACE); |
3601 bool is_lazily_parsed = | 3696 bool is_lazily_parsed = |
3602 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); | 3697 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); |
3603 if (is_lazily_parsed) { | 3698 if (is_lazily_parsed) { |
3604 body = this->NewStatementList(0, zone()); | 3699 body = this->NewStatementList(0, zone()); |
3605 this->SkipLazyFunctionBody(&materialized_literal_count, | 3700 this->SkipLazyFunctionBody(&materialized_literal_count, |
3606 &expected_property_count, CHECK_OK); | 3701 &expected_property_count, CHECK_OK); |
3607 } else { | 3702 } else { |
3608 body = this->ParseEagerFunctionBody( | 3703 body = this->ParseEagerFunctionBody( |
3609 this->EmptyIdentifier(), RelocInfo::kNoPosition, NULL, | 3704 this->EmptyIdentifier(), RelocInfo::kNoPosition, NULL, |
3610 Token::INIT_VAR, kArrowFunction, CHECK_OK); | 3705 Token::INIT_VAR, kArrowFunction, CHECK_OK); |
3611 materialized_literal_count = | 3706 materialized_literal_count = |
3612 function_state.materialized_literal_count(); | 3707 function_state.materialized_literal_count(); |
3613 expected_property_count = function_state.expected_property_count(); | 3708 expected_property_count = function_state.expected_property_count(); |
3614 handler_count = function_state.handler_count(); | 3709 handler_count = function_state.handler_count(); |
3615 } | 3710 } |
3616 } else { | 3711 } else { |
3617 // Single-expression body | 3712 // Single-expression body |
3618 int pos = position(); | 3713 int pos = position(); |
3619 parenthesized_function_ = false; | 3714 parenthesized_function_ = false; |
| 3715 ExpressionClassifier classifier; |
3620 ExpressionT expression = | 3716 ExpressionT expression = |
3621 ParseAssignmentExpression(true, classifier, CHECK_OK); | 3717 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 3718 ValidateExpression(&classifier, CHECK_OK); |
3622 body = this->NewStatementList(1, zone()); | 3719 body = this->NewStatementList(1, zone()); |
3623 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 3720 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
3624 materialized_literal_count = function_state.materialized_literal_count(); | 3721 materialized_literal_count = function_state.materialized_literal_count(); |
3625 expected_property_count = function_state.expected_property_count(); | 3722 expected_property_count = function_state.expected_property_count(); |
3626 handler_count = function_state.handler_count(); | 3723 handler_count = function_state.handler_count(); |
3627 } | 3724 } |
3628 super_loc = function_state.super_location(); | 3725 super_loc = function_state.super_location(); |
3629 | 3726 |
3630 scope->set_end_position(scanner()->location().end_pos); | 3727 scope->set_end_position(scanner()->location().end_pos); |
3631 | 3728 |
3632 // Arrow function formal parameters are parsed as StrictFormalParameterList, | 3729 // Arrow function formal parameters are parsed as StrictFormalParameterList, |
3633 // which is not the same as "parameters of a strict function"; it only means | 3730 // which is not the same as "parameters of a strict function"; it only means |
3634 // that duplicates are not allowed. Of course, the arrow function may | 3731 // that duplicates are not allowed. Of course, the arrow function may |
3635 // itself be strict as well. | 3732 // itself be strict as well. |
3636 const bool use_strict_params = true; | 3733 const bool allow_duplicate_parameters = false; |
3637 this->CheckFunctionParameterNames(language_mode(), use_strict_params, | 3734 this->ValidateFormalParameters(&formals_classifier, language_mode(), |
3638 error_locs, CHECK_OK); | 3735 allow_duplicate_parameters, CHECK_OK); |
3639 | 3736 |
3640 // Validate strict mode. | 3737 // Validate strict mode. |
3641 if (is_strict(language_mode())) { | 3738 if (is_strict(language_mode())) { |
3642 CheckStrictOctalLiteral(scope->start_position(), | 3739 CheckStrictOctalLiteral(scope->start_position(), |
3643 scanner()->location().end_pos, CHECK_OK); | 3740 scanner()->location().end_pos, CHECK_OK); |
3644 this->CheckConflictingVarDeclarations(scope, CHECK_OK); | 3741 this->CheckConflictingVarDeclarations(scope, CHECK_OK); |
3645 } | 3742 } |
3646 } | 3743 } |
3647 | 3744 |
3648 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 3745 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3843 *ok = false; | 3940 *ok = false; |
3844 return; | 3941 return; |
3845 } | 3942 } |
3846 has_seen_constructor_ = true; | 3943 has_seen_constructor_ = true; |
3847 return; | 3944 return; |
3848 } | 3945 } |
3849 } | 3946 } |
3850 } } // v8::internal | 3947 } } // v8::internal |
3851 | 3948 |
3852 #endif // V8_PREPARSER_H | 3949 #endif // V8_PREPARSER_H |
OLD | NEW |