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/parser.h" | 5 #include "src/parser.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/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 3886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3897 | 3897 |
3898 bool is_rest = expr->IsSpread(); | 3898 bool is_rest = expr->IsSpread(); |
3899 if (is_rest) { | 3899 if (is_rest) { |
3900 expr = expr->AsSpread()->expression(); | 3900 expr = expr->AsSpread()->expression(); |
3901 parameters->has_rest = true; | 3901 parameters->has_rest = true; |
3902 } | 3902 } |
3903 if (parameters->is_simple) { | 3903 if (parameters->is_simple) { |
3904 parameters->is_simple = !is_rest && expr->IsVariableProxy(); | 3904 parameters->is_simple = !is_rest && expr->IsVariableProxy(); |
3905 } | 3905 } |
3906 | 3906 |
| 3907 Expression* initializer = nullptr; |
3907 if (expr->IsVariableProxy()) { | 3908 if (expr->IsVariableProxy()) { |
3908 // When the formal parameter was originally seen, it was parsed as a | 3909 // When the formal parameter was originally seen, it was parsed as a |
3909 // VariableProxy and recorded as unresolved in the scope. Here we undo that | 3910 // VariableProxy and recorded as unresolved in the scope. Here we undo that |
3910 // parse-time side-effect for parameters that are single-names (not | 3911 // parse-time side-effect for parameters that are single-names (not |
3911 // patterns; for patterns that happens uniformly in | 3912 // patterns; for patterns that happens uniformly in |
3912 // PatternRewriter::VisitVariableProxy). | 3913 // PatternRewriter::VisitVariableProxy). |
3913 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); | 3914 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); |
3914 } | 3915 } else if (expr->IsAssignment()) { |
3915 | 3916 Assignment* assignment = expr->AsAssignment(); |
3916 Expression* initializer = nullptr; | 3917 DCHECK(parser_->allow_harmony_default_parameters()); |
3917 if (!is_rest && parser_->allow_harmony_default_parameters() && | 3918 DCHECK(!assignment->is_compound()); |
3918 parser_->Check(Token::ASSIGN)) { | 3919 initializer = assignment->value(); |
3919 ExpressionClassifier init_classifier; | 3920 expr = assignment->target(); |
3920 initializer = | |
3921 parser_->ParseAssignmentExpression(true, &init_classifier, ok); | |
3922 if (!*ok) return; | |
3923 parser_->ValidateExpression(&init_classifier, ok); | |
3924 if (!*ok) return; | |
3925 parameters->is_simple = false; | |
3926 } | 3921 } |
3927 | 3922 |
3928 AddFormalParameter(parameters, expr, initializer, is_rest); | 3923 AddFormalParameter(parameters, expr, initializer, is_rest); |
3929 } | 3924 } |
3930 | 3925 |
3931 | 3926 |
3932 void ParserTraits::ParseArrowFunctionFormalParameterList( | 3927 void ParserTraits::ParseArrowFunctionFormalParameterList( |
3933 ParserFormalParameters* parameters, Expression* expr, | 3928 ParserFormalParameters* parameters, Expression* expr, |
3934 const Scanner::Location& params_loc, | 3929 const Scanner::Location& params_loc, |
3935 Scanner::Location* duplicate_loc, bool* ok) { | 3930 Scanner::Location* duplicate_loc, bool* ok) { |
(...skipping 2135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6071 Expression* Parser::SpreadCallNew(Expression* function, | 6066 Expression* Parser::SpreadCallNew(Expression* function, |
6072 ZoneList<v8::internal::Expression*>* args, | 6067 ZoneList<v8::internal::Expression*>* args, |
6073 int pos) { | 6068 int pos) { |
6074 args->InsertAt(0, function, zone()); | 6069 args->InsertAt(0, function, zone()); |
6075 | 6070 |
6076 return factory()->NewCallRuntime( | 6071 return factory()->NewCallRuntime( |
6077 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 6072 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
6078 } | 6073 } |
6079 } // namespace internal | 6074 } // namespace internal |
6080 } // namespace v8 | 6075 } // namespace v8 |
OLD | NEW |