| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 84 } |
| 85 | 85 |
| 86 PreParser::PreParseResult PreParser::PreParseFunction( | 86 PreParser::PreParseResult PreParser::PreParseFunction( |
| 87 FunctionKind kind, DeclarationScope* function_scope, bool parsing_module, | 87 FunctionKind kind, DeclarationScope* function_scope, bool parsing_module, |
| 88 bool is_inner_function, bool may_abort, int* use_counts) { | 88 bool is_inner_function, bool may_abort, int* use_counts) { |
| 89 DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type()); | 89 DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type()); |
| 90 parsing_module_ = parsing_module; | 90 parsing_module_ = parsing_module; |
| 91 use_counts_ = use_counts; | 91 use_counts_ = use_counts; |
| 92 DCHECK(!track_unresolved_variables_); | 92 DCHECK(!track_unresolved_variables_); |
| 93 track_unresolved_variables_ = is_inner_function; | 93 track_unresolved_variables_ = is_inner_function; |
| 94 #ifdef DEBUG |
| 95 function_scope->set_is_being_lazily_parsed(true); |
| 96 #endif |
| 94 | 97 |
| 95 // In the preparser, we use the function literal ids to count how many | 98 // In the preparser, we use the function literal ids to count how many |
| 96 // FunctionLiterals were encountered. The PreParser doesn't actually persist | 99 // FunctionLiterals were encountered. The PreParser doesn't actually persist |
| 97 // FunctionLiterals, so there IDs don't matter. | 100 // FunctionLiterals, so there IDs don't matter. |
| 98 ResetFunctionLiteralId(); | 101 ResetFunctionLiteralId(); |
| 99 | 102 |
| 100 // The caller passes the function_scope which is not yet inserted into the | 103 // The caller passes the function_scope which is not yet inserted into the |
| 101 // scope_state_. All scopes above the function_scope are ignored by the | 104 // scope_state_. All scopes above the function_scope are ignored by the |
| 102 // PreParser. | 105 // PreParser. |
| 103 DCHECK_NULL(scope_state_); | 106 DCHECK_NULL(scope_state_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 126 formals_end_position, CHECK_OK_VALUE(kPreParseSuccess)); | 129 formals_end_position, CHECK_OK_VALUE(kPreParseSuccess)); |
| 127 has_duplicate_parameters = | 130 has_duplicate_parameters = |
| 128 !classifier()->is_valid_formal_parameter_list_without_duplicates(); | 131 !classifier()->is_valid_formal_parameter_list_without_duplicates(); |
| 129 } | 132 } |
| 130 | 133 |
| 131 Expect(Token::LBRACE, CHECK_OK_VALUE(kPreParseSuccess)); | 134 Expect(Token::LBRACE, CHECK_OK_VALUE(kPreParseSuccess)); |
| 132 LazyParsingResult result = ParseStatementListAndLogFunction( | 135 LazyParsingResult result = ParseStatementListAndLogFunction( |
| 133 &formals, has_duplicate_parameters, may_abort, ok); | 136 &formals, has_duplicate_parameters, may_abort, ok); |
| 134 use_counts_ = nullptr; | 137 use_counts_ = nullptr; |
| 135 track_unresolved_variables_ = false; | 138 track_unresolved_variables_ = false; |
| 139 |
| 136 if (result == kLazyParsingAborted) { | 140 if (result == kLazyParsingAborted) { |
| 137 return kPreParseAbort; | 141 return kPreParseAbort; |
| 138 } else if (stack_overflow()) { | 142 } else if (stack_overflow()) { |
| 139 return kPreParseStackOverflow; | 143 return kPreParseStackOverflow; |
| 140 } else if (!*ok) { | 144 } else if (!*ok) { |
| 141 DCHECK(pending_error_handler_->has_pending_error()); | 145 DCHECK(pending_error_handler_->has_pending_error()); |
| 142 } else { | 146 } else { |
| 143 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 147 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| 144 | 148 |
| 145 if (!IsArrowFunction(kind)) { | 149 if (!IsArrowFunction(kind)) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 if (declaration->pattern.identifiers_ != nullptr) { | 293 if (declaration->pattern.identifiers_ != nullptr) { |
| 290 DCHECK(FLAG_lazy_inner_functions); | 294 DCHECK(FLAG_lazy_inner_functions); |
| 291 /* Mimic what Parser does when declaring variables (see | 295 /* Mimic what Parser does when declaring variables (see |
| 292 Parser::PatternRewriter::VisitVariableProxy). | 296 Parser::PatternRewriter::VisitVariableProxy). |
| 293 | 297 |
| 294 var + no initializer -> RemoveUnresolved | 298 var + no initializer -> RemoveUnresolved |
| 295 let / const + no initializer -> RemoveUnresolved | 299 let / const + no initializer -> RemoveUnresolved |
| 296 var + initializer -> RemoveUnresolved followed by NewUnresolved | 300 var + initializer -> RemoveUnresolved followed by NewUnresolved |
| 297 let / const + initializer -> RemoveUnresolved | 301 let / const + initializer -> RemoveUnresolved |
| 298 */ | 302 */ |
| 299 | 303 Scope* scope = declaration_descriptor->hoist_scope; |
| 304 if (scope == nullptr) { |
| 305 scope = this->scope(); |
| 306 } |
| 300 if (declaration->initializer.IsEmpty() || | 307 if (declaration->initializer.IsEmpty() || |
| 301 (declaration_descriptor->mode == VariableMode::LET || | 308 (declaration_descriptor->mode == VariableMode::LET || |
| 302 declaration_descriptor->mode == VariableMode::CONST)) { | 309 declaration_descriptor->mode == VariableMode::CONST)) { |
| 303 for (auto identifier : *(declaration->pattern.identifiers_)) { | 310 for (auto identifier : *(declaration->pattern.identifiers_)) { |
| 304 declaration_descriptor->scope->RemoveUnresolved(identifier); | 311 declaration_descriptor->scope->RemoveUnresolved(identifier); |
| 305 } | 312 } |
| 306 } | 313 } |
| 314 for (auto identifier : *(declaration->pattern.identifiers_)) { |
| 315 scope->DeclareVariableName(identifier, declaration_descriptor->mode); |
| 316 } |
| 307 } | 317 } |
| 308 } | 318 } |
| 309 | 319 |
| 310 #undef CHECK_OK | 320 #undef CHECK_OK |
| 311 #undef CHECK_OK_CUSTOM | 321 #undef CHECK_OK_CUSTOM |
| 312 | 322 |
| 313 | 323 |
| 314 } // namespace internal | 324 } // namespace internal |
| 315 } // namespace v8 | 325 } // namespace v8 |
| OLD | NEW |