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

Side by Side Diff: src/parser.h

Issue 1259283002: [es6] Implement proper TDZ for parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 months 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 | « no previous file | src/parser.cc » ('j') | src/parser.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 }; 549 };
550 550
551 explicit ParserFormalParameters(Scope* scope) 551 explicit ParserFormalParameters(Scope* scope)
552 : PreParserFormalParameters(scope), params(4, scope->zone()) {} 552 : PreParserFormalParameters(scope), params(4, scope->zone()) {}
553 553
554 ZoneList<Parameter> params; 554 ZoneList<Parameter> params;
555 555
556 void AddParameter( 556 void AddParameter(
557 const AstRawString* name, Expression* pattern, bool is_rest) { 557 const AstRawString* name, Expression* pattern, bool is_rest) {
558 params.Add(Parameter(name, pattern, is_rest), scope->zone()); 558 params.Add(Parameter(name, pattern, is_rest), scope->zone());
559 DCHECK(arity == params.length()); 559 DCHECK(arity == params.length());
adamk 2015/08/03 18:43:51 This code could be responsible for keeping arity i
560 } 560 }
561
562 const Parameter& at(int i) { return params[i]; }
561 }; 563 };
562 564
563 565
564 class ParserTraits { 566 class ParserTraits {
565 public: 567 public:
566 struct Type { 568 struct Type {
567 // TODO(marja): To be removed. The Traits object should contain all the data 569 // TODO(marja): To be removed. The Traits object should contain all the data
568 // it needs. 570 // it needs.
569 typedef v8::internal::Parser* Parser; 571 typedef v8::internal::Parser* Parser;
570 572
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); 777 return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
776 } 778 }
777 779
778 V8_INLINE void AddParameterInitializationBlock( 780 V8_INLINE void AddParameterInitializationBlock(
779 const ParserFormalParameters& parameters, 781 const ParserFormalParameters& parameters,
780 ZoneList<v8::internal::Statement*>* body, bool* ok); 782 ZoneList<v8::internal::Statement*>* body, bool* ok);
781 783
782 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, 784 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type,
783 FunctionKind kind = kNormalFunction); 785 FunctionKind kind = kNormalFunction);
784 786
787 V8_INLINE void AddFormalParameter(
788 ParserFormalParameters* parameters, Expression* pattern, bool is_rest);
785 V8_INLINE void DeclareFormalParameter( 789 V8_INLINE void DeclareFormalParameter(
786 ParserFormalParameters* parameters, Expression* pattern, bool is_rest, 790 Scope* scope, const ParserFormalParameters::Parameter& parameter,
787 ExpressionClassifier* classifier); 791 bool is_simple, ExpressionClassifier* classifier);
788 void ParseArrowFunctionFormalParameters( 792 void ParseArrowFunctionFormalParameters(
789 ParserFormalParameters* parameters, Expression* params, 793 ParserFormalParameters* parameters, Expression* params,
790 const Scanner::Location& params_loc, 794 const Scanner::Location& params_loc,
791 Scanner::Location* duplicate_loc, bool* ok); 795 Scanner::Location* duplicate_loc, bool* ok);
796 void ParseArrowFunctionFormalParameterList(
797 ParserFormalParameters* parameters, Expression* params,
798 const Scanner::Location& params_loc,
799 Scanner::Location* duplicate_loc, bool* ok);
792 800
793 void ReindexLiterals(const ParserFormalParameters& parameters); 801 void ReindexLiterals(const ParserFormalParameters& parameters);
794 802
795 // Temporary glue; these functions will move to ParserBase. 803 // Temporary glue; these functions will move to ParserBase.
796 Expression* ParseV8Intrinsic(bool* ok); 804 Expression* ParseV8Intrinsic(bool* ok);
797 FunctionLiteral* ParseFunctionLiteral( 805 FunctionLiteral* ParseFunctionLiteral(
798 const AstRawString* name, Scanner::Location function_name_location, 806 const AstRawString* name, Scanner::Location function_name_location,
799 FunctionNameValidity function_name_validity, FunctionKind kind, 807 FunctionNameValidity function_name_validity, FunctionKind kind,
800 int function_token_position, FunctionLiteral::FunctionType type, 808 int function_token_position, FunctionLiteral::FunctionType type,
801 FunctionLiteral::ArityRestriction arity_restriction, 809 FunctionLiteral::ArityRestriction arity_restriction,
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 return parser_->SpreadCall(function, args, pos); 1312 return parser_->SpreadCall(function, args, pos);
1305 } 1313 }
1306 1314
1307 1315
1308 Expression* ParserTraits::SpreadCallNew( 1316 Expression* ParserTraits::SpreadCallNew(
1309 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { 1317 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) {
1310 return parser_->SpreadCallNew(function, args, pos); 1318 return parser_->SpreadCallNew(function, args, pos);
1311 } 1319 }
1312 1320
1313 1321
1322 void ParserTraits::AddFormalParameter(
1323 ParserFormalParameters* parameters, Expression* pattern, bool is_rest) {
1324 bool is_simple = pattern->IsVariableProxy();
1325 DCHECK(parser_->allow_harmony_destructuring() ||
1326 parser_->allow_harmony_rest_parameters() || is_simple);
1327 const AstRawString* name = is_simple
1328 ? pattern->AsVariableProxy()->raw_name()
1329 : parser_->ast_value_factory()->empty_string();
1330 parameters->AddParameter(name, pattern, is_rest);
1331 DCHECK(parameters->arity == parameters->params.length());
adamk 2015/08/03 18:43:52 Nit: DCHECK_EQ
rossberg 2015/08/04 15:31:19 Done.
1332 }
1333
1334
1314 void ParserTraits::DeclareFormalParameter( 1335 void ParserTraits::DeclareFormalParameter(
1315 ParserFormalParameters* parameters, Expression* pattern, bool is_rest, 1336 Scope* scope, const ParserFormalParameters::Parameter& parameter,
1316 ExpressionClassifier* classifier) { 1337 bool is_simple, ExpressionClassifier* classifier) {
1317 bool is_duplicate = false; 1338 bool is_duplicate = false;
1318 bool is_simple = pattern->IsVariableProxy(); 1339 Variable* var = scope->DeclareParameter(
1319 DCHECK(parser_->allow_harmony_destructuring() || is_simple); 1340 // TODO(caitp): Remove special handling for rest once desugaring is in.
1320 1341 is_simple || parameter.is_rest
1321 const AstRawString* name = is_simple 1342 ? parameter.name : parser_->ast_value_factory()->empty_string(),
1322 ? pattern->AsVariableProxy()->raw_name() 1343 VAR, parameter.is_rest, &is_duplicate);
1323 : parser_->ast_value_factory()->empty_string();
1324 Variable* var =
1325 parameters->scope->DeclareParameter(name, VAR, is_rest, &is_duplicate);
1326 parameters->AddParameter(name, is_simple ? nullptr : pattern, is_rest);
1327 if (is_duplicate) { 1344 if (is_duplicate) {
1328 classifier->RecordDuplicateFormalParameterError( 1345 classifier->RecordDuplicateFormalParameterError(
1329 parser_->scanner()->location()); 1346 parser_->scanner()->location());
1330 } 1347 }
1331 if (is_sloppy(parameters->scope->language_mode())) { 1348 if (is_sloppy(scope->language_mode())) {
1332 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 1349 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
1333 // conservative approximation necessary to account for parameters 1350 // conservative approximation necessary to account for parameters
1334 // that are assigned via the arguments array. 1351 // that are assigned via the arguments array.
1335 var->set_maybe_assigned(); 1352 var->set_maybe_assigned();
1336 } 1353 }
1337 } 1354 }
1338 1355
1339 1356
1340 void ParserTraits::AddParameterInitializationBlock( 1357 void ParserTraits::AddParameterInitializationBlock(
1341 const ParserFormalParameters& parameters, 1358 const ParserFormalParameters& parameters,
1342 ZoneList<v8::internal::Statement*>* body, bool* ok) { 1359 ZoneList<v8::internal::Statement*>* body, bool* ok) {
1343 if (!parameters.is_simple) { 1360 if (!parameters.is_simple) {
1344 auto* init_block = 1361 auto* init_block =
1345 parser_->BuildParameterInitializationBlock(parameters, ok); 1362 parser_->BuildParameterInitializationBlock(parameters, ok);
1346 if (!*ok) return; 1363 if (!*ok) return;
1347 if (init_block != nullptr) { 1364 if (init_block != nullptr) {
1348 body->Add(init_block, parser_->zone()); 1365 body->Add(init_block, parser_->zone());
1349 } 1366 }
1350 } 1367 }
1351 } 1368 }
1352 } } // namespace v8::internal 1369 } } // namespace v8::internal
1353 1370
1354 #endif // V8_PARSER_H_ 1371 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | src/parser.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698