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

Unified 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: minor test cleanup Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 72967d6df43fd064f0a82943c61df55f7945656a..0a63caae2132d90d53276467bedfc4348254c27a 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1201,9 +1201,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
// BindingIdentifier
ParseFormalParameter(&formals, &formals_classifier, &ok);
if (ok) {
- DeclareFormalParameter(
- formals.scope, formals.at(0), formals.is_simple,
- &formals_classifier);
+ DeclareFormalParameter(formals.scope, formals.at(0),
+ &formals_classifier);
}
}
}
@@ -1325,6 +1324,21 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
token_loc.end_pos - token_loc.beg_pos ==
ast_value_factory()->use_strong_string()->length() + 2;
if (use_strict_found || use_strong_found) {
+ if (!scope_->HasSimpleParameters()) {
+ // A block declaration scope as a child scope of a function scope
+ // indicates that a function has a non-simple parameter list.
+ // TC39 deemed "use strict" directives to be an error in this case,
+ // on 29/7/2015. https://goo.gl/ueA7Ln
+ //
+ // In V8, this also applies to "use strong " directives.
+ const AstRawString* string = literal->raw_value()->AsString();
+ ParserTraits::ReportMessageAt(
+ token_loc, MessageTemplate::kIllegalLanguageModeDirective,
+ string);
+ *ok = false;
+ return nullptr;
+ }
+
// Strong mode implies strict mode. If there are several "use strict"
// / "use strong" directives, do the strict mode changes only once.
if (is_sloppy(scope_->language_mode())) {
@@ -3858,8 +3872,7 @@ Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
void ParserTraits::ParseArrowFunctionFormalParameters(
ParserFormalParameters* parameters, Expression* expr,
- const Scanner::Location& params_loc,
- Scanner::Location* duplicate_loc, bool* ok) {
+ const Scanner::Location& params_loc, bool* ok) {
if (parameters->Arity() >= Code::kMaxArguments) {
ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
*ok = false;
@@ -3886,8 +3899,7 @@ void ParserTraits::ParseArrowFunctionFormalParameters(
DCHECK_EQ(binop->op(), Token::COMMA);
Expression* left = binop->left();
Expression* right = binop->right();
- ParseArrowFunctionFormalParameters(parameters, left, params_loc,
- duplicate_loc, ok);
+ ParseArrowFunctionFormalParameters(parameters, left, params_loc, ok);
if (!*ok) return;
// LHS of comma expression should be unparenthesized.
expr = right;
@@ -3936,15 +3948,16 @@ void ParserTraits::ParseArrowFunctionFormalParameterList(
Scanner::Location* duplicate_loc, bool* ok) {
if (expr->IsEmptyParentheses()) return;
- ParseArrowFunctionFormalParameters(parameters, expr, params_loc,
- duplicate_loc, ok);
+ ParseArrowFunctionFormalParameters(parameters, expr, params_loc, ok);
if (!*ok) return;
+ ExpressionClassifier classifier;
+ if (!parameters->is_simple) {
+ classifier.RecordNonSimpleParameter();
+ }
for (int i = 0; i < parameters->Arity(); ++i) {
auto parameter = parameters->at(i);
- ExpressionClassifier classifier;
- DeclareFormalParameter(
- parameters->scope, parameter, parameters->is_simple, &classifier);
+ DeclareFormalParameter(parameters->scope, parameter, &classifier);
if (!duplicate_loc->IsValid()) {
*duplicate_loc = classifier.duplicate_formal_parameter_error().location;
}
@@ -4563,7 +4576,8 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
#undef SET_ALLOW
}
PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
- language_mode(), function_state_->kind(), logger, bookmark);
+ language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
+ logger, bookmark);
if (pre_parse_timer_ != NULL) {
pre_parse_timer_->Stop();
}

Powered by Google App Engine
This is Rietveld 408576698