OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 #include <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 901 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
902 // Function :: | 902 // Function :: |
903 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 903 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
904 | 904 |
905 // Parse function body. | 905 // Parse function body. |
906 bool outer_is_script_scope = scope_->is_script_scope(); | 906 bool outer_is_script_scope = scope_->is_script_scope(); |
907 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); | 907 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); |
908 PreParserFactory factory(NULL); | 908 PreParserFactory factory(NULL); |
909 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 909 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
910 &factory); | 910 &factory); |
911 // FormalParameterList :: | |
912 // '(' (Identifier)*[','] ')' | |
913 Expect(Token::LPAREN, CHECK_OK); | |
914 int start_position = position(); | |
915 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | |
916 // We don't yet know if the function will be strict, so we cannot yet produce | 911 // We don't yet know if the function will be strict, so we cannot yet produce |
917 // errors for parameter names or duplicates. However, we remember the | 912 // errors for parameter names or duplicates. However, we remember the |
918 // locations of these errors if they occur and produce the errors later. | 913 // locations of these errors if they occur and produce the errors later. |
919 Scanner::Location eval_args_loc = Scanner::Location::invalid(); | 914 Scanner::Location eval_args_loc = Scanner::Location::invalid(); |
920 Scanner::Location dupe_loc = Scanner::Location::invalid(); | 915 Scanner::Location dupe_loc = Scanner::Location::invalid(); |
921 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 916 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
922 | 917 |
923 // Similarly for strong mode. | 918 // Similarly for strong mode. |
924 Scanner::Location undefined_loc = Scanner::Location::invalid(); | 919 Scanner::Location undefined_loc = Scanner::Location::invalid(); |
925 | 920 |
926 bool is_rest = false; | 921 bool is_rest = false; |
927 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || | 922 Expect(Token::LPAREN, CHECK_OK); |
928 (peek() == Token::RPAREN && | 923 int start_position = scanner()->location().beg_pos; |
929 arity_restriction != FunctionLiteral::SETTER_ARITY); | 924 PreParserFormalParameterList params = |
930 while (!done) { | 925 ParseFormalParameterList(&eval_args_loc, &undefined_loc, &dupe_loc, |
931 bool is_strict_reserved = false; | 926 &reserved_loc, &is_rest, CHECK_OK); |
932 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); | 927 Expect(Token::RPAREN, CHECK_OK); |
933 if (is_rest) { | 928 int formals_end_position = scanner()->location().end_pos; |
934 Consume(Token::ELLIPSIS); | |
935 } | |
936 | 929 |
937 Identifier param_name = | 930 CheckArityRestrictions(params->length(), arity_restriction, start_position, |
938 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 931 formals_end_position, ok); |
939 if (!eval_args_loc.IsValid() && param_name.IsEvalOrArguments()) { | 932 if (!*ok) return Expression::Default(); |
940 eval_args_loc = scanner()->location(); | |
941 } | |
942 if (!undefined_loc.IsValid() && param_name.IsUndefined()) { | |
943 undefined_loc = scanner()->location(); | |
944 } | |
945 if (!reserved_loc.IsValid() && is_strict_reserved) { | |
946 reserved_loc = scanner()->location(); | |
947 } | |
948 | |
949 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1); | |
950 | |
951 if (!dupe_loc.IsValid() && prev_value != 0) { | |
952 dupe_loc = scanner()->location(); | |
953 } | |
954 | |
955 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; | |
956 done = (peek() == Token::RPAREN); | |
957 if (!done) { | |
958 if (is_rest) { | |
959 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); | |
960 *ok = false; | |
961 return Expression::Default(); | |
962 } | |
963 Expect(Token::COMMA, CHECK_OK); | |
964 } | |
965 } | |
966 Expect(Token::RPAREN, CHECK_OK); | |
967 | 933 |
968 // See Parser::ParseFunctionLiteral for more information about lazy parsing | 934 // See Parser::ParseFunctionLiteral for more information about lazy parsing |
969 // and lazy compilation. | 935 // and lazy compilation. |
970 bool is_lazily_parsed = | 936 bool is_lazily_parsed = |
971 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); | 937 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); |
972 parenthesized_function_ = false; | 938 parenthesized_function_ = false; |
973 | 939 |
974 Expect(Token::LBRACE, CHECK_OK); | 940 Expect(Token::LBRACE, CHECK_OK); |
975 if (is_lazily_parsed) { | 941 if (is_lazily_parsed) { |
976 ParseLazyFunctionLiteralBody(CHECK_OK); | 942 ParseLazyFunctionLiteralBody(CHECK_OK); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 | 1054 |
1089 DCHECK(!spread_pos.IsValid()); | 1055 DCHECK(!spread_pos.IsValid()); |
1090 | 1056 |
1091 return Expression::Default(); | 1057 return Expression::Default(); |
1092 } | 1058 } |
1093 | 1059 |
1094 #undef CHECK_OK | 1060 #undef CHECK_OK |
1095 | 1061 |
1096 | 1062 |
1097 } } // v8::internal | 1063 } } // v8::internal |
OLD | NEW |