OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_PARSER_H_ | 5 #ifndef V8_PARSER_H_ |
6 #define V8_PARSER_H_ | 6 #define V8_PARSER_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/compiler.h" // TODO(titzer): remove this include dependency | 10 #include "src/compiler.h" // TODO(titzer): remove this include dependency |
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 void ParserTraits::DeclareFormalParameter( | 1311 void ParserTraits::DeclareFormalParameter( |
1312 ParserFormalParameters* parameters, Expression* pattern, bool is_rest, | 1312 ParserFormalParameters* parameters, Expression* pattern, bool is_rest, |
1313 ExpressionClassifier* classifier) { | 1313 ExpressionClassifier* classifier) { |
1314 bool is_duplicate = false; | 1314 bool is_duplicate = false; |
1315 bool is_simple = pattern->IsVariableProxy(); | 1315 bool is_simple = pattern->IsVariableProxy(); |
1316 DCHECK(parser_->allow_harmony_destructuring() || is_simple); | 1316 DCHECK(parser_->allow_harmony_destructuring() || is_simple); |
1317 | 1317 |
1318 const AstRawString* name = is_simple | 1318 const AstRawString* name = is_simple |
1319 ? pattern->AsVariableProxy()->raw_name() | 1319 ? pattern->AsVariableProxy()->raw_name() |
1320 : parser_->ast_value_factory()->empty_string(); | 1320 : parser_->ast_value_factory()->empty_string(); |
| 1321 VariableMode mode = is_simple ? VAR : TEMPORARY; |
1321 Variable* var = | 1322 Variable* var = |
1322 parameters->scope->DeclareParameter(name, VAR, is_rest, &is_duplicate); | 1323 parameters->scope->DeclareParameter(name, mode, is_rest, &is_duplicate); |
1323 parameters->AddParameter(var, is_simple ? nullptr : pattern); | 1324 parameters->AddParameter(var, is_simple ? nullptr : pattern); |
1324 if (is_duplicate) { | 1325 if (is_duplicate) { |
1325 classifier->RecordDuplicateFormalParameterError( | 1326 classifier->RecordDuplicateFormalParameterError( |
1326 parser_->scanner()->location()); | 1327 parser_->scanner()->location()); |
1327 } | 1328 } |
1328 if (is_sloppy(parameters->scope->language_mode())) { | 1329 if (is_sloppy(parameters->scope->language_mode())) { |
1329 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 1330 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
1330 // conservative approximation necessary to account for parameters | 1331 // conservative approximation necessary to account for parameters |
1331 // that are assigned via the arguments array. | 1332 // that are assigned via the arguments array. |
1332 var->set_maybe_assigned(); | 1333 var->set_maybe_assigned(); |
1333 } | 1334 } |
1334 } | 1335 } |
1335 | 1336 |
1336 | 1337 |
1337 void ParserTraits::AddParameterInitializationBlock( | 1338 void ParserTraits::AddParameterInitializationBlock( |
1338 const ParserFormalParameters& parameters, | 1339 const ParserFormalParameters& parameters, |
1339 ZoneList<v8::internal::Statement*>* body, bool* ok) { | 1340 ZoneList<v8::internal::Statement*>* body, bool* ok) { |
1340 if (!parameters.is_simple) { | 1341 if (!parameters.is_simple) { |
1341 auto* init_block = | 1342 auto* init_block = |
1342 parser_->BuildParameterInitializationBlock(parameters, ok); | 1343 parser_->BuildParameterInitializationBlock(parameters, ok); |
1343 if (!*ok) return; | 1344 if (!*ok) return; |
1344 if (init_block != nullptr) { | 1345 if (init_block != nullptr) { |
1345 body->Add(init_block, parser_->zone()); | 1346 body->Add(init_block, parser_->zone()); |
1346 } | 1347 } |
1347 } | 1348 } |
1348 } | 1349 } |
1349 } } // namespace v8::internal | 1350 } } // namespace v8::internal |
1350 | 1351 |
1351 #endif // V8_PARSER_H_ | 1352 #endif // V8_PARSER_H_ |
OLD | NEW |