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); |
} |