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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/ast-literal-reindexer.h" |
9 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 11 #include "src/base/platform/platform.h" |
11 #include "src/bootstrapper.h" | 12 #include "src/bootstrapper.h" |
12 #include "src/char-predicates-inl.h" | 13 #include "src/char-predicates-inl.h" |
13 #include "src/codegen.h" | 14 #include "src/codegen.h" |
14 #include "src/compiler.h" | 15 #include "src/compiler.h" |
15 #include "src/messages.h" | 16 #include "src/messages.h" |
16 #include "src/parser.h" | 17 #include "src/parser.h" |
17 #include "src/preparser.h" | 18 #include "src/preparser.h" |
18 #include "src/runtime/runtime.h" | 19 #include "src/runtime/runtime.h" |
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 : FunctionLiteral::NAMED_EXPRESSION) | 1174 : FunctionLiteral::NAMED_EXPRESSION) |
1174 : FunctionLiteral::DECLARATION; | 1175 : FunctionLiteral::DECLARATION; |
1175 bool ok = true; | 1176 bool ok = true; |
1176 | 1177 |
1177 if (shared_info->is_arrow()) { | 1178 if (shared_info->is_arrow()) { |
1178 Scope* scope = | 1179 Scope* scope = |
1179 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 1180 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
1180 scope->set_start_position(shared_info->start_position()); | 1181 scope->set_start_position(shared_info->start_position()); |
1181 ExpressionClassifier formals_classifier; | 1182 ExpressionClassifier formals_classifier; |
1182 ParserFormalParameterParsingState parsing_state(scope); | 1183 ParserFormalParameterParsingState parsing_state(scope); |
| 1184 Checkpoint checkpoint(this); |
1183 { | 1185 { |
1184 // Parsing patterns as variable reference expression creates | 1186 // Parsing patterns as variable reference expression creates |
1185 // NewUnresolved references in current scope. Entrer arrow function | 1187 // NewUnresolved references in current scope. Entrer arrow function |
1186 // scope for formal parameter parsing. | 1188 // scope for formal parameter parsing. |
1187 BlockState block_state(&scope_, scope); | 1189 BlockState block_state(&scope_, scope); |
1188 if (Check(Token::LPAREN)) { | 1190 if (Check(Token::LPAREN)) { |
1189 // '(' StrictFormalParameters ')' | 1191 // '(' StrictFormalParameters ')' |
1190 ParseFormalParameterList(&parsing_state, &formals_classifier, &ok); | 1192 ParseFormalParameterList(&parsing_state, &formals_classifier, &ok); |
1191 if (ok) ok = Check(Token::RPAREN); | 1193 if (ok) ok = Check(Token::RPAREN); |
1192 } else { | 1194 } else { |
1193 // BindingIdentifier | 1195 // BindingIdentifier |
1194 const bool is_rest = false; | 1196 const bool is_rest = false; |
1195 ParseFormalParameter(is_rest, &parsing_state, &formals_classifier, | 1197 ParseFormalParameter(is_rest, &parsing_state, &formals_classifier, |
1196 &ok); | 1198 &ok); |
1197 } | 1199 } |
1198 } | 1200 } |
1199 | 1201 |
1200 if (ok) { | 1202 if (ok) { |
| 1203 checkpoint.Restore(&parsing_state.materialized_literals_count); |
1201 Expression* expression = | 1204 Expression* expression = |
1202 ParseArrowFunctionLiteral(parsing_state, formals_classifier, &ok); | 1205 ParseArrowFunctionLiteral(parsing_state, formals_classifier, &ok); |
1203 if (ok) { | 1206 if (ok) { |
1204 // Scanning must end at the same position that was recorded | 1207 // Scanning must end at the same position that was recorded |
1205 // previously. If not, parsing has been interrupted due to a stack | 1208 // previously. If not, parsing has been interrupted due to a stack |
1206 // overflow, at which point the partially parsed arrow function | 1209 // overflow, at which point the partially parsed arrow function |
1207 // concise body happens to be a valid expression. This is a problem | 1210 // concise body happens to be a valid expression. This is a problem |
1208 // only for arrow functions with single expression bodies, since there | 1211 // only for arrow functions with single expression bodies, since there |
1209 // is no end token such as "}" for normal functions. | 1212 // is no end token such as "}" for normal functions. |
1210 if (scanner()->location().end_pos == shared_info->end_position()) { | 1213 if (scanner()->location().end_pos == shared_info->end_position()) { |
(...skipping 2636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3847 } | 3850 } |
3848 | 3851 |
3849 ExpressionClassifier classifier; | 3852 ExpressionClassifier classifier; |
3850 DeclareFormalParameter(parsing_state, expr, &classifier, is_rest); | 3853 DeclareFormalParameter(parsing_state, expr, &classifier, is_rest); |
3851 if (!duplicate_loc->IsValid()) { | 3854 if (!duplicate_loc->IsValid()) { |
3852 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; | 3855 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; |
3853 } | 3856 } |
3854 } | 3857 } |
3855 | 3858 |
3856 | 3859 |
| 3860 void ParserTraits::ReindexLiterals( |
| 3861 const ParserFormalParameterParsingState& parsing_state) { |
| 3862 if (parser_->function_state_->materialized_literal_count() > 0) { |
| 3863 AstLiteralReindexer reindexer; |
| 3864 |
| 3865 for (const auto p : parsing_state.params) { |
| 3866 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); |
| 3867 } |
| 3868 DCHECK(reindexer.count() <= |
| 3869 parser_->function_state_->materialized_literal_count()); |
| 3870 } |
| 3871 } |
| 3872 |
| 3873 |
3857 FunctionLiteral* Parser::ParseFunctionLiteral( | 3874 FunctionLiteral* Parser::ParseFunctionLiteral( |
3858 const AstRawString* function_name, Scanner::Location function_name_location, | 3875 const AstRawString* function_name, Scanner::Location function_name_location, |
3859 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 3876 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
3860 FunctionLiteral::FunctionType function_type, | 3877 FunctionLiteral::FunctionType function_type, |
3861 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 3878 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
3862 // Function :: | 3879 // Function :: |
3863 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 3880 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
3864 // | 3881 // |
3865 // Getter :: | 3882 // Getter :: |
3866 // '(' ')' '{' FunctionBody '}' | 3883 // '(' ')' '{' FunctionBody '}' |
(...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5894 Expression* Parser::SpreadCallNew(Expression* function, | 5911 Expression* Parser::SpreadCallNew(Expression* function, |
5895 ZoneList<v8::internal::Expression*>* args, | 5912 ZoneList<v8::internal::Expression*>* args, |
5896 int pos) { | 5913 int pos) { |
5897 args->InsertAt(0, function, zone()); | 5914 args->InsertAt(0, function, zone()); |
5898 | 5915 |
5899 return factory()->NewCallRuntime( | 5916 return factory()->NewCallRuntime( |
5900 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5917 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5901 } | 5918 } |
5902 } // namespace internal | 5919 } // namespace internal |
5903 } // namespace v8 | 5920 } // namespace v8 |
OLD | NEW |