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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 // The caller passes the function_scope which is not yet inserted into the | 95 // The caller passes the function_scope which is not yet inserted into the |
96 // scope_state_. All scopes above the function_scope are ignored by the | 96 // scope_state_. All scopes above the function_scope are ignored by the |
97 // PreParser. | 97 // PreParser. |
98 DCHECK_NULL(scope_state_); | 98 DCHECK_NULL(scope_state_); |
99 FunctionState function_state(&function_state_, &scope_state_, function_scope); | 99 FunctionState function_state(&function_state_, &scope_state_, function_scope); |
100 // This indirection is needed so that we can use the CHECK_OK macros. | 100 // This indirection is needed so that we can use the CHECK_OK macros. |
101 bool ok_holder = true; | 101 bool ok_holder = true; |
102 bool* ok = &ok_holder; | 102 bool* ok = &ok_holder; |
103 | 103 |
104 PreParserFormalParameters formals(function_scope); | 104 PreParserFormalParameters* formals = |
| 105 new (zone()) PreParserFormalParameters(function_scope); |
105 bool has_duplicate_parameters = false; | 106 bool has_duplicate_parameters = false; |
106 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 107 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
107 std::unique_ptr<ExpressionClassifier> formals_classifier; | 108 std::unique_ptr<ExpressionClassifier> formals_classifier; |
108 | 109 |
109 // Parse non-arrow function parameters. For arrow functions, the parameters | 110 // Parse non-arrow function parameters. For arrow functions, the parameters |
110 // have already been parsed. | 111 // have already been parsed. |
111 if (!IsArrowFunction(kind)) { | 112 if (!IsArrowFunction(kind)) { |
112 formals_classifier.reset(new ExpressionClassifier(this, &duplicate_finder)); | 113 formals_classifier.reset(new ExpressionClassifier(this, &duplicate_finder)); |
113 // We return kPreParseSuccess in failure cases too - errors are retrieved | 114 // We return kPreParseSuccess in failure cases too - errors are retrieved |
114 // separately by Parser::SkipLazyFunctionBody. | 115 // separately by Parser::SkipLazyFunctionBody. |
115 ParseFormalParameterList(&formals, CHECK_OK_VALUE(kPreParseSuccess)); | 116 ParseFormalParameterList(formals, CHECK_OK_VALUE(kPreParseSuccess)); |
116 Expect(Token::RPAREN, CHECK_OK_VALUE(kPreParseSuccess)); | 117 Expect(Token::RPAREN, CHECK_OK_VALUE(kPreParseSuccess)); |
117 int formals_end_position = scanner()->location().end_pos; | 118 int formals_end_position = scanner()->location().end_pos; |
118 | 119 |
119 CheckArityRestrictions( | 120 CheckArityRestrictions(formals->arity, kind, formals->has_rest, |
120 formals.arity, kind, formals.has_rest, function_scope->start_position(), | 121 function_scope->start_position(), |
121 formals_end_position, CHECK_OK_VALUE(kPreParseSuccess)); | 122 formals_end_position, |
| 123 CHECK_OK_VALUE(kPreParseSuccess)); |
122 has_duplicate_parameters = | 124 has_duplicate_parameters = |
123 !classifier()->is_valid_formal_parameter_list_without_duplicates(); | 125 !classifier()->is_valid_formal_parameter_list_without_duplicates(); |
124 } | 126 } |
125 | 127 |
126 Expect(Token::LBRACE, CHECK_OK_VALUE(kPreParseSuccess)); | 128 Expect(Token::LBRACE, CHECK_OK_VALUE(kPreParseSuccess)); |
127 LazyParsingResult result = ParseStatementListAndLogFunction( | 129 LazyParsingResult result = ParseStatementListAndLogFunction( |
128 &formals, has_duplicate_parameters, may_abort, ok); | 130 formals, has_duplicate_parameters, may_abort, ok); |
129 use_counts_ = nullptr; | 131 use_counts_ = nullptr; |
130 track_unresolved_variables_ = false; | 132 track_unresolved_variables_ = false; |
131 if (result == kLazyParsingAborted) { | 133 if (result == kLazyParsingAborted) { |
132 return kPreParseAbort; | 134 return kPreParseAbort; |
133 } else if (stack_overflow()) { | 135 } else if (stack_overflow()) { |
134 return kPreParseStackOverflow; | 136 return kPreParseStackOverflow; |
135 } else if (!*ok) { | 137 } else if (!*ok) { |
136 DCHECK(pending_error_handler_->has_pending_error()); | 138 DCHECK(pending_error_handler_->has_pending_error()); |
137 } else { | 139 } else { |
138 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 140 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
139 | 141 |
140 if (!IsArrowFunction(kind)) { | 142 if (!IsArrowFunction(kind)) { |
141 // Validate parameter names. We can do this only after parsing the | 143 // Validate parameter names. We can do this only after parsing the |
142 // function, since the function can declare itself strict. | 144 // function, since the function can declare itself strict. |
143 const bool allow_duplicate_parameters = | 145 const bool allow_duplicate_parameters = |
144 is_sloppy(function_scope->language_mode()) && formals.is_simple && | 146 is_sloppy(function_scope->language_mode()) && formals->is_simple && |
145 !IsConciseMethod(kind); | 147 !IsConciseMethod(kind); |
146 ValidateFormalParameters(function_scope->language_mode(), | 148 ValidateFormalParameters(function_scope->language_mode(), |
147 allow_duplicate_parameters, | 149 allow_duplicate_parameters, |
148 CHECK_OK_VALUE(kPreParseSuccess)); | 150 CHECK_OK_VALUE(kPreParseSuccess)); |
149 } | 151 } |
150 | 152 |
151 if (is_strict(function_scope->language_mode())) { | 153 if (is_strict(function_scope->language_mode())) { |
152 int end_pos = scanner()->location().end_pos; | 154 int end_pos = scanner()->location().end_pos; |
153 CheckStrictOctalLiteral(function_scope->start_position(), end_pos, ok); | 155 CheckStrictOctalLiteral(function_scope->start_position(), end_pos, ok); |
154 CheckDecimalLiteralWithLeadingZero(function_scope->start_position(), | 156 CheckDecimalLiteralWithLeadingZero(function_scope->start_position(), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 PreParserStatementList body; | 194 PreParserStatementList body; |
193 DeclarationScope* function_scope = NewFunctionScope(kind); | 195 DeclarationScope* function_scope = NewFunctionScope(kind); |
194 function_scope->SetLanguageMode(language_mode); | 196 function_scope->SetLanguageMode(language_mode); |
195 FunctionState function_state(&function_state_, &scope_state_, function_scope); | 197 FunctionState function_state(&function_state_, &scope_state_, function_scope); |
196 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 198 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
197 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 199 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
198 | 200 |
199 Expect(Token::LPAREN, CHECK_OK); | 201 Expect(Token::LPAREN, CHECK_OK); |
200 int start_position = scanner()->location().beg_pos; | 202 int start_position = scanner()->location().beg_pos; |
201 function_scope->set_start_position(start_position); | 203 function_scope->set_start_position(start_position); |
202 PreParserFormalParameters formals(function_scope); | 204 PreParserFormalParameters* formals = |
203 ParseFormalParameterList(&formals, CHECK_OK); | 205 new (zone()) PreParserFormalParameters(function_scope); |
| 206 ParseFormalParameterList(formals, CHECK_OK); |
204 Expect(Token::RPAREN, CHECK_OK); | 207 Expect(Token::RPAREN, CHECK_OK); |
205 int formals_end_position = scanner()->location().end_pos; | 208 int formals_end_position = scanner()->location().end_pos; |
206 | 209 |
207 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, | 210 CheckArityRestrictions(formals->arity, kind, formals->has_rest, |
208 formals_end_position, CHECK_OK); | 211 start_position, formals_end_position, CHECK_OK); |
209 | 212 |
210 Expect(Token::LBRACE, CHECK_OK); | 213 Expect(Token::LBRACE, CHECK_OK); |
211 ParseStatementList(body, Token::RBRACE, CHECK_OK); | 214 ParseStatementList(body, Token::RBRACE, CHECK_OK); |
212 Expect(Token::RBRACE, CHECK_OK); | 215 Expect(Token::RBRACE, CHECK_OK); |
213 | 216 |
214 // Parsing the body may change the language mode in our scope. | 217 // Parsing the body may change the language mode in our scope. |
215 language_mode = function_scope->language_mode(); | 218 language_mode = function_scope->language_mode(); |
216 | 219 |
217 // Validate name and parameter names. We can do this only after parsing the | 220 // Validate name and parameter names. We can do this only after parsing the |
218 // function, since the function can declare itself strict. | 221 // function, since the function can declare itself strict. |
219 CheckFunctionName(language_mode, function_name, function_name_validity, | 222 CheckFunctionName(language_mode, function_name, function_name_validity, |
220 function_name_location, CHECK_OK); | 223 function_name_location, CHECK_OK); |
221 const bool allow_duplicate_parameters = | 224 const bool allow_duplicate_parameters = |
222 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); | 225 is_sloppy(language_mode) && formals->is_simple && !IsConciseMethod(kind); |
223 ValidateFormalParameters(language_mode, allow_duplicate_parameters, CHECK_OK); | 226 ValidateFormalParameters(language_mode, allow_duplicate_parameters, CHECK_OK); |
224 | 227 |
225 int end_position = scanner()->location().end_pos; | 228 int end_position = scanner()->location().end_pos; |
226 if (is_strict(language_mode)) { | 229 if (is_strict(language_mode)) { |
227 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 230 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
228 CheckDecimalLiteralWithLeadingZero(start_position, end_position); | 231 CheckDecimalLiteralWithLeadingZero(start_position, end_position); |
229 } | 232 } |
230 function_scope->set_end_position(end_position); | 233 function_scope->set_end_position(end_position); |
231 | 234 |
232 if (FLAG_trace_preparse) { | 235 if (FLAG_trace_preparse) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 303 } |
301 } | 304 } |
302 } | 305 } |
303 | 306 |
304 #undef CHECK_OK | 307 #undef CHECK_OK |
305 #undef CHECK_OK_CUSTOM | 308 #undef CHECK_OK_CUSTOM |
306 | 309 |
307 | 310 |
308 } // namespace internal | 311 } // namespace internal |
309 } // namespace v8 | 312 } // namespace v8 |
OLD | NEW |