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

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: CR feedback + rebase 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
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
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 #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 // Parsing patterns as variable reference expression creates
1188 ParseFormalParameterList(scope, &has_rest, &formals_classifier, &ok); 1188 // NewUnresolved references in current scope. Entrer arrow function
1189 if (ok) ok = Check(Token::RPAREN); 1189 // scope for formal parameter parsing.
1190 } else { 1190 BlockState block_state(&scope_, scope);
1191 // BindingIdentifier 1191 if (Check(Token::LPAREN)) {
1192 ParseFormalParameter(scope, has_rest, &formals_classifier, &ok); 1192 // '(' StrictFormalParameters ')'
1193 ParseFormalParameterList(scope, &has_rest, &formals_classifier, &ok);
1194 if (ok) ok = Check(Token::RPAREN);
1195 } else {
1196 // BindingIdentifier
1197 ParseFormalParameter(scope, has_rest, &formals_classifier, &ok);
1198 }
1193 } 1199 }
1194 1200
1195 if (ok) { 1201 if (ok) {
1196 Expression* expression = 1202 Expression* expression =
1197 ParseArrowFunctionLiteral(scope, has_rest, formals_classifier, &ok); 1203 ParseArrowFunctionLiteral(scope, has_rest, formals_classifier, &ok);
1198 if (ok) { 1204 if (ok) {
1199 // Scanning must end at the same position that was recorded 1205 // Scanning must end at the same position that was recorded
1200 // previously. If not, parsing has been interrupted due to a stack 1206 // previously. If not, parsing has been interrupted due to a stack
1201 // overflow, at which point the partially parsed arrow function 1207 // overflow, at which point the partially parsed arrow function
1202 // concise body happens to be a valid expression. This is a problem 1208 // concise body happens to be a valid expression. This is a problem
(...skipping 2595 matching lines...) Expand 10 before | Expand all | Expand 10 after
3798 } 3804 }
3799 3805
3800 // Only the right-most expression may be a rest parameter. 3806 // Only the right-most expression may be a rest parameter.
3801 DCHECK(!*has_rest); 3807 DCHECK(!*has_rest);
3802 3808
3803 if (expr->IsSpread()) { 3809 if (expr->IsSpread()) {
3804 *has_rest = true; 3810 *has_rest = true;
3805 expr = expr->AsSpread()->expression(); 3811 expr = expr->AsSpread()->expression();
3806 } 3812 }
3807 3813
3808 DCHECK(expr->IsVariableProxy()); 3814 if (!expr->IsVariableProxy()) {
3815 // TODO(dslomov): support pattern desugaring
3816 return;
3817 }
3809 DCHECK(!expr->AsVariableProxy()->is_this()); 3818 DCHECK(!expr->AsVariableProxy()->is_this());
3810 3819
3811 const AstRawString* raw_name = expr->AsVariableProxy()->raw_name(); 3820 const AstRawString* raw_name = expr->AsVariableProxy()->raw_name();
3812 Scanner::Location param_location(expr->position(), 3821 Scanner::Location param_location(expr->position(),
3813 expr->position() + raw_name->length()); 3822 expr->position() + raw_name->length());
3814 3823
3815 // When the formal parameter was originally seen, it was parsed as a 3824 // When the formal parameter was originally seen, it was parsed as a
3816 // VariableProxy and recorded as unresolved in the scope. Here we undo that 3825 // VariableProxy and recorded as unresolved in the scope. Here we undo that
3817 // parse-time side-effect. 3826 // parse-time side-effect.
3818 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); 3827 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
3819 3828
3820 ExpressionClassifier classifier; 3829 ExpressionClassifier classifier;
3821 DeclareFormalParameter(scope, raw_name, &classifier, *has_rest); 3830 DeclareFormalParameter(scope, expr, &classifier, *has_rest);
3822 if (!duplicate_loc->IsValid()) { 3831 if (!duplicate_loc->IsValid()) {
3823 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; 3832 *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
3824 } 3833 }
3825 } 3834 }
3826 3835
3827 3836
3828 FunctionLiteral* Parser::ParseFunctionLiteral( 3837 FunctionLiteral* Parser::ParseFunctionLiteral(
3829 const AstRawString* function_name, Scanner::Location function_name_location, 3838 const AstRawString* function_name, Scanner::Location function_name_location,
3830 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, 3839 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos,
3831 FunctionLiteral::FunctionType function_type, 3840 FunctionLiteral::FunctionType function_type,
(...skipping 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after
5826 Expression* Parser::SpreadCallNew(Expression* function, 5835 Expression* Parser::SpreadCallNew(Expression* function,
5827 ZoneList<v8::internal::Expression*>* args, 5836 ZoneList<v8::internal::Expression*>* args,
5828 int pos) { 5837 int pos) {
5829 args->InsertAt(0, function, zone()); 5838 args->InsertAt(0, function, zone());
5830 5839
5831 return factory()->NewCallRuntime( 5840 return factory()->NewCallRuntime(
5832 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5841 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5833 } 5842 }
5834 } // namespace internal 5843 } // namespace internal
5835 } // namespace v8 5844 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698