Chromium Code Reviews| 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 3741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3752 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3752 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
| 3753 return static_cast<LiteralType>(literal_type->value()); | 3753 return static_cast<LiteralType>(literal_type->value()); |
| 3754 } | 3754 } |
| 3755 | 3755 |
| 3756 | 3756 |
| 3757 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3757 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
| 3758 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3758 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
| 3759 } | 3759 } |
| 3760 | 3760 |
| 3761 | 3761 |
| 3762 void ParserTraits::DeclareArrowFunctionParameters( | 3762 void ParserTraits::ParseArrowFunctionFormalParameters( |
| 3763 Scope* scope, Expression* expr, const Scanner::Location& params_loc, | 3763 Scope* scope, Expression* expr, const Scanner::Location& params_loc, |
| 3764 Scanner::Location* duplicate_loc, bool* ok) { | 3764 bool has_rest, Scanner::Location* duplicate_loc, bool* ok) { |
| 3765 if (scope->num_parameters() >= Code::kMaxArguments) { | 3765 if (scope->num_parameters() >= Code::kMaxArguments) { |
| 3766 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); | 3766 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); |
| 3767 *ok = false; | 3767 *ok = false; |
| 3768 return; | 3768 return; |
| 3769 } | 3769 } |
| 3770 | 3770 |
| 3771 // ArrowFunctionFormals :: | 3771 // ArrowFunctionFormals :: |
| 3772 // Binary(Token::COMMA, ArrowFunctionFormals, VariableProxy) | 3772 // Binary(Token::COMMA, ArrowFunctionFormals, VariableProxy) |
| 3773 // VariableProxy | 3773 // VariableProxy |
| 3774 // | 3774 // |
| 3775 // As we need to visit the parameters in left-to-right order, we recurse on | 3775 // As we need to visit the parameters in left-to-right order, we recurse on |
| 3776 // the left-hand side of comma expressions. | 3776 // the left-hand side of comma expressions. |
| 3777 // | 3777 // |
| 3778 // Sadly, for the various malformed_arrow_function_parameter_list errors, we | 3778 // Sadly, for the various malformed_arrow_function_parameter_list errors, we |
| 3779 // can't be more specific on the error message or on the location because we | 3779 // can't be more specific on the error message or on the location because we |
| 3780 // need to match the pre-parser's behavior. | 3780 // need to match the pre-parser's behavior. |
| 3781 if (expr->IsBinaryOperation()) { | 3781 if (expr->IsBinaryOperation()) { |
| 3782 BinaryOperation* binop = expr->AsBinaryOperation(); | 3782 BinaryOperation* binop = expr->AsBinaryOperation(); |
| 3783 // The classifier has already run, so we know that the expression is a valid | 3783 // The classifier has already run, so we know that the expression is a valid |
| 3784 // arrow function formals production. | 3784 // arrow function formals production. |
| 3785 DCHECK_EQ(binop->op(), Token::COMMA); | 3785 DCHECK_EQ(binop->op(), Token::COMMA); |
| 3786 Expression* left = binop->left(); | 3786 Expression* left = binop->left(); |
| 3787 Expression* right = binop->right(); | 3787 Expression* right = binop->right(); |
| 3788 DeclareArrowFunctionParameters(scope, left, params_loc, duplicate_loc, ok); | 3788 // Only the right-most expression may be a rest parameter. |
| 3789 bool has_rest = false; | |
| 3790 ParseArrowFunctionFormalParameters(scope, left, params_loc, has_rest, | |
| 3791 duplicate_loc, ok); | |
| 3789 if (!*ok) return; | 3792 if (!*ok) return; |
| 3790 // LHS of comma expression should be unparenthesized. | 3793 // LHS of comma expression should be unparenthesized. |
| 3791 expr = right; | 3794 expr = right; |
| 3792 } | 3795 } |
| 3793 | 3796 |
| 3794 // TODO(wingo): Support rest parameters. | |
| 3795 DCHECK(expr->IsVariableProxy()); | 3797 DCHECK(expr->IsVariableProxy()); |
| 3796 DCHECK(!expr->AsVariableProxy()->is_this()); | 3798 DCHECK(!expr->AsVariableProxy()->is_this()); |
| 3797 | 3799 |
| 3798 const AstRawString* raw_name = expr->AsVariableProxy()->raw_name(); | 3800 const AstRawString* raw_name = expr->AsVariableProxy()->raw_name(); |
| 3799 Scanner::Location param_location(expr->position(), | 3801 Scanner::Location param_location(expr->position(), |
| 3800 expr->position() + raw_name->length()); | 3802 expr->position() + raw_name->length()); |
| 3801 | 3803 |
| 3802 // When the formal parameter was originally seen, it was parsed as a | 3804 // When the formal parameter was originally seen, it was parsed as a |
| 3803 // VariableProxy and recorded as unresolved in the scope. Here we undo that | 3805 // VariableProxy and recorded as unresolved in the scope. Here we undo that |
| 3804 // parse-time side-effect. | 3806 // parse-time side-effect. |
| 3805 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); | 3807 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); |
| 3806 | 3808 |
| 3807 bool is_rest = false; | |
| 3808 ExpressionClassifier classifier; | 3809 ExpressionClassifier classifier; |
| 3809 DeclareFormalParameter(scope, raw_name, &classifier, is_rest); | 3810 DeclareFormalParameter(scope, raw_name, &classifier, has_rest); |
| 3810 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; | 3811 if (!duplicate_loc->IsValid()) { |
|
Dmitry Lomov (no reviews)
2015/06/10 11:04:41
Oops, thanks for fixing this! Can we add a test th
wingo
2015/06/10 13:21:10
Sure. I'll see if I can cook one up for this CL a
| |
| 3812 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; | |
| 3813 } | |
| 3811 } | 3814 } |
| 3812 | 3815 |
| 3813 | 3816 |
| 3814 void ParserTraits::ParseArrowFunctionFormalParameters( | |
| 3815 Scope* scope, Expression* params, const Scanner::Location& params_loc, | |
| 3816 bool* is_rest, Scanner::Location* duplicate_loc, bool* ok) { | |
| 3817 DeclareArrowFunctionParameters(scope, params, params_loc, duplicate_loc, ok); | |
| 3818 } | |
| 3819 | |
| 3820 | |
| 3821 FunctionLiteral* Parser::ParseFunctionLiteral( | 3817 FunctionLiteral* Parser::ParseFunctionLiteral( |
| 3822 const AstRawString* function_name, Scanner::Location function_name_location, | 3818 const AstRawString* function_name, Scanner::Location function_name_location, |
| 3823 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 3819 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
| 3824 FunctionLiteral::FunctionType function_type, | 3820 FunctionLiteral::FunctionType function_type, |
| 3825 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 3821 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
| 3826 // Function :: | 3822 // Function :: |
| 3827 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 3823 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 3828 // | 3824 // |
| 3829 // Getter :: | 3825 // Getter :: |
| 3830 // '(' ')' '{' FunctionBody '}' | 3826 // '(' ')' '{' FunctionBody '}' |
| (...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5819 Expression* Parser::SpreadCallNew(Expression* function, | 5815 Expression* Parser::SpreadCallNew(Expression* function, |
| 5820 ZoneList<v8::internal::Expression*>* args, | 5816 ZoneList<v8::internal::Expression*>* args, |
| 5821 int pos) { | 5817 int pos) { |
| 5822 args->InsertAt(0, function, zone()); | 5818 args->InsertAt(0, function, zone()); |
| 5823 | 5819 |
| 5824 return factory()->NewCallRuntime( | 5820 return factory()->NewCallRuntime( |
| 5825 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5821 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
| 5826 } | 5822 } |
| 5827 } // namespace internal | 5823 } // namespace internal |
| 5828 } // namespace v8 | 5824 } // namespace v8 |
| OLD | NEW |