Commit 988d5fe5 authored by marja@chromium.org's avatar marja@chromium.org

Parser & preparser unification: make the ParseFunctionLiteral APIs the same.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/190853011

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19763 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e25d51cc
...@@ -3360,14 +3360,14 @@ Expression* Parser::ParseMemberExpression(bool* ok) { ...@@ -3360,14 +3360,14 @@ Expression* Parser::ParseMemberExpression(bool* ok) {
Handle<String> name; Handle<String> name;
bool is_strict_reserved_name = false; bool is_strict_reserved_name = false;
Scanner::Location function_name_location = Scanner::Location::invalid(); Scanner::Location function_name_location = Scanner::Location::invalid();
FunctionLiteral::FunctionType function_type =
FunctionLiteral::ANONYMOUS_EXPRESSION;
if (peek_any_identifier()) { if (peek_any_identifier()) {
name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
CHECK_OK); CHECK_OK);
function_name_location = scanner()->location(); function_name_location = scanner()->location();
function_type = FunctionLiteral::NAMED_EXPRESSION;
} }
FunctionLiteral::FunctionType function_type = name.is_null()
? FunctionLiteral::ANONYMOUS_EXPRESSION
: FunctionLiteral::NAMED_EXPRESSION;
result = ParseFunctionLiteral(name, result = ParseFunctionLiteral(name,
function_name_location, function_name_location,
is_strict_reserved_name, is_strict_reserved_name,
......
...@@ -347,7 +347,7 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { ...@@ -347,7 +347,7 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
// 'function' '*' Identifier '(' FormalParameterListopt ')' // 'function' '*' Identifier '(' FormalParameterListopt ')'
// '{' FunctionBody '}' // '{' FunctionBody '}'
Expect(Token::FUNCTION, CHECK_OK); Expect(Token::FUNCTION, CHECK_OK);
int pos = position();
bool is_generator = allow_generators() && Check(Token::MUL); bool is_generator = allow_generators() && Check(Token::MUL);
bool is_strict_reserved = false; bool is_strict_reserved = false;
Identifier name = ParseIdentifierOrStrictReservedWord( Identifier name = ParseIdentifierOrStrictReservedWord(
...@@ -356,6 +356,8 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { ...@@ -356,6 +356,8 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
scanner()->location(), scanner()->location(),
is_strict_reserved, is_strict_reserved,
is_generator, is_generator,
pos,
FunctionLiteral::DECLARATION,
CHECK_OK); CHECK_OK);
return Statement::FunctionDeclaration(); return Statement::FunctionDeclaration();
} }
...@@ -1063,20 +1065,25 @@ PreParser::Expression PreParser::ParseMemberExpression(bool* ok) { ...@@ -1063,20 +1065,25 @@ PreParser::Expression PreParser::ParseMemberExpression(bool* ok) {
Expression result = Expression::Default(); Expression result = Expression::Default();
if (peek() == Token::FUNCTION) { if (peek() == Token::FUNCTION) {
Consume(Token::FUNCTION); Consume(Token::FUNCTION);
int function_token_position = position();
bool is_generator = allow_generators() && Check(Token::MUL); bool is_generator = allow_generators() && Check(Token::MUL);
Identifier name = Identifier::Default(); Identifier name = Identifier::Default();
bool is_strict_reserved_name = false; bool is_strict_reserved_name = false;
Scanner::Location function_name_location = Scanner::Location::invalid(); Scanner::Location function_name_location = Scanner::Location::invalid();
FunctionLiteral::FunctionType function_type =
FunctionLiteral::ANONYMOUS_EXPRESSION;
if (peek_any_identifier()) { if (peek_any_identifier()) {
name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
CHECK_OK); CHECK_OK);
function_name_location = scanner()->location(); function_name_location = scanner()->location();
function_type = FunctionLiteral::NAMED_EXPRESSION;
} }
result = ParseFunctionLiteral(name, result = ParseFunctionLiteral(name,
function_name_location, function_name_location,
is_strict_reserved_name, is_strict_reserved_name,
is_generator, is_generator,
function_token_position,
function_type,
CHECK_OK); CHECK_OK);
} else { } else {
result = ParsePrimaryExpression(CHECK_OK); result = ParsePrimaryExpression(CHECK_OK);
...@@ -1162,6 +1169,8 @@ PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) { ...@@ -1162,6 +1169,8 @@ PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) {
scanner()->location(), scanner()->location(),
false, // reserved words are allowed here false, // reserved words are allowed here
false, // not a generator false, // not a generator
RelocInfo::kNoPosition,
FunctionLiteral::ANONYMOUS_EXPRESSION,
CHECK_OK); CHECK_OK);
if (peek() != Token::RBRACE) { if (peek() != Token::RBRACE) {
Expect(Token::COMMA, CHECK_OK); Expect(Token::COMMA, CHECK_OK);
...@@ -1232,6 +1241,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -1232,6 +1241,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
Scanner::Location function_name_location, Scanner::Location function_name_location,
bool name_is_strict_reserved, bool name_is_strict_reserved,
bool is_generator, bool is_generator,
int function_token_pos,
FunctionLiteral::FunctionType function_type,
bool* ok) { bool* ok) {
// Function :: // Function ::
// '(' FormalParameterList? ')' '{' FunctionBody '}' // '(' FormalParameterList? ')' '{' FunctionBody '}'
......
...@@ -903,6 +903,8 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -903,6 +903,8 @@ class PreParser : public ParserBase<PreParserTraits> {
Scanner::Location function_name_location, Scanner::Location function_name_location,
bool name_is_strict_reserved, bool name_is_strict_reserved,
bool is_generator, bool is_generator,
int function_token_pos,
FunctionLiteral::FunctionType function_type,
bool* ok); bool* ok);
void ParseLazyFunctionLiteralBody(bool* ok); void ParseLazyFunctionLiteralBody(bool* ok);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment