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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 3719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3730 // VariableProxy | 3730 // VariableProxy |
3731 // | 3731 // |
3732 // As we need to visit the parameters in left-to-right order, we recurse on | 3732 // As we need to visit the parameters in left-to-right order, we recurse on |
3733 // the left-hand side of comma expressions. | 3733 // the left-hand side of comma expressions. |
3734 // | 3734 // |
3735 // Sadly, for the various malformed_arrow_function_parameter_list errors, we | 3735 // Sadly, for the various malformed_arrow_function_parameter_list errors, we |
3736 // can't be more specific on the error message or on the location because we | 3736 // can't be more specific on the error message or on the location because we |
3737 // need to match the pre-parser's behavior. | 3737 // need to match the pre-parser's behavior. |
3738 if (expr->IsBinaryOperation()) { | 3738 if (expr->IsBinaryOperation()) { |
3739 BinaryOperation* binop = expr->AsBinaryOperation(); | 3739 BinaryOperation* binop = expr->AsBinaryOperation(); |
3740 // TODO(wingo): These checks are now unnecessary, given the classifier. | 3740 // The classifier has already run, so we know that the expression is a valid |
3741 if (binop->op() != Token::COMMA) { | 3741 // arrow function formals production. |
3742 ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list"); | 3742 DCHECK_EQ(binop->op(), Token::COMMA); |
3743 *ok = false; | |
3744 return; | |
3745 } | |
3746 Expression* left = binop->left(); | 3743 Expression* left = binop->left(); |
3747 Expression* right = binop->right(); | 3744 Expression* right = binop->right(); |
3748 if (left->is_single_parenthesized() || right->is_single_parenthesized()) { | |
3749 ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list"); | |
3750 *ok = false; | |
3751 return; | |
3752 } | |
3753 DeclareArrowFunctionParameters(scope, left, params_loc, duplicate_loc, ok); | 3745 DeclareArrowFunctionParameters(scope, left, params_loc, duplicate_loc, ok); |
3754 if (!*ok) return; | 3746 if (!*ok) return; |
3755 // LHS of comma expression should be unparenthesized. | 3747 // LHS of comma expression should be unparenthesized. |
3756 expr = right; | 3748 expr = right; |
3757 } | 3749 } |
3758 | 3750 |
3759 // TODO(wingo): Support rest parameters. | 3751 // TODO(wingo): Support rest parameters. |
3760 if (!expr->IsVariableProxy()) { | 3752 DCHECK(expr->IsVariableProxy()); |
3761 ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list"); | 3753 DCHECK(!expr->AsVariableProxy()->is_this()); |
3762 *ok = false; | |
3763 return; | |
3764 } | |
3765 | 3754 |
3766 const AstRawString* raw_name = expr->AsVariableProxy()->raw_name(); | 3755 const AstRawString* raw_name = expr->AsVariableProxy()->raw_name(); |
3767 Scanner::Location param_location(expr->position(), | 3756 Scanner::Location param_location(expr->position(), |
3768 expr->position() + raw_name->length()); | 3757 expr->position() + raw_name->length()); |
3769 | 3758 |
3770 if (expr->AsVariableProxy()->is_this()) { | |
3771 ReportMessageAt(param_location, "this_formal_parameter"); | |
3772 *ok = false; | |
3773 return; | |
3774 } | |
3775 | |
3776 // When the formal parameter was originally seen, it was parsed as a | 3759 // When the formal parameter was originally seen, it was parsed as a |
3777 // VariableProxy and recorded as unresolved in the scope. Here we undo that | 3760 // VariableProxy and recorded as unresolved in the scope. Here we undo that |
3778 // parse-time side-effect. | 3761 // parse-time side-effect. |
3779 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); | 3762 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); |
3780 | 3763 |
3781 bool is_rest = false; | 3764 bool is_rest = false; |
3782 bool is_duplicate = DeclareFormalParameter(scope, raw_name, is_rest); | 3765 bool is_duplicate = DeclareFormalParameter(scope, raw_name, is_rest); |
3783 | 3766 |
3784 if (is_duplicate && !duplicate_loc->IsValid()) { | 3767 if (is_duplicate && !duplicate_loc->IsValid()) { |
3785 *duplicate_loc = param_location; | 3768 *duplicate_loc = param_location; |
3786 } | 3769 } |
3787 } | 3770 } |
3788 | 3771 |
3789 | 3772 |
3790 void ParserTraits::ParseArrowFunctionFormalParameters( | 3773 void ParserTraits::ParseArrowFunctionFormalParameters( |
3791 Scope* scope, Expression* params, const Scanner::Location& params_loc, | 3774 Scope* scope, Expression* params, const Scanner::Location& params_loc, |
3792 bool* is_rest, Scanner::Location* duplicate_loc, bool* ok) { | 3775 bool* is_rest, Scanner::Location* duplicate_loc, bool* ok) { |
3793 // Too many parentheses around expression: | |
3794 // (( ... )) => ... | |
3795 if (params->is_multi_parenthesized()) { | |
3796 // TODO(wingo): Make a better message. | |
3797 ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list"); | |
3798 *ok = false; | |
3799 return; | |
3800 } | |
3801 | |
3802 DeclareArrowFunctionParameters(scope, params, params_loc, duplicate_loc, ok); | 3776 DeclareArrowFunctionParameters(scope, params, params_loc, duplicate_loc, ok); |
3803 } | 3777 } |
3804 | 3778 |
3805 | 3779 |
3806 FunctionLiteral* Parser::ParseFunctionLiteral( | 3780 FunctionLiteral* Parser::ParseFunctionLiteral( |
3807 const AstRawString* function_name, Scanner::Location function_name_location, | 3781 const AstRawString* function_name, Scanner::Location function_name_location, |
3808 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 3782 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
3809 FunctionLiteral::FunctionType function_type, | 3783 FunctionLiteral::FunctionType function_type, |
3810 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 3784 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
3811 // Function :: | 3785 // Function :: |
(...skipping 1952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5764 | 5738 |
5765 Expression* Parser::SpreadCallNew(Expression* function, | 5739 Expression* Parser::SpreadCallNew(Expression* function, |
5766 ZoneList<v8::internal::Expression*>* args, | 5740 ZoneList<v8::internal::Expression*>* args, |
5767 int pos) { | 5741 int pos) { |
5768 args->InsertAt(0, function, zone()); | 5742 args->InsertAt(0, function, zone()); |
5769 | 5743 |
5770 return factory()->NewCallRuntime( | 5744 return factory()->NewCallRuntime( |
5771 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5745 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5772 } | 5746 } |
5773 } } // namespace v8::internal | 5747 } } // namespace v8::internal |
OLD | NEW |