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

Unified Diff: src/preparser.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/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index b1541f616afe133554881e99aec4f71a9f5e45e0..b1e6ad8309661e590156c7c15df1235c44cb8729 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -102,8 +102,8 @@ PreParserExpression PreParserTraits::ParseFunctionLiteral(
PreParser::PreParseResult PreParser::PreParseLazyFunction(
- LanguageMode language_mode, FunctionKind kind, ParserRecorder* log,
- Scanner::BookmarkScope* bookmark) {
+ LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters,
+ ParserRecorder* log, Scanner::BookmarkScope* bookmark) {
log_ = log;
// Lazy functions always have trivial outer scopes (no with/catch scopes).
Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE);
@@ -113,6 +113,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
scope_->SetLanguageMode(language_mode);
Scope* function_scope = NewScope(
scope_, IsArrowFunction(kind) ? ARROW_SCOPE : FUNCTION_SCOPE, kind);
+ if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters();
PreParserFactory function_factory(NULL);
FunctionState function_state(&function_state_, &scope_, function_scope, kind,
&function_factory);
@@ -251,15 +252,35 @@ void PreParser::ParseStatementList(int end_token, bool* ok,
}
if (directive_prologue) {
- if (statement.IsUseStrictLiteral()) {
+ bool use_strict_found = statement.IsUseStrictLiteral();
+ bool use_strong_found =
+ statement.IsUseStrongLiteral() && allow_strong_mode();
+
+ if (use_strict_found) {
scope_->SetLanguageMode(
static_cast<LanguageMode>(scope_->language_mode() | STRICT));
- } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) {
+ } else if (use_strong_found) {
scope_->SetLanguageMode(static_cast<LanguageMode>(
scope_->language_mode() | STRONG));
} else if (!statement.IsStringLiteral()) {
directive_prologue = false;
}
+
+ if (use_strict_found || use_strong_found) {
+ if (!scope_->HasSimpleParameters()) {
rossberg 2015/08/24 13:11:08 Nit: merge conditions
conradw 2015/08/25 11:31:20 Done.
+ // A block declaration scope as a child scope of a function scope
rossberg 2015/08/24 13:11:08 Not sure how the comment relates to the code. Whic
conradw 2015/08/25 11:31:20 I think this is referring to HasSimpleParameters l
+ // 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.
+ PreParserTraits::ReportMessageAt(
+ token_loc, MessageTemplate::kIllegalLanguageModeDirective,
+ use_strict_found ? "use strict" : "use strong");
+ *ok = false;
+ return;
+ }
+ }
}
// If we're allowed to reset to a bookmark, we will do so when we see a long
@@ -1057,7 +1078,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
Expect(Token::LPAREN, CHECK_OK);
int start_position = scanner()->location().beg_pos;
function_scope->set_start_position(start_position);
- PreParserFormalParameters formals(nullptr);
+ PreParserFormalParameters formals(function_scope);
ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
int formals_end_position = scanner()->location().end_pos;

Powered by Google App Engine
This is Rietveld 408576698