Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/parsing/preparser.cc

Issue 2539123002: Preparsing inner funcs: be less pessimistic about maybe_assigned. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 DCHECK(this->scope()->is_function_scope()); 259 DCHECK(this->scope()->is_function_scope());
260 log_.LogFunction( 260 log_.LogFunction(
261 body_end, formals->num_parameters(), formals->function_length, 261 body_end, formals->num_parameters(), formals->function_length,
262 has_duplicate_parameters, function_state_->materialized_literal_count(), 262 has_duplicate_parameters, function_state_->materialized_literal_count(),
263 function_state_->expected_property_count(), GetLastFunctionLiteralId()); 263 function_state_->expected_property_count(), GetLastFunctionLiteralId());
264 return kLazyParsingComplete; 264 return kLazyParsingComplete;
265 } 265 }
266 266
267 PreParserExpression PreParser::ExpressionFromIdentifier( 267 PreParserExpression PreParser::ExpressionFromIdentifier(
268 PreParserIdentifier name, int start_position, InferName infer) { 268 PreParserIdentifier name, int start_position, InferName infer) {
269 VariableProxy* proxy = nullptr;
269 if (track_unresolved_variables_) { 270 if (track_unresolved_variables_) {
270 AstNodeFactory factory(ast_value_factory()); 271 AstNodeFactory factory(ast_value_factory());
271 // Setting the Zone is necessary because zone_ might be the temp Zone, and 272 // Setting the Zone is necessary because zone_ might be the temp Zone, and
272 // AstValueFactory doesn't know about it. 273 // AstValueFactory doesn't know about it.
273 factory.set_zone(zone()); 274 factory.set_zone(zone());
274 DCHECK_NOT_NULL(name.string_); 275 DCHECK_NOT_NULL(name.string_);
275 VariableProxy* proxy = scope()->NewUnresolved( 276 proxy = scope()->NewUnresolved(&factory, name.string_, start_position,
276 &factory, name.string_, start_position, NORMAL_VARIABLE); 277 NORMAL_VARIABLE);
277 // We don't know whether the preparsed function assigns or not, so we set
278 // is_assigned pessimistically.
279 proxy->set_is_assigned();
280 } 278 }
281 return PreParserExpression::FromIdentifier(name, zone()); 279 return PreParserExpression::FromIdentifier(name, proxy, zone());
282 } 280 }
283 281
284 void PreParser::DeclareAndInitializeVariables( 282 void PreParser::DeclareAndInitializeVariables(
285 PreParserStatement block, 283 PreParserStatement block,
286 const DeclarationDescriptor* declaration_descriptor, 284 const DeclarationDescriptor* declaration_descriptor,
287 const DeclarationParsingResult::Declaration* declaration, 285 const DeclarationParsingResult::Declaration* declaration,
288 ZoneList<const AstRawString*>* names, bool* ok) { 286 ZoneList<const AstRawString*>* names, bool* ok) {
289 if (declaration->pattern.identifiers_ != nullptr) { 287 if (declaration->pattern.variables_ != nullptr) {
290 DCHECK(FLAG_lazy_inner_functions); 288 DCHECK(FLAG_lazy_inner_functions);
291 /* Mimic what Parser does when declaring variables (see 289 /* Mimic what Parser does when declaring variables (see
292 Parser::PatternRewriter::VisitVariableProxy). 290 Parser::PatternRewriter::VisitVariableProxy).
293 291
294 var + no initializer -> RemoveUnresolved 292 var + no initializer -> RemoveUnresolved
295 let / const + no initializer -> RemoveUnresolved 293 let / const + no initializer -> RemoveUnresolved
296 var + initializer -> RemoveUnresolved followed by NewUnresolved 294 var + initializer -> RemoveUnresolved followed by NewUnresolved
297 let / const + initializer -> RemoveUnresolved 295 let / const + initializer -> RemoveUnresolved
298 */ 296 */
299 Scope* scope = declaration_descriptor->hoist_scope; 297 Scope* scope = declaration_descriptor->hoist_scope;
300 if (scope == nullptr) { 298 if (scope == nullptr) {
301 scope = this->scope(); 299 scope = this->scope();
302 } 300 }
303 if (declaration->initializer.IsEmpty() || 301 if (declaration->initializer.IsEmpty() ||
304 (declaration_descriptor->mode == VariableMode::LET || 302 (declaration_descriptor->mode == VariableMode::LET ||
305 declaration_descriptor->mode == VariableMode::CONST)) { 303 declaration_descriptor->mode == VariableMode::CONST)) {
306 for (auto identifier : *(declaration->pattern.identifiers_)) { 304 for (auto variable : *(declaration->pattern.variables_)) {
307 declaration_descriptor->scope->RemoveUnresolved(identifier); 305 declaration_descriptor->scope->RemoveUnresolved(variable);
308 } 306 }
309 } 307 }
310 for (auto identifier : *(declaration->pattern.identifiers_)) { 308 for (auto variable : *(declaration->pattern.variables_)) {
311 scope->DeclareVariableName(identifier, declaration_descriptor->mode); 309 scope->DeclareVariableName(variable->raw_name(),
310 declaration_descriptor->mode);
312 } 311 }
313 } 312 }
314 } 313 }
315 314
316 #undef CHECK_OK 315 #undef CHECK_OK
317 #undef CHECK_OK_CUSTOM 316 #undef CHECK_OK_CUSTOM
318 317
319 318
320 } // namespace internal 319 } // namespace internal
321 } // namespace v8 320 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698