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

Unified Diff: src/parsing/preparser.cc

Issue 1900033003: Disallow generator declarations in certain locations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: src/parsing/preparser.cc
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc
index 8b059b1bea0e320c149c6c5426a837ebe9f55a3a..fc9cb2b279c06b0ad954dd805cbc95cfa30b79b2 100644
--- a/src/parsing/preparser.cc
+++ b/src/parsing/preparser.cc
@@ -278,7 +278,7 @@ PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) {
(legacy && allow_harmony_restrictive_declarations())) {
return ParseSubStatement(kDisallowLabelledFunctionStatement, ok);
} else {
- return ParseFunctionDeclaration(CHECK_OK);
+ return ParseOnlyFunctionDeclaration(ok);
}
}
@@ -546,6 +546,30 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
return Statement::Default();
}
+PreParser::Statement PreParser::ParseOnlyFunctionDeclaration(bool* ok) {
+ Consume(Token::FUNCTION);
+ int pos = position();
+ bool is_generator = Check(Token::MUL);
+ if (allow_harmony_restrictive_declarations() && is_generator) {
+ PreParserTraits::ReportMessageAt(
+ scanner()->location(),
+ MessageTemplate::kGeneratorInLegacyContext);
+ *ok = false;
+ return Statement::Default();
+ }
+ bool is_strict_reserved = false;
+ Identifier name =
+ ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
+ ParseFunctionLiteral(name, scanner()->location(),
+ is_strict_reserved ? kFunctionNameIsStrictReserved
+ : kFunctionNameValidityUnknown,
+ is_generator ? FunctionKind::kGeneratorFunction
+ : FunctionKind::kNormalFunction,
+ pos, FunctionLiteral::kDeclaration,
adamk 2016/04/20 19:09:28 This is a lot of boilerplate to copy; what if you
Dan Ehrenberg 2016/04/26 22:24:19 Done
+ language_mode(), CHECK_OK);
+ return Statement::FunctionDeclaration();
+}
+
PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(
AllowLabelledFunctionStatement allow_function, bool* ok) {
// ExpressionStatement | LabelledStatement ::
@@ -583,7 +607,7 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(
// ES#sec-labelled-function-declarations Labelled Function Declarations
if (peek() == Token::FUNCTION && is_sloppy(language_mode())) {
if (allow_function == kAllowLabelledFunctionStatement) {
- return ParseFunctionDeclaration(ok);
+ return ParseOnlyFunctionDeclaration(ok);
} else {
return ParseScopedStatement(true, ok);
}

Powered by Google App Engine
This is Rietveld 408576698