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

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

Issue 2539123002: Preparsing inner funcs: be less pessimistic about maybe_assigned. (Closed)
Patch Set: moar 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
« no previous file with comments | « src/parsing/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 DCHECK(this->scope()->is_function_scope()); 262 DCHECK(this->scope()->is_function_scope());
263 log_.LogFunction( 263 log_.LogFunction(
264 body_end, formals->num_parameters(), formals->function_length, 264 body_end, formals->num_parameters(), formals->function_length,
265 has_duplicate_parameters, function_state_->materialized_literal_count(), 265 has_duplicate_parameters, function_state_->materialized_literal_count(),
266 function_state_->expected_property_count(), GetLastFunctionLiteralId()); 266 function_state_->expected_property_count(), GetLastFunctionLiteralId());
267 return kLazyParsingComplete; 267 return kLazyParsingComplete;
268 } 268 }
269 269
270 PreParserExpression PreParser::ExpressionFromIdentifier( 270 PreParserExpression PreParser::ExpressionFromIdentifier(
271 PreParserIdentifier name, int start_position, InferName infer) { 271 PreParserIdentifier name, int start_position, InferName infer) {
272 VariableProxy* proxy = nullptr;
272 if (track_unresolved_variables_) { 273 if (track_unresolved_variables_) {
273 AstNodeFactory factory(ast_value_factory()); 274 AstNodeFactory factory(ast_value_factory());
274 // Setting the Zone is necessary because zone_ might be the temp Zone, and 275 // Setting the Zone is necessary because zone_ might be the temp Zone, and
275 // AstValueFactory doesn't know about it. 276 // AstValueFactory doesn't know about it.
276 factory.set_zone(zone()); 277 factory.set_zone(zone());
277 DCHECK_NOT_NULL(name.string_); 278 DCHECK_NOT_NULL(name.string_);
278 VariableProxy* proxy = scope()->NewUnresolved( 279 proxy = scope()->NewUnresolved(&factory, name.string_, start_position,
279 &factory, name.string_, start_position, NORMAL_VARIABLE); 280 NORMAL_VARIABLE);
280 // We don't know whether the preparsed function assigns or not, so we set
281 // is_assigned pessimistically.
282 proxy->set_is_assigned();
283 } 281 }
284 return PreParserExpression::FromIdentifier(name, zone()); 282 return PreParserExpression::FromIdentifier(name, proxy, zone());
285 } 283 }
286 284
287 void PreParser::DeclareAndInitializeVariables( 285 void PreParser::DeclareAndInitializeVariables(
288 PreParserStatement block, 286 PreParserStatement block,
289 const DeclarationDescriptor* declaration_descriptor, 287 const DeclarationDescriptor* declaration_descriptor,
290 const DeclarationParsingResult::Declaration* declaration, 288 const DeclarationParsingResult::Declaration* declaration,
291 ZoneList<const AstRawString*>* names, bool* ok) { 289 ZoneList<const AstRawString*>* names, bool* ok) {
292 if (declaration->pattern.identifiers_ != nullptr) { 290 if (declaration->pattern.variables_ != nullptr) {
293 DCHECK(FLAG_lazy_inner_functions); 291 DCHECK(FLAG_lazy_inner_functions);
294 /* Mimic what Parser does when declaring variables (see 292 /* Mimic what Parser does when declaring variables (see
295 Parser::PatternRewriter::VisitVariableProxy). 293 Parser::PatternRewriter::VisitVariableProxy).
296 294
297 var + no initializer -> RemoveUnresolved 295 var + no initializer -> RemoveUnresolved
298 let / const + no initializer -> RemoveUnresolved 296 let / const + no initializer -> RemoveUnresolved
299 var + initializer -> RemoveUnresolved followed by NewUnresolved 297 var + initializer -> RemoveUnresolved followed by NewUnresolved
300 let / const + initializer -> RemoveUnresolved 298 let / const + initializer -> RemoveUnresolved
301 */ 299 */
302 Scope* scope = declaration_descriptor->hoist_scope; 300 Scope* scope = declaration_descriptor->hoist_scope;
303 if (scope == nullptr) { 301 if (scope == nullptr) {
304 scope = this->scope(); 302 scope = this->scope();
305 } 303 }
306 if (declaration->initializer.IsEmpty() || 304 if (declaration->initializer.IsEmpty() ||
307 (declaration_descriptor->mode == VariableMode::LET || 305 (declaration_descriptor->mode == VariableMode::LET ||
308 declaration_descriptor->mode == VariableMode::CONST)) { 306 declaration_descriptor->mode == VariableMode::CONST)) {
309 for (auto identifier : *(declaration->pattern.identifiers_)) { 307 for (auto variable : *(declaration->pattern.variables_)) {
310 declaration_descriptor->scope->RemoveUnresolved(identifier); 308 declaration_descriptor->scope->RemoveUnresolved(variable);
311 } 309 }
312 } 310 }
313 for (auto identifier : *(declaration->pattern.identifiers_)) { 311 for (auto variable : *(declaration->pattern.variables_)) {
314 scope->DeclareVariableName(identifier, declaration_descriptor->mode); 312 scope->DeclareVariableName(variable->raw_name(),
313 declaration_descriptor->mode);
315 } 314 }
316 } 315 }
317 } 316 }
318 317
319 #undef CHECK_OK 318 #undef CHECK_OK
320 #undef CHECK_OK_CUSTOM 319 #undef CHECK_OK_CUSTOM
321 320
322 321
323 } // namespace internal 322 } // namespace internal
324 } // namespace v8 323 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698