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

Side by Side Diff: src/parser.cc

Issue 1212473002: [destructuring] Re-index materialized literals in arrow function parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes Created 5 years, 5 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
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 #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 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 : FunctionLiteral::NAMED_EXPRESSION) 1175 : FunctionLiteral::NAMED_EXPRESSION)
1175 : FunctionLiteral::DECLARATION; 1176 : FunctionLiteral::DECLARATION;
1176 bool ok = true; 1177 bool ok = true;
1177 1178
1178 if (shared_info->is_arrow()) { 1179 if (shared_info->is_arrow()) {
1179 Scope* scope = 1180 Scope* scope =
1180 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); 1181 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
1181 scope->set_start_position(shared_info->start_position()); 1182 scope->set_start_position(shared_info->start_position());
1182 ExpressionClassifier formals_classifier; 1183 ExpressionClassifier formals_classifier;
1183 ParserFormalParameterParsingState parsing_state(scope); 1184 ParserFormalParameterParsingState parsing_state(scope);
1185 Checkpoint checkpoint(this);
1184 { 1186 {
1185 // Parsing patterns as variable reference expression creates 1187 // Parsing patterns as variable reference expression creates
1186 // NewUnresolved references in current scope. Entrer arrow function 1188 // NewUnresolved references in current scope. Entrer arrow function
1187 // scope for formal parameter parsing. 1189 // scope for formal parameter parsing.
1188 BlockState block_state(&scope_, scope); 1190 BlockState block_state(&scope_, scope);
1189 if (Check(Token::LPAREN)) { 1191 if (Check(Token::LPAREN)) {
1190 // '(' StrictFormalParameters ')' 1192 // '(' StrictFormalParameters ')'
1191 ParseFormalParameterList(&parsing_state, &formals_classifier, &ok); 1193 ParseFormalParameterList(&parsing_state, &formals_classifier, &ok);
1192 if (ok) ok = Check(Token::RPAREN); 1194 if (ok) ok = Check(Token::RPAREN);
1193 } else { 1195 } else {
1194 // BindingIdentifier 1196 // BindingIdentifier
1195 const bool is_rest = false; 1197 const bool is_rest = false;
1196 ParseFormalParameter(is_rest, &parsing_state, &formals_classifier, 1198 ParseFormalParameter(is_rest, &parsing_state, &formals_classifier,
1197 &ok); 1199 &ok);
1198 } 1200 }
1199 } 1201 }
1200 1202
1201 if (ok) { 1203 if (ok) {
1204 checkpoint.Restore(&parsing_state.materialized_literals_count);
1202 Expression* expression = 1205 Expression* expression =
1203 ParseArrowFunctionLiteral(parsing_state, formals_classifier, &ok); 1206 ParseArrowFunctionLiteral(parsing_state, formals_classifier, &ok);
1204 if (ok) { 1207 if (ok) {
1205 // Scanning must end at the same position that was recorded 1208 // Scanning must end at the same position that was recorded
1206 // previously. If not, parsing has been interrupted due to a stack 1209 // previously. If not, parsing has been interrupted due to a stack
1207 // overflow, at which point the partially parsed arrow function 1210 // overflow, at which point the partially parsed arrow function
1208 // concise body happens to be a valid expression. This is a problem 1211 // concise body happens to be a valid expression. This is a problem
1209 // only for arrow functions with single expression bodies, since there 1212 // only for arrow functions with single expression bodies, since there
1210 // is no end token such as "}" for normal functions. 1213 // is no end token such as "}" for normal functions.
1211 if (scanner()->location().end_pos == shared_info->end_position()) { 1214 if (scanner()->location().end_pos == shared_info->end_position()) {
(...skipping 2636 matching lines...) Expand 10 before | Expand all | Expand 10 after
3848 } 3851 }
3849 3852
3850 ExpressionClassifier classifier; 3853 ExpressionClassifier classifier;
3851 DeclareFormalParameter(parsing_state, expr, &classifier, is_rest); 3854 DeclareFormalParameter(parsing_state, expr, &classifier, is_rest);
3852 if (!duplicate_loc->IsValid()) { 3855 if (!duplicate_loc->IsValid()) {
3853 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; 3856 *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
3854 } 3857 }
3855 } 3858 }
3856 3859
3857 3860
3861 void ParserTraits::ReindexLiterals(
3862 const ParserFormalParameterParsingState& parsing_state) {
3863 if (parser_->function_state_->materialized_literal_count() > 0) {
3864 AstLiteralReindexer reindexer;
3865
3866 for (const auto p : parsing_state.params) {
3867 if (p.pattern != nullptr) reindexer.Reindex(p.pattern);
3868 }
3869 DCHECK(reindexer.count() <=
3870 parser_->function_state_->materialized_literal_count());
3871 }
3872 }
3873
3874
3858 FunctionLiteral* Parser::ParseFunctionLiteral( 3875 FunctionLiteral* Parser::ParseFunctionLiteral(
3859 const AstRawString* function_name, Scanner::Location function_name_location, 3876 const AstRawString* function_name, Scanner::Location function_name_location,
3860 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, 3877 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos,
3861 FunctionLiteral::FunctionType function_type, 3878 FunctionLiteral::FunctionType function_type,
3862 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { 3879 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) {
3863 // Function :: 3880 // Function ::
3864 // '(' FormalParameterList? ')' '{' FunctionBody '}' 3881 // '(' FormalParameterList? ')' '{' FunctionBody '}'
3865 // 3882 //
3866 // Getter :: 3883 // Getter ::
3867 // '(' ')' '{' FunctionBody '}' 3884 // '(' ')' '{' FunctionBody '}'
(...skipping 2028 matching lines...) Expand 10 before | Expand all | Expand 10 after
5896 Expression* Parser::SpreadCallNew(Expression* function, 5913 Expression* Parser::SpreadCallNew(Expression* function,
5897 ZoneList<v8::internal::Expression*>* args, 5914 ZoneList<v8::internal::Expression*>* args,
5898 int pos) { 5915 int pos) {
5899 args->InsertAt(0, function, zone()); 5916 args->InsertAt(0, function, zone());
5900 5917
5901 return factory()->NewCallRuntime( 5918 return factory()->NewCallRuntime(
5902 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5919 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5903 } 5920 }
5904 } // namespace internal 5921 } // namespace internal
5905 } // namespace v8 5922 } // namespace v8
OLDNEW
« src/ast-literal-reindexer.h ('K') | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698