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 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 Expression* GetIterator(Expression* iterable, AstNodeFactory* factory); | 744 Expression* GetIterator(Expression* iterable, AstNodeFactory* factory); |
745 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { | 745 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { |
746 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | 746 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
747 } | 747 } |
748 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 748 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
749 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 749 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
750 } | 750 } |
751 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { | 751 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { |
752 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | 752 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
753 } | 753 } |
| 754 |
| 755 V8_INLINE void AddParameterInitializationBlock( |
| 756 ZoneList<v8::internal::Statement*>* body, bool* ok); |
| 757 |
754 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, | 758 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, |
755 FunctionKind kind = kNormalFunction); | 759 FunctionKind kind = kNormalFunction); |
756 | 760 |
757 V8_INLINE void DeclareFormalParameter(Scope* scope, Expression* name, | 761 V8_INLINE void DeclareFormalParameter(Scope* scope, Expression* name, |
758 ExpressionClassifier* classifier, | 762 ExpressionClassifier* classifier, |
759 bool is_rest); | 763 bool is_rest); |
760 void ParseArrowFunctionFormalParameters(Scope* scope, Expression* params, | 764 void ParseArrowFunctionFormalParameters(Scope* scope, Expression* params, |
761 const Scanner::Location& params_loc, | 765 const Scanner::Location& params_loc, |
762 bool* has_rest, | 766 bool* has_rest, |
763 Scanner::Location* duplicate_loc, | 767 Scanner::Location* duplicate_loc, |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 // If bookmark is set, the (pre-)parser may decide to abort skipping | 1118 // If bookmark is set, the (pre-)parser may decide to abort skipping |
1115 // in order to force the function to be eagerly parsed, after all. | 1119 // in order to force the function to be eagerly parsed, after all. |
1116 // In this case, it'll reset the scanner using the bookmark. | 1120 // In this case, it'll reset the scanner using the bookmark. |
1117 void SkipLazyFunctionBody(int* materialized_literal_count, | 1121 void SkipLazyFunctionBody(int* materialized_literal_count, |
1118 int* expected_property_count, bool* ok, | 1122 int* expected_property_count, bool* ok, |
1119 Scanner::BookmarkScope* bookmark = nullptr); | 1123 Scanner::BookmarkScope* bookmark = nullptr); |
1120 | 1124 |
1121 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser( | 1125 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser( |
1122 SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr); | 1126 SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr); |
1123 | 1127 |
| 1128 Block* BuildParameterInitializationBlock(bool* ok); |
| 1129 |
1124 // Consumes the ending }. | 1130 // Consumes the ending }. |
1125 ZoneList<Statement*>* ParseEagerFunctionBody( | 1131 ZoneList<Statement*>* ParseEagerFunctionBody( |
1126 const AstRawString* function_name, int pos, Variable* fvar, | 1132 const AstRawString* function_name, int pos, Variable* fvar, |
1127 Token::Value fvar_init_op, FunctionKind kind, bool* ok); | 1133 Token::Value fvar_init_op, FunctionKind kind, bool* ok); |
1128 | 1134 |
1129 void ThrowPendingError(Isolate* isolate, Handle<Script> script); | 1135 void ThrowPendingError(Isolate* isolate, Handle<Script> script); |
1130 | 1136 |
1131 TemplateLiteralState OpenTemplateLiteral(int pos); | 1137 TemplateLiteralState OpenTemplateLiteral(int pos); |
1132 void AddTemplateSpan(TemplateLiteralState* state, bool tail); | 1138 void AddTemplateSpan(TemplateLiteralState* state, bool tail); |
1133 void AddTemplateExpression(TemplateLiteralState* state, | 1139 void AddTemplateExpression(TemplateLiteralState* state, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 Expression* ParserTraits::SpreadCallNew( | 1273 Expression* ParserTraits::SpreadCallNew( |
1268 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { | 1274 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { |
1269 return parser_->SpreadCallNew(function, args, pos); | 1275 return parser_->SpreadCallNew(function, args, pos); |
1270 } | 1276 } |
1271 | 1277 |
1272 | 1278 |
1273 void ParserTraits::DeclareFormalParameter(Scope* scope, Expression* pattern, | 1279 void ParserTraits::DeclareFormalParameter(Scope* scope, Expression* pattern, |
1274 ExpressionClassifier* classifier, | 1280 ExpressionClassifier* classifier, |
1275 bool is_rest) { | 1281 bool is_rest) { |
1276 bool is_duplicate = false; | 1282 bool is_duplicate = false; |
1277 if (!pattern->IsVariableProxy()) { | 1283 bool is_simple_name = pattern->IsVariableProxy(); |
1278 // TODO(dslomov): implement. | 1284 DCHECK(parser_->allow_harmony_destructuring() || is_simple_name); |
1279 DCHECK(parser_->allow_harmony_destructuring()); | 1285 |
1280 return; | 1286 const AstRawString* name = is_simple_name |
1281 } | 1287 ? pattern->AsVariableProxy()->raw_name() |
1282 auto name = pattern->AsVariableProxy()->raw_name(); | 1288 : parser_->ast_value_factory()->empty_string(); |
1283 Variable* var = scope->DeclareParameter(name, VAR, is_rest, &is_duplicate); | 1289 Variable* var = scope->DeclareParameter( |
| 1290 name, is_simple_name ? nullptr : pattern, VAR, is_rest, &is_duplicate); |
1284 if (is_sloppy(scope->language_mode())) { | 1291 if (is_sloppy(scope->language_mode())) { |
1285 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 1292 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
1286 // conservative approximation necessary to account for parameters | 1293 // conservative approximation necessary to account for parameters |
1287 // that are assigned via the arguments array. | 1294 // that are assigned via the arguments array. |
1288 var->set_maybe_assigned(); | 1295 var->set_maybe_assigned(); |
1289 } | 1296 } |
1290 if (is_duplicate) { | 1297 if (is_duplicate) { |
1291 classifier->RecordDuplicateFormalParameterError( | 1298 classifier->RecordDuplicateFormalParameterError( |
1292 parser_->scanner()->location()); | 1299 parser_->scanner()->location()); |
1293 } | 1300 } |
1294 } | 1301 } |
| 1302 |
| 1303 |
| 1304 void ParserTraits::AddParameterInitializationBlock( |
| 1305 ZoneList<v8::internal::Statement*>* body, bool* ok) { |
| 1306 auto* init_block = parser_->BuildParameterInitializationBlock(ok); |
| 1307 if (!*ok) return; |
| 1308 if (init_block != nullptr) { |
| 1309 body->Add(init_block, parser_->zone()); |
| 1310 } |
| 1311 } |
1295 } } // namespace v8::internal | 1312 } } // namespace v8::internal |
1296 | 1313 |
1297 #endif // V8_PARSER_H_ | 1314 #endif // V8_PARSER_H_ |
OLD | NEW |