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

Side by Side Diff: src/parsing/parser.cc

Issue 1900343002: More accurately record an end position for default parameters in arrows (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: nikolaos comments Created 4 years, 8 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/parsing/parser.h ('k') | test/mjsunit/regress/regress-4908.js » ('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/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 3809 matching lines...) Expand 10 before | Expand all | Expand 10 after
3820 Handle<FixedArray> value) { 3820 Handle<FixedArray> value) {
3821 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); 3821 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot));
3822 return static_cast<LiteralType>(literal_type->value()); 3822 return static_cast<LiteralType>(literal_type->value());
3823 } 3823 }
3824 3824
3825 3825
3826 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 3826 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3827 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 3827 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3828 } 3828 }
3829 3829
3830
3831 void ParserTraits::ParseArrowFunctionFormalParameters( 3830 void ParserTraits::ParseArrowFunctionFormalParameters(
3832 ParserFormalParameters* parameters, Expression* expr, 3831 ParserFormalParameters* parameters, Expression* expr, int end_pos,
3833 const Scanner::Location& params_loc, bool* ok) { 3832 bool* ok) {
3834 if (parameters->Arity() >= Code::kMaxArguments) {
3835 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
3836 *ok = false;
3837 return;
3838 }
3839
3840 // ArrowFunctionFormals :: 3833 // ArrowFunctionFormals ::
3841 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail) 3834 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail)
3842 // Tail 3835 // Tail
3843 // NonTailArrowFunctionFormals :: 3836 // NonTailArrowFunctionFormals ::
3844 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy) 3837 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy)
3845 // VariableProxy 3838 // VariableProxy
3846 // Tail :: 3839 // Tail ::
3847 // VariableProxy 3840 // VariableProxy
3848 // Spread(VariableProxy) 3841 // Spread(VariableProxy)
3849 // 3842 //
3850 // As we need to visit the parameters in left-to-right order, we recurse on 3843 // As we need to visit the parameters in left-to-right order, we recurse on
3851 // the left-hand side of comma expressions. 3844 // the left-hand side of comma expressions.
3852 // 3845 //
3853 if (expr->IsBinaryOperation()) { 3846 if (expr->IsBinaryOperation()) {
3854 BinaryOperation* binop = expr->AsBinaryOperation(); 3847 BinaryOperation* binop = expr->AsBinaryOperation();
3855 // The classifier has already run, so we know that the expression is a valid 3848 // The classifier has already run, so we know that the expression is a valid
3856 // arrow function formals production. 3849 // arrow function formals production.
3857 DCHECK_EQ(binop->op(), Token::COMMA); 3850 DCHECK_EQ(binop->op(), Token::COMMA);
3858 Expression* left = binop->left(); 3851 Expression* left = binop->left();
3859 Expression* right = binop->right(); 3852 Expression* right = binop->right();
3860 ParseArrowFunctionFormalParameters(parameters, left, params_loc, ok); 3853 int comma_pos = binop->position();
3854 ParseArrowFunctionFormalParameters(parameters, left, comma_pos, ok);
3861 if (!*ok) return; 3855 if (!*ok) return;
3862 // LHS of comma expression should be unparenthesized. 3856 // LHS of comma expression should be unparenthesized.
3863 expr = right; 3857 expr = right;
3864 } 3858 }
3865 3859
3866 // Only the right-most expression may be a rest parameter. 3860 // Only the right-most expression may be a rest parameter.
3867 DCHECK(!parameters->has_rest); 3861 DCHECK(!parameters->has_rest);
3868 3862
3869 bool is_rest = expr->IsSpread(); 3863 bool is_rest = expr->IsSpread();
3870 if (is_rest) { 3864 if (is_rest) {
(...skipping 16 matching lines...) Expand all
3887 Assignment* assignment = expr->AsAssignment(); 3881 Assignment* assignment = expr->AsAssignment();
3888 DCHECK(!assignment->is_compound()); 3882 DCHECK(!assignment->is_compound());
3889 initializer = assignment->value(); 3883 initializer = assignment->value();
3890 expr = assignment->target(); 3884 expr = assignment->target();
3891 3885
3892 // TODO(adamk): Only call this if necessary. 3886 // TODO(adamk): Only call this if necessary.
3893 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, 3887 RewriteParameterInitializerScope(parser_->stack_limit(), initializer,
3894 parser_->scope_, parameters->scope); 3888 parser_->scope_, parameters->scope);
3895 } 3889 }
3896 3890
3897 // TODO(adamk): params_loc.end_pos is not the correct initializer position, 3891 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest);
3898 // but it should be conservative enough to trigger hole checks for variables
3899 // referenced in the initializer (if any).
3900 AddFormalParameter(parameters, expr, initializer, params_loc.end_pos,
3901 is_rest);
3902 } 3892 }
3903 3893
3904 3894
3905 DoExpression* Parser::ParseDoExpression(bool* ok) { 3895 DoExpression* Parser::ParseDoExpression(bool* ok) {
3906 // AssignmentExpression :: 3896 // AssignmentExpression ::
3907 // do '{' StatementList '}' 3897 // do '{' StatementList '}'
3908 int pos = peek_position(); 3898 int pos = peek_position();
3909 3899
3910 Expect(Token::DO, CHECK_OK); 3900 Expect(Token::DO, CHECK_OK);
3911 Variable* result = 3901 Variable* result =
3912 scope_->NewTemporary(ast_value_factory()->dot_result_string()); 3902 scope_->NewTemporary(ast_value_factory()->dot_result_string());
3913 Block* block = ParseBlock(nullptr, false, CHECK_OK); 3903 Block* block = ParseBlock(nullptr, false, CHECK_OK);
3914 DoExpression* expr = factory()->NewDoExpression(block, result, pos); 3904 DoExpression* expr = factory()->NewDoExpression(block, result, pos);
3915 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { 3905 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) {
3916 *ok = false; 3906 *ok = false;
3917 return nullptr; 3907 return nullptr;
3918 } 3908 }
3919 block->set_scope(block->scope()->FinalizeBlockScope()); 3909 block->set_scope(block->scope()->FinalizeBlockScope());
3920 return expr; 3910 return expr;
3921 } 3911 }
3922 3912
3923 3913
3924 void ParserTraits::ParseArrowFunctionFormalParameterList( 3914 void ParserTraits::ParseArrowFunctionFormalParameterList(
3925 ParserFormalParameters* parameters, Expression* expr, 3915 ParserFormalParameters* parameters, Expression* expr,
3926 const Scanner::Location& params_loc, 3916 const Scanner::Location& params_loc,
3927 Scanner::Location* duplicate_loc, bool* ok) { 3917 Scanner::Location* duplicate_loc, bool* ok) {
3928 if (expr->IsEmptyParentheses()) return; 3918 if (expr->IsEmptyParentheses()) return;
3929 3919
3930 ParseArrowFunctionFormalParameters(parameters, expr, params_loc, ok); 3920 ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos, ok);
3931 if (!*ok) return; 3921 if (!*ok) return;
3932 3922
3923 if (parameters->Arity() > Code::kMaxArguments) {
3924 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
3925 *ok = false;
3926 return;
3927 }
3928
3933 Type::ExpressionClassifier classifier(parser_); 3929 Type::ExpressionClassifier classifier(parser_);
3934 if (!parameters->is_simple) { 3930 if (!parameters->is_simple) {
3935 classifier.RecordNonSimpleParameter(); 3931 classifier.RecordNonSimpleParameter();
3936 } 3932 }
3937 for (int i = 0; i < parameters->Arity(); ++i) { 3933 for (int i = 0; i < parameters->Arity(); ++i) {
3938 auto parameter = parameters->at(i); 3934 auto parameter = parameters->at(i);
3939 DeclareFormalParameter(parameters->scope, parameter, &classifier); 3935 DeclareFormalParameter(parameters->scope, parameter, &classifier);
3940 if (!duplicate_loc->IsValid()) { 3936 if (!duplicate_loc->IsValid()) {
3941 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; 3937 *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
3942 } 3938 }
(...skipping 2842 matching lines...) Expand 10 before | Expand all | Expand 10 after
6785 try_block, target); 6781 try_block, target);
6786 final_loop = target; 6782 final_loop = target;
6787 } 6783 }
6788 6784
6789 return final_loop; 6785 return final_loop;
6790 } 6786 }
6791 6787
6792 6788
6793 } // namespace internal 6789 } // namespace internal
6794 } // namespace v8 6790 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | test/mjsunit/regress/regress-4908.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698