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

Side by Side Diff: src/parser.cc

Issue 1167393005: [destructuring] Parse binding patterns in formal parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase + tests Created 5 years, 6 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/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 : FunctionLiteral::NAMED_EXPRESSION) 1176 : FunctionLiteral::NAMED_EXPRESSION)
1177 : FunctionLiteral::DECLARATION; 1177 : FunctionLiteral::DECLARATION;
1178 bool ok = true; 1178 bool ok = true;
1179 1179
1180 if (shared_info->is_arrow()) { 1180 if (shared_info->is_arrow()) {
1181 Scope* scope = 1181 Scope* scope =
1182 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); 1182 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
1183 scope->set_start_position(shared_info->start_position()); 1183 scope->set_start_position(shared_info->start_position());
1184 ExpressionClassifier formals_classifier; 1184 ExpressionClassifier formals_classifier;
1185 bool has_rest = false; 1185 bool has_rest = false;
1186 if (Check(Token::LPAREN)) { 1186 {
1187 // '(' StrictFormalParameters ')' 1187 BlockState block_state(&scope_, scope);
arv (Not doing code reviews) 2015/06/15 15:21:59 Why was this block state added? It does not seem l
Dmitry Lomov (no reviews) 2015/06/15 16:12:51 Ah, this is a tricky bit. Parsing patterns as vari
1188 ParseFormalParameterList(scope, &has_rest, &formals_classifier, &ok); 1188 if (Check(Token::LPAREN)) {
1189 if (ok) ok = Check(Token::RPAREN); 1189 // '(' StrictFormalParameters ')'
1190 } else { 1190 ParseFormalParameterList(scope, &has_rest, &formals_classifier, &ok);
1191 // BindingIdentifier 1191 if (ok) ok = Check(Token::RPAREN);
1192 ParseFormalParameter(scope, has_rest, &formals_classifier, &ok); 1192 } else {
1193 // BindingIdentifier
1194 ParseFormalParameter(scope, has_rest, &formals_classifier, &ok);
1195 }
1193 } 1196 }
1194 1197
1195 if (ok) { 1198 if (ok) {
1196 Expression* expression = 1199 Expression* expression =
1197 ParseArrowFunctionLiteral(scope, has_rest, formals_classifier, &ok); 1200 ParseArrowFunctionLiteral(scope, has_rest, formals_classifier, &ok);
1198 if (ok) { 1201 if (ok) {
1199 // Scanning must end at the same position that was recorded 1202 // Scanning must end at the same position that was recorded
1200 // previously. If not, parsing has been interrupted due to a stack 1203 // previously. If not, parsing has been interrupted due to a stack
1201 // overflow, at which point the partially parsed arrow function 1204 // overflow, at which point the partially parsed arrow function
1202 // concise body happens to be a valid expression. This is a problem 1205 // concise body happens to be a valid expression. This is a problem
(...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after
3796 } 3799 }
3797 3800
3798 // Only the right-most expression may be a rest parameter. 3801 // Only the right-most expression may be a rest parameter.
3799 DCHECK(!*has_rest); 3802 DCHECK(!*has_rest);
3800 3803
3801 if (expr->IsSpread()) { 3804 if (expr->IsSpread()) {
3802 *has_rest = true; 3805 *has_rest = true;
3803 expr = expr->AsSpread()->expression(); 3806 expr = expr->AsSpread()->expression();
3804 } 3807 }
3805 3808
3806 DCHECK(expr->IsVariableProxy()); 3809 if (!expr->IsVariableProxy()) {
3810 // TODO(dslomov): support pattern desugaring
3811 return;
3812 }
3813 // TODO(wingo): Support rest parameters.
arv (Not doing code reviews) 2015/06/15 15:21:59 Andy implemented this last week.
Dmitry Lomov (no reviews) 2015/06/15 16:12:51 Removed.
3807 DCHECK(!expr->AsVariableProxy()->is_this()); 3814 DCHECK(!expr->AsVariableProxy()->is_this());
3808 3815
3809 const AstRawString* raw_name = expr->AsVariableProxy()->raw_name(); 3816 const AstRawString* raw_name = expr->AsVariableProxy()->raw_name();
3810 Scanner::Location param_location(expr->position(), 3817 Scanner::Location param_location(expr->position(),
3811 expr->position() + raw_name->length()); 3818 expr->position() + raw_name->length());
3812 3819
3813 // When the formal parameter was originally seen, it was parsed as a 3820 // When the formal parameter was originally seen, it was parsed as a
3814 // VariableProxy and recorded as unresolved in the scope. Here we undo that 3821 // VariableProxy and recorded as unresolved in the scope. Here we undo that
3815 // parse-time side-effect. 3822 // parse-time side-effect.
3816 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); 3823 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
3817 3824
3818 ExpressionClassifier classifier; 3825 ExpressionClassifier classifier;
3819 DeclareFormalParameter(scope, raw_name, &classifier, *has_rest); 3826 DeclareFormalParameter(scope, expr, &classifier, *has_rest);
3820 if (!duplicate_loc->IsValid()) { 3827 if (!duplicate_loc->IsValid()) {
3821 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; 3828 *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
3822 } 3829 }
3823 } 3830 }
3824 3831
3825 3832
3826 FunctionLiteral* Parser::ParseFunctionLiteral( 3833 FunctionLiteral* Parser::ParseFunctionLiteral(
3827 const AstRawString* function_name, Scanner::Location function_name_location, 3834 const AstRawString* function_name, Scanner::Location function_name_location,
3828 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, 3835 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos,
3829 FunctionLiteral::FunctionType function_type, 3836 FunctionLiteral::FunctionType function_type,
(...skipping 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after
5824 Expression* Parser::SpreadCallNew(Expression* function, 5831 Expression* Parser::SpreadCallNew(Expression* function,
5825 ZoneList<v8::internal::Expression*>* args, 5832 ZoneList<v8::internal::Expression*>* args,
5826 int pos) { 5833 int pos) {
5827 args->InsertAt(0, function, zone()); 5834 args->InsertAt(0, function, zone());
5828 5835
5829 return factory()->NewCallRuntime( 5836 return factory()->NewCallRuntime(
5830 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5837 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5831 } 5838 }
5832 } // namespace internal 5839 } // namespace internal
5833 } // namespace v8 5840 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | test/cctest/test-parsing.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698