| 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 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 919 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
| 920 // Function :: | 920 // Function :: |
| 921 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 921 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 922 | 922 |
| 923 // Parse function body. | 923 // Parse function body. |
| 924 bool outer_is_script_scope = scope_->is_script_scope(); | 924 bool outer_is_script_scope = scope_->is_script_scope(); |
| 925 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); | 925 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); |
| 926 PreParserFactory factory(NULL); | 926 PreParserFactory factory(NULL); |
| 927 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 927 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
| 928 &factory); | 928 &factory); |
| 929 // FormalParameterList :: | 929 FormalParameterErrorLocations error_locs; |
| 930 // '(' (Identifier)*[','] ')' | |
| 931 Expect(Token::LPAREN, CHECK_OK); | |
| 932 int start_position = position(); | |
| 933 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | |
| 934 // We don't yet know if the function will be strict, so we cannot yet produce | |
| 935 // errors for parameter names or duplicates. However, we remember the | |
| 936 // locations of these errors if they occur and produce the errors later. | |
| 937 Scanner::Location eval_args_loc = Scanner::Location::invalid(); | |
| 938 Scanner::Location dupe_loc = Scanner::Location::invalid(); | |
| 939 Scanner::Location reserved_loc = Scanner::Location::invalid(); | |
| 940 | |
| 941 // Similarly for strong mode. | |
| 942 Scanner::Location undefined_loc = Scanner::Location::invalid(); | |
| 943 | 930 |
| 944 bool is_rest = false; | 931 bool is_rest = false; |
| 945 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || | 932 Expect(Token::LPAREN, CHECK_OK); |
| 946 (peek() == Token::RPAREN && | 933 int start_position = scanner()->location().beg_pos; |
| 947 arity_restriction != FunctionLiteral::SETTER_ARITY); | 934 function_scope->set_start_position(start_position); |
| 948 while (!done) { | 935 int num_parameters = ParseFormalParameterList(function_scope, &error_locs, |
| 949 bool is_strict_reserved = false; | 936 &is_rest, CHECK_OK); |
| 950 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); | 937 Expect(Token::RPAREN, CHECK_OK); |
| 951 if (is_rest) { | 938 int formals_end_position = scanner()->location().end_pos; |
| 952 Consume(Token::ELLIPSIS); | |
| 953 } | |
| 954 | 939 |
| 955 Identifier param_name = | 940 CheckArityRestrictions(num_parameters, arity_restriction, |
| 956 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 941 start_position, formals_end_position, CHECK_OK); |
| 957 if (!eval_args_loc.IsValid() && param_name.IsEvalOrArguments()) { | |
| 958 eval_args_loc = scanner()->location(); | |
| 959 } | |
| 960 if (!undefined_loc.IsValid() && param_name.IsUndefined()) { | |
| 961 undefined_loc = scanner()->location(); | |
| 962 } | |
| 963 if (!reserved_loc.IsValid() && is_strict_reserved) { | |
| 964 reserved_loc = scanner()->location(); | |
| 965 } | |
| 966 | |
| 967 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1); | |
| 968 | |
| 969 if (!dupe_loc.IsValid() && prev_value != 0) { | |
| 970 dupe_loc = scanner()->location(); | |
| 971 } | |
| 972 | |
| 973 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; | |
| 974 done = (peek() == Token::RPAREN); | |
| 975 if (!done) { | |
| 976 if (is_rest) { | |
| 977 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); | |
| 978 *ok = false; | |
| 979 return Expression::Default(); | |
| 980 } | |
| 981 Expect(Token::COMMA, CHECK_OK); | |
| 982 } | |
| 983 } | |
| 984 Expect(Token::RPAREN, CHECK_OK); | |
| 985 | 942 |
| 986 // See Parser::ParseFunctionLiteral for more information about lazy parsing | 943 // See Parser::ParseFunctionLiteral for more information about lazy parsing |
| 987 // and lazy compilation. | 944 // and lazy compilation. |
| 988 bool is_lazily_parsed = | 945 bool is_lazily_parsed = |
| 989 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); | 946 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); |
| 990 parenthesized_function_ = false; | 947 parenthesized_function_ = false; |
| 991 | 948 |
| 992 Expect(Token::LBRACE, CHECK_OK); | 949 Expect(Token::LBRACE, CHECK_OK); |
| 993 if (is_lazily_parsed) { | 950 if (is_lazily_parsed) { |
| 994 ParseLazyFunctionLiteralBody(CHECK_OK); | 951 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 995 } else { | 952 } else { |
| 996 ParseStatementList(Token::RBRACE, CHECK_OK); | 953 ParseStatementList(Token::RBRACE, CHECK_OK); |
| 997 } | 954 } |
| 998 Expect(Token::RBRACE, CHECK_OK); | 955 Expect(Token::RBRACE, CHECK_OK); |
| 999 | 956 |
| 1000 // Validate name and parameter names. We can do this only after parsing the | 957 // Validate name and parameter names. We can do this only after parsing the |
| 1001 // function, since the function can declare itself strict. | 958 // function, since the function can declare itself strict. |
| 1002 CheckFunctionName(language_mode(), kind, function_name, | 959 CheckFunctionName(language_mode(), kind, function_name, |
| 1003 name_is_strict_reserved, function_name_location, CHECK_OK); | 960 name_is_strict_reserved, function_name_location, CHECK_OK); |
| 1004 const bool use_strict_params = is_rest || IsConciseMethod(kind); | 961 const bool use_strict_params = is_rest || IsConciseMethod(kind); |
| 1005 CheckFunctionParameterNames(language_mode(), use_strict_params, eval_args_loc, | 962 CheckFunctionParameterNames(language_mode(), use_strict_params, error_locs, |
| 1006 undefined_loc, dupe_loc, reserved_loc, CHECK_OK); | 963 CHECK_OK); |
| 1007 | 964 |
| 1008 if (is_strict(language_mode())) { | 965 if (is_strict(language_mode())) { |
| 1009 int end_position = scanner()->location().end_pos; | 966 int end_position = scanner()->location().end_pos; |
| 1010 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 967 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
| 1011 } | 968 } |
| 1012 | 969 |
| 1013 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { | 970 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { |
| 1014 if (!function_state.super_call_location().IsValid()) { | 971 if (!function_state.super_call_location().IsValid()) { |
| 1015 ReportMessageAt(function_name_location, "strong_super_call_missing", | 972 ReportMessageAt(function_name_location, "strong_super_call_missing", |
| 1016 kReferenceError); | 973 kReferenceError); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 | 1063 |
| 1107 DCHECK(!spread_pos.IsValid()); | 1064 DCHECK(!spread_pos.IsValid()); |
| 1108 | 1065 |
| 1109 return Expression::Default(); | 1066 return Expression::Default(); |
| 1110 } | 1067 } |
| 1111 | 1068 |
| 1112 #undef CHECK_OK | 1069 #undef CHECK_OK |
| 1113 | 1070 |
| 1114 | 1071 |
| 1115 } } // v8::internal | 1072 } } // v8::internal |
| OLD | NEW |