| 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 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 898 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
| 899 // Function :: | 899 // Function :: |
| 900 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 900 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 901 | 901 |
| 902 // Parse function body. | 902 // Parse function body. |
| 903 bool outer_is_script_scope = scope_->is_script_scope(); | 903 bool outer_is_script_scope = scope_->is_script_scope(); |
| 904 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); | 904 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); |
| 905 PreParserFactory factory(NULL); | 905 PreParserFactory factory(NULL); |
| 906 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 906 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
| 907 &factory); | 907 &factory); |
| 908 // FormalParameterList :: | |
| 909 // '(' (Identifier)*[','] ')' | |
| 910 Expect(Token::LPAREN, CHECK_OK); | |
| 911 int start_position = position(); | |
| 912 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | |
| 913 // We don't yet know if the function will be strict, so we cannot yet produce | 908 // We don't yet know if the function will be strict, so we cannot yet produce |
| 914 // errors for parameter names or duplicates. However, we remember the | 909 // errors for parameter names or duplicates. However, we remember the |
| 915 // locations of these errors if they occur and produce the errors later. | 910 // locations of these errors if they occur and produce the errors later. |
| 916 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); | 911 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); |
| 917 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 912 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
| 918 Scanner::Location reserved_error_loc = Scanner::Location::invalid(); | 913 Scanner::Location reserved_error_loc = Scanner::Location::invalid(); |
| 919 | 914 |
| 920 bool is_rest = false; | 915 bool is_rest = false; |
| 921 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || | 916 Expect(Token::LPAREN, CHECK_OK); |
| 922 (peek() == Token::RPAREN && | 917 int start_position = scanner()->location().beg_pos; |
| 923 arity_restriction != FunctionLiteral::SETTER_ARITY); | 918 PreParserFormalParameterList params = |
| 924 while (!done) { | 919 ParseFormalParameterList(&eval_args_error_loc, &dupe_error_loc, |
| 925 bool is_strict_reserved = false; | 920 &reserved_error_loc, &is_rest, CHECK_OK); |
| 926 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); | 921 Expect(Token::RPAREN, CHECK_OK); |
| 927 if (is_rest) { | 922 int formals_end_position = scanner()->location().end_pos; |
| 928 Consume(Token::ELLIPSIS); | |
| 929 } | |
| 930 | 923 |
| 931 Identifier param_name = | 924 CheckArityRestrictions(params->length(), arity_restriction, start_position, |
| 932 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 925 formals_end_position, ok); |
| 933 if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) { | 926 if (!*ok) return Expression::Default(); |
| 934 eval_args_error_loc = scanner()->location(); | |
| 935 } | |
| 936 if (!reserved_error_loc.IsValid() && is_strict_reserved) { | |
| 937 reserved_error_loc = scanner()->location(); | |
| 938 } | |
| 939 | |
| 940 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1); | |
| 941 | |
| 942 if (!dupe_error_loc.IsValid() && prev_value != 0) { | |
| 943 dupe_error_loc = scanner()->location(); | |
| 944 } | |
| 945 | |
| 946 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; | |
| 947 done = (peek() == Token::RPAREN); | |
| 948 if (!done) { | |
| 949 if (is_rest) { | |
| 950 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); | |
| 951 *ok = false; | |
| 952 return Expression::Default(); | |
| 953 } | |
| 954 Expect(Token::COMMA, CHECK_OK); | |
| 955 } | |
| 956 } | |
| 957 Expect(Token::RPAREN, CHECK_OK); | |
| 958 | 927 |
| 959 // See Parser::ParseFunctionLiteral for more information about lazy parsing | 928 // See Parser::ParseFunctionLiteral for more information about lazy parsing |
| 960 // and lazy compilation. | 929 // and lazy compilation. |
| 961 bool is_lazily_parsed = | 930 bool is_lazily_parsed = |
| 962 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); | 931 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); |
| 963 parenthesized_function_ = false; | 932 parenthesized_function_ = false; |
| 964 | 933 |
| 965 Expect(Token::LBRACE, CHECK_OK); | 934 Expect(Token::LBRACE, CHECK_OK); |
| 966 if (is_lazily_parsed) { | 935 if (is_lazily_parsed) { |
| 967 ParseLazyFunctionLiteralBody(CHECK_OK); | 936 ParseLazyFunctionLiteralBody(CHECK_OK); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 | 1043 |
| 1075 DCHECK(!spread_pos.IsValid()); | 1044 DCHECK(!spread_pos.IsValid()); |
| 1076 | 1045 |
| 1077 return Expression::Default(); | 1046 return Expression::Default(); |
| 1078 } | 1047 } |
| 1079 | 1048 |
| 1080 #undef CHECK_OK | 1049 #undef CHECK_OK |
| 1081 | 1050 |
| 1082 | 1051 |
| 1083 } } // v8::internal | 1052 } } // v8::internal |
| OLD | NEW |