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 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 function_scope->SetLanguageMode(language_mode); | 1045 function_scope->SetLanguageMode(language_mode); |
1046 PreParserFactory factory(NULL); | 1046 PreParserFactory factory(NULL); |
1047 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 1047 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
1048 &factory); | 1048 &factory); |
1049 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 1049 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
1050 ExpressionClassifier formals_classifier(&duplicate_finder); | 1050 ExpressionClassifier formals_classifier(&duplicate_finder); |
1051 | 1051 |
1052 Expect(Token::LPAREN, CHECK_OK); | 1052 Expect(Token::LPAREN, CHECK_OK); |
1053 int start_position = scanner()->location().beg_pos; | 1053 int start_position = scanner()->location().beg_pos; |
1054 function_scope->set_start_position(start_position); | 1054 function_scope->set_start_position(start_position); |
1055 PreParserFormalParameterParsingState parsing_state(nullptr); | 1055 PreParserFormalParameters formals(nullptr); |
1056 int num_parameters = | 1056 int arity = ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); |
1057 ParseFormalParameterList(&parsing_state, &formals_classifier, CHECK_OK); | |
1058 Expect(Token::RPAREN, CHECK_OK); | 1057 Expect(Token::RPAREN, CHECK_OK); |
1059 int formals_end_position = scanner()->location().end_pos; | 1058 int formals_end_position = scanner()->location().end_pos; |
1060 | 1059 |
1061 CheckArityRestrictions(num_parameters, arity_restriction, | 1060 CheckArityRestrictions(arity, arity_restriction, |
1062 parsing_state.has_rest, start_position, | 1061 formals.has_rest, start_position, |
1063 formals_end_position, CHECK_OK); | 1062 formals_end_position, CHECK_OK); |
1064 | 1063 |
1065 // See Parser::ParseFunctionLiteral for more information about lazy parsing | 1064 // See Parser::ParseFunctionLiteral for more information about lazy parsing |
1066 // and lazy compilation. | 1065 // and lazy compilation. |
1067 bool is_lazily_parsed = | 1066 bool is_lazily_parsed = |
1068 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); | 1067 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); |
1069 parenthesized_function_ = false; | 1068 parenthesized_function_ = false; |
1070 | 1069 |
1071 Expect(Token::LBRACE, CHECK_OK); | 1070 Expect(Token::LBRACE, CHECK_OK); |
1072 if (is_lazily_parsed) { | 1071 if (is_lazily_parsed) { |
1073 ParseLazyFunctionLiteralBody(CHECK_OK); | 1072 ParseLazyFunctionLiteralBody(CHECK_OK); |
1074 } else { | 1073 } else { |
1075 ParseStatementList(Token::RBRACE, CHECK_OK); | 1074 ParseStatementList(Token::RBRACE, CHECK_OK); |
1076 } | 1075 } |
1077 Expect(Token::RBRACE, CHECK_OK); | 1076 Expect(Token::RBRACE, CHECK_OK); |
1078 | 1077 |
1079 // Parsing the body may change the language mode in our scope. | 1078 // Parsing the body may change the language mode in our scope. |
1080 language_mode = function_scope->language_mode(); | 1079 language_mode = function_scope->language_mode(); |
1081 | 1080 |
1082 // Validate name and parameter names. We can do this only after parsing the | 1081 // Validate name and parameter names. We can do this only after parsing the |
1083 // function, since the function can declare itself strict. | 1082 // function, since the function can declare itself strict. |
1084 CheckFunctionName(language_mode, function_name, function_name_validity, | 1083 CheckFunctionName(language_mode, function_name, function_name_validity, |
1085 function_name_location, CHECK_OK); | 1084 function_name_location, CHECK_OK); |
1086 const bool strict_formal_parameters = | |
1087 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind); | |
1088 const bool allow_duplicate_parameters = | 1085 const bool allow_duplicate_parameters = |
1089 is_sloppy(language_mode) && !strict_formal_parameters; | 1086 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); |
1090 ValidateFormalParameters(&formals_classifier, language_mode, | 1087 ValidateFormalParameters(&formals_classifier, language_mode, |
1091 allow_duplicate_parameters, CHECK_OK); | 1088 allow_duplicate_parameters, CHECK_OK); |
1092 | 1089 |
1093 if (is_strict(language_mode)) { | 1090 if (is_strict(language_mode)) { |
1094 int end_position = scanner()->location().end_pos; | 1091 int end_position = scanner()->location().end_pos; |
1095 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 1092 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
1096 } | 1093 } |
1097 | 1094 |
1098 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { | 1095 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { |
1099 if (!function_state.super_location().IsValid()) { | 1096 if (!function_state.super_location().IsValid()) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 | 1199 |
1203 DCHECK(!spread_pos.IsValid()); | 1200 DCHECK(!spread_pos.IsValid()); |
1204 | 1201 |
1205 return Expression::Default(); | 1202 return Expression::Default(); |
1206 } | 1203 } |
1207 | 1204 |
1208 #undef CHECK_OK | 1205 #undef CHECK_OK |
1209 | 1206 |
1210 | 1207 |
1211 } } // v8::internal | 1208 } } // v8::internal |
OLD | NEW |