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

Side by Side Diff: src/parser.cc

Issue 1300103005: [parser] disallow language mode directive in body of function with non-simple parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: flag implications don't work in test suite? Created 5 years, 3 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/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 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 // scope for formal parameter parsing. 1191 // scope for formal parameter parsing.
1192 BlockState block_state(&scope_, scope); 1192 BlockState block_state(&scope_, scope);
1193 if (Check(Token::LPAREN)) { 1193 if (Check(Token::LPAREN)) {
1194 // '(' StrictFormalParameters ')' 1194 // '(' StrictFormalParameters ')'
1195 ParseFormalParameterList(&formals, &formals_classifier, &ok); 1195 ParseFormalParameterList(&formals, &formals_classifier, &ok);
1196 if (ok) ok = Check(Token::RPAREN); 1196 if (ok) ok = Check(Token::RPAREN);
1197 } else { 1197 } else {
1198 // BindingIdentifier 1198 // BindingIdentifier
1199 ParseFormalParameter(&formals, &formals_classifier, &ok); 1199 ParseFormalParameter(&formals, &formals_classifier, &ok);
1200 if (ok) { 1200 if (ok) {
1201 DeclareFormalParameter( 1201 DeclareFormalParameter(formals.scope, formals.at(0),
1202 formals.scope, formals.at(0), formals.is_simple, 1202 &formals_classifier);
1203 &formals_classifier);
1204 } 1203 }
1205 } 1204 }
1206 } 1205 }
1207 1206
1208 if (ok) { 1207 if (ok) {
1209 checkpoint.Restore(&formals.materialized_literals_count); 1208 checkpoint.Restore(&formals.materialized_literals_count);
1210 Expression* expression = 1209 Expression* expression =
1211 ParseArrowFunctionLiteral(formals, formals_classifier, &ok); 1210 ParseArrowFunctionLiteral(formals, formals_classifier, &ok);
1212 if (ok) { 1211 if (ok) {
1213 // Scanning must end at the same position that was recorded 1212 // Scanning must end at the same position that was recorded
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 ast_value_factory()->use_strict_string() && 1314 ast_value_factory()->use_strict_string() &&
1316 token_loc.end_pos - token_loc.beg_pos == 1315 token_loc.end_pos - token_loc.beg_pos ==
1317 ast_value_factory()->use_strict_string()->length() + 2; 1316 ast_value_factory()->use_strict_string()->length() + 2;
1318 bool use_strong_found = 1317 bool use_strong_found =
1319 allow_strong_mode() && 1318 allow_strong_mode() &&
1320 literal->raw_value()->AsString() == 1319 literal->raw_value()->AsString() ==
1321 ast_value_factory()->use_strong_string() && 1320 ast_value_factory()->use_strong_string() &&
1322 token_loc.end_pos - token_loc.beg_pos == 1321 token_loc.end_pos - token_loc.beg_pos ==
1323 ast_value_factory()->use_strong_string()->length() + 2; 1322 ast_value_factory()->use_strong_string()->length() + 2;
1324 if (use_strict_found || use_strong_found) { 1323 if (use_strict_found || use_strong_found) {
1324 if (!scope_->HasSimpleParameters()) {
1325 // TC39 deemed "use strict" directives to be an error when occurring
1326 // in the body of a function with non-simple parameter list, on
1327 // 29/7/2015. https://goo.gl/ueA7Ln
1328 //
1329 // In V8, this also applies to "use strong " directives.
1330 const AstRawString* string = literal->raw_value()->AsString();
1331 ParserTraits::ReportMessageAt(
1332 token_loc, MessageTemplate::kIllegalLanguageModeDirective,
1333 string);
1334 *ok = false;
1335 return nullptr;
1336 }
1337
1325 // Strong mode implies strict mode. If there are several "use strict" 1338 // Strong mode implies strict mode. If there are several "use strict"
1326 // / "use strong" directives, do the strict mode changes only once. 1339 // / "use strong" directives, do the strict mode changes only once.
1327 if (is_sloppy(scope_->language_mode())) { 1340 if (is_sloppy(scope_->language_mode())) {
1328 scope_->SetLanguageMode(static_cast<LanguageMode>( 1341 scope_->SetLanguageMode(static_cast<LanguageMode>(
1329 scope_->language_mode() | STRICT)); 1342 scope_->language_mode() | STRICT));
1330 } 1343 }
1331 1344
1332 if (use_strong_found) { 1345 if (use_strong_found) {
1333 scope_->SetLanguageMode(static_cast<LanguageMode>( 1346 scope_->SetLanguageMode(static_cast<LanguageMode>(
1334 scope_->language_mode() | STRONG)); 1347 scope_->language_mode() | STRONG));
(...skipping 2547 matching lines...) Expand 10 before | Expand all | Expand 10 after
3882 } 3895 }
3883 3896
3884 3897
3885 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 3898 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3886 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 3899 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3887 } 3900 }
3888 3901
3889 3902
3890 void ParserTraits::ParseArrowFunctionFormalParameters( 3903 void ParserTraits::ParseArrowFunctionFormalParameters(
3891 ParserFormalParameters* parameters, Expression* expr, 3904 ParserFormalParameters* parameters, Expression* expr,
3892 const Scanner::Location& params_loc, 3905 const Scanner::Location& params_loc, bool* ok) {
3893 Scanner::Location* duplicate_loc, bool* ok) {
3894 if (parameters->Arity() >= Code::kMaxArguments) { 3906 if (parameters->Arity() >= Code::kMaxArguments) {
3895 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); 3907 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
3896 *ok = false; 3908 *ok = false;
3897 return; 3909 return;
3898 } 3910 }
3899 3911
3900 // ArrowFunctionFormals :: 3912 // ArrowFunctionFormals ::
3901 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail) 3913 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail)
3902 // Tail 3914 // Tail
3903 // NonTailArrowFunctionFormals :: 3915 // NonTailArrowFunctionFormals ::
3904 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy) 3916 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy)
3905 // VariableProxy 3917 // VariableProxy
3906 // Tail :: 3918 // Tail ::
3907 // VariableProxy 3919 // VariableProxy
3908 // Spread(VariableProxy) 3920 // Spread(VariableProxy)
3909 // 3921 //
3910 // As we need to visit the parameters in left-to-right order, we recurse on 3922 // As we need to visit the parameters in left-to-right order, we recurse on
3911 // the left-hand side of comma expressions. 3923 // the left-hand side of comma expressions.
3912 // 3924 //
3913 if (expr->IsBinaryOperation()) { 3925 if (expr->IsBinaryOperation()) {
3914 BinaryOperation* binop = expr->AsBinaryOperation(); 3926 BinaryOperation* binop = expr->AsBinaryOperation();
3915 // The classifier has already run, so we know that the expression is a valid 3927 // The classifier has already run, so we know that the expression is a valid
3916 // arrow function formals production. 3928 // arrow function formals production.
3917 DCHECK_EQ(binop->op(), Token::COMMA); 3929 DCHECK_EQ(binop->op(), Token::COMMA);
3918 Expression* left = binop->left(); 3930 Expression* left = binop->left();
3919 Expression* right = binop->right(); 3931 Expression* right = binop->right();
3920 ParseArrowFunctionFormalParameters(parameters, left, params_loc, 3932 ParseArrowFunctionFormalParameters(parameters, left, params_loc, ok);
3921 duplicate_loc, ok);
3922 if (!*ok) return; 3933 if (!*ok) return;
3923 // LHS of comma expression should be unparenthesized. 3934 // LHS of comma expression should be unparenthesized.
3924 expr = right; 3935 expr = right;
3925 } 3936 }
3926 3937
3927 // Only the right-most expression may be a rest parameter. 3938 // Only the right-most expression may be a rest parameter.
3928 DCHECK(!parameters->has_rest); 3939 DCHECK(!parameters->has_rest);
3929 3940
3930 bool is_rest = expr->IsSpread(); 3941 bool is_rest = expr->IsSpread();
3931 if (is_rest) { 3942 if (is_rest) {
(...skipping 23 matching lines...) Expand all
3955 AddFormalParameter(parameters, expr, initializer, is_rest); 3966 AddFormalParameter(parameters, expr, initializer, is_rest);
3956 } 3967 }
3957 3968
3958 3969
3959 void ParserTraits::ParseArrowFunctionFormalParameterList( 3970 void ParserTraits::ParseArrowFunctionFormalParameterList(
3960 ParserFormalParameters* parameters, Expression* expr, 3971 ParserFormalParameters* parameters, Expression* expr,
3961 const Scanner::Location& params_loc, 3972 const Scanner::Location& params_loc,
3962 Scanner::Location* duplicate_loc, bool* ok) { 3973 Scanner::Location* duplicate_loc, bool* ok) {
3963 if (expr->IsEmptyParentheses()) return; 3974 if (expr->IsEmptyParentheses()) return;
3964 3975
3965 ParseArrowFunctionFormalParameters(parameters, expr, params_loc, 3976 ParseArrowFunctionFormalParameters(parameters, expr, params_loc, ok);
3966 duplicate_loc, ok);
3967 if (!*ok) return; 3977 if (!*ok) return;
3968 3978
3979 ExpressionClassifier classifier;
3980 if (!parameters->is_simple) {
3981 classifier.RecordNonSimpleParameter();
3982 }
3969 for (int i = 0; i < parameters->Arity(); ++i) { 3983 for (int i = 0; i < parameters->Arity(); ++i) {
3970 auto parameter = parameters->at(i); 3984 auto parameter = parameters->at(i);
3971 ExpressionClassifier classifier; 3985 DeclareFormalParameter(parameters->scope, parameter, &classifier);
3972 DeclareFormalParameter(
3973 parameters->scope, parameter, parameters->is_simple, &classifier);
3974 if (!duplicate_loc->IsValid()) { 3986 if (!duplicate_loc->IsValid()) {
3975 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; 3987 *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
3976 } 3988 }
3977 } 3989 }
3978 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); 3990 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters());
3979 } 3991 }
3980 3992
3981 3993
3982 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) { 3994 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) {
3983 if (parser_->function_state_->materialized_literal_count() > 0) { 3995 if (parser_->function_state_->materialized_literal_count() > 0) {
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
4578 SET_ALLOW(harmony_rest_parameters); 4590 SET_ALLOW(harmony_rest_parameters);
4579 SET_ALLOW(harmony_default_parameters); 4591 SET_ALLOW(harmony_default_parameters);
4580 SET_ALLOW(harmony_spreadcalls); 4592 SET_ALLOW(harmony_spreadcalls);
4581 SET_ALLOW(harmony_destructuring); 4593 SET_ALLOW(harmony_destructuring);
4582 SET_ALLOW(harmony_spread_arrays); 4594 SET_ALLOW(harmony_spread_arrays);
4583 SET_ALLOW(harmony_new_target); 4595 SET_ALLOW(harmony_new_target);
4584 SET_ALLOW(strong_mode); 4596 SET_ALLOW(strong_mode);
4585 #undef SET_ALLOW 4597 #undef SET_ALLOW
4586 } 4598 }
4587 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4599 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4588 language_mode(), function_state_->kind(), logger, bookmark); 4600 language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
4601 logger, bookmark);
4589 if (pre_parse_timer_ != NULL) { 4602 if (pre_parse_timer_ != NULL) {
4590 pre_parse_timer_->Stop(); 4603 pre_parse_timer_->Stop();
4591 } 4604 }
4592 return result; 4605 return result;
4593 } 4606 }
4594 4607
4595 4608
4596 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, 4609 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
4597 Scanner::Location class_name_location, 4610 Scanner::Location class_name_location,
4598 bool name_is_strict_reserved, int pos, 4611 bool name_is_strict_reserved, int pos,
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after
6090 6103
6091 Expression* Parser::SpreadCallNew(Expression* function, 6104 Expression* Parser::SpreadCallNew(Expression* function,
6092 ZoneList<v8::internal::Expression*>* args, 6105 ZoneList<v8::internal::Expression*>* args,
6093 int pos) { 6106 int pos) {
6094 args->InsertAt(0, function, zone()); 6107 args->InsertAt(0, function, zone());
6095 6108
6096 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6109 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6097 } 6110 }
6098 } // namespace internal 6111 } // namespace internal
6099 } // namespace v8 6112 } // 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