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 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1313 | 1313 |
1314 Expression* ParserTraits::SpreadCallNew( | 1314 Expression* ParserTraits::SpreadCallNew( |
1315 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { | 1315 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { |
1316 return parser_->SpreadCallNew(function, args, pos); | 1316 return parser_->SpreadCallNew(function, args, pos); |
1317 } | 1317 } |
1318 | 1318 |
1319 | 1319 |
1320 void ParserTraits::AddFormalParameter( | 1320 void ParserTraits::AddFormalParameter( |
1321 ParserFormalParameters* parameters, | 1321 ParserFormalParameters* parameters, |
1322 Expression* pattern, Expression* initializer, bool is_rest) { | 1322 Expression* pattern, Expression* initializer, bool is_rest) { |
1323 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; | 1323 bool is_simple = |
1324 !is_rest && pattern->IsVariableProxy() && initializer == nullptr; | |
caitp (gmail)
2015/09/02 20:11:31
This makes sure the empty string is used instead o
rossberg
2015/09/02 20:44:10
Yes, this looks right to me.
| |
1324 DCHECK(parser_->allow_harmony_destructuring() || | 1325 DCHECK(parser_->allow_harmony_destructuring() || |
1325 parser_->allow_harmony_rest_parameters() || | 1326 parser_->allow_harmony_rest_parameters() || |
1326 parser_->allow_harmony_default_parameters() || is_simple); | 1327 parser_->allow_harmony_default_parameters() || is_simple); |
1327 const AstRawString* name = is_simple | 1328 const AstRawString* name = is_simple |
1328 ? pattern->AsVariableProxy()->raw_name() | 1329 ? pattern->AsVariableProxy()->raw_name() |
1329 : parser_->ast_value_factory()->empty_string(); | 1330 : parser_->ast_value_factory()->empty_string(); |
1330 parameters->params.Add( | 1331 parameters->params.Add( |
1331 ParserFormalParameters::Parameter(name, pattern, initializer, is_rest), | 1332 ParserFormalParameters::Parameter(name, pattern, initializer, is_rest), |
1332 parameters->scope->zone()); | 1333 parameters->scope->zone()); |
1333 } | 1334 } |
1334 | 1335 |
1335 | 1336 |
1336 void ParserTraits::DeclareFormalParameter( | 1337 void ParserTraits::DeclareFormalParameter( |
1337 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 1338 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
1338 ExpressionClassifier* classifier) { | 1339 ExpressionClassifier* classifier) { |
1339 bool is_duplicate = false; | 1340 bool is_duplicate = false; |
1340 bool is_simple = classifier->is_simple_parameter_list(); | 1341 bool is_simple = classifier->is_simple_parameter_list(); |
1341 // TODO(caitp): Remove special handling for rest once desugaring is in. | 1342 auto name = parameter.name; |
1342 auto name = is_simple || parameter.is_rest | 1343 auto mode = is_simple ? VAR : TEMPORARY; |
1343 ? parameter.name : parser_->ast_value_factory()->empty_string(); | |
1344 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; | |
1345 if (!is_simple) scope->SetHasNonSimpleParameters(); | 1344 if (!is_simple) scope->SetHasNonSimpleParameters(); |
1346 bool is_optional = parameter.initializer != nullptr; | 1345 bool is_optional = parameter.initializer != nullptr; |
1347 Variable* var = scope->DeclareParameter( | 1346 Variable* var = scope->DeclareParameter( |
1348 name, mode, is_optional, parameter.is_rest, &is_duplicate); | 1347 name, mode, is_optional, parameter.is_rest, &is_duplicate); |
1349 if (is_duplicate) { | 1348 if (is_duplicate) { |
1350 classifier->RecordDuplicateFormalParameterError( | 1349 classifier->RecordDuplicateFormalParameterError( |
1351 parser_->scanner()->location()); | 1350 parser_->scanner()->location()); |
1352 } | 1351 } |
1353 if (is_sloppy(scope->language_mode())) { | 1352 if (is_sloppy(scope->language_mode())) { |
1354 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 1353 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
(...skipping 12 matching lines...) Expand all Loading... | |
1367 parser_->BuildParameterInitializationBlock(parameters, ok); | 1366 parser_->BuildParameterInitializationBlock(parameters, ok); |
1368 if (!*ok) return; | 1367 if (!*ok) return; |
1369 if (init_block != nullptr) { | 1368 if (init_block != nullptr) { |
1370 body->Add(init_block, parser_->zone()); | 1369 body->Add(init_block, parser_->zone()); |
1371 } | 1370 } |
1372 } | 1371 } |
1373 } | 1372 } |
1374 } } // namespace v8::internal | 1373 } } // namespace v8::internal |
1375 | 1374 |
1376 #endif // V8_PARSER_H_ | 1375 #endif // V8_PARSER_H_ |
OLD | NEW |