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

Unified Diff: src/preparser.cc

Issue 1281163002: [parser] partially revert "use-strict directives in function body affect init block" Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « src/preparser.h ('k') | src/scopes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index ec0ea2de3a04ba42bf5b32a54722420fb33de5d7..49f43b75d643168ad6dddd577f174fa02a8bcb8d 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()) {
+ // 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.
+ 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
@@ -1052,7 +1073,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;
@@ -1119,7 +1140,8 @@ void PreParser::ParseLazyFunctionLiteralBody(bool* ok,
log_->LogFunction(body_start, body_end,
function_state_->materialized_literal_count(),
function_state_->expected_property_count(), language_mode(),
- scope_->uses_super_property(), scope_->calls_eval());
+ scope_->uses_super_property(), scope_->calls_eval(),
+ scope_->has_simple_parameters());
}
« no previous file with comments | « src/preparser.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698