Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index ed6ff493133e54de3a27a2a267a5f2198b0e69e7..2c45f1503e55023b683a89a03871bb22776079cc 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -2842,8 +2842,11 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack, |
name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, |
CHECK_OK); |
} |
- result = ParseFunctionLiteral(name, is_strict_reserved_name, |
- function_token_position, NESTED, CHECK_OK); |
+ result = ParseFunctionLiteral(name, |
+ is_strict_reserved_name, |
+ function_token_position, |
+ EXPRESSION, |
+ CHECK_OK); |
} else { |
result = ParsePrimaryExpression(CHECK_OK); |
} |
@@ -3412,7 +3415,7 @@ ObjectLiteral::Property* Parser::ParseObjectLiteralGetSet(bool is_getter, |
ParseFunctionLiteral(name, |
false, // reserved words are allowed here |
RelocInfo::kNoPosition, |
- DECLARATION, |
+ EXPRESSION, |
CHECK_OK); |
// Allow any number of parameters for compatiabilty with JSC. |
// Specification only allows zero parameters for get and one for set. |
@@ -3619,25 +3622,23 @@ ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { |
} |
-FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, |
+FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name, |
bool name_is_strict_reserved, |
int function_token_position, |
FunctionLiteralType type, |
bool* ok) { |
// Function :: |
// '(' FormalParameterList? ')' '{' FunctionBody '}' |
- bool is_named = !var_name.is_null(); |
+ bool has_name = !function_name.is_null(); |
+ // The function's name, empty if the function is anonymous. |
+ if (!has_name) { |
+ function_name = isolate()->factory()->empty_symbol(); |
+ } |
- // The name associated with this function. If it's a function expression, |
- // this is the actual function name, otherwise this is the name of the |
- // variable declared and initialized with the function (expression). In |
- // that case, we don't have a function name (it's empty). |
Kevin Millikin (Chromium)
2011/08/04 16:32:09
I loved this comment, but I couldn't find a way to
|
- Handle<String> name = |
- is_named ? var_name : isolate()->factory()->empty_symbol(); |
- // The function name, if any. |
- Handle<String> function_name = isolate()->factory()->empty_symbol(); |
- if (is_named && (type == EXPRESSION || type == NESTED)) { |
- function_name = name; |
+ // The name of a named function expression, otherwise an empty handle. |
+ Handle<String> self_name; |
+ if (type == EXPRESSION && function_name->length() > 0) { |
+ self_name = function_name; |
} |
int num_parameters = 0; |
@@ -3655,7 +3656,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, |
bool has_duplicate_parameters = false; |
// Parse function body. |
{ LexicalScope lexical_scope(this, scope, isolate()); |
- top_scope_->SetScopeName(name); |
+ top_scope_->SetScopeName(function_name); |
// FormalParameterList :: |
// '(' (Identifier)*[','] ')' |
@@ -3705,10 +3706,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, |
// NOTE: We create a proxy and resolve it here so that in the |
// future we can change the AST to only refer to VariableProxies |
// instead of Variables and Proxis as is the case now. |
- if (!function_name.is_null() && function_name->length() > 0) { |
- Variable* fvar = top_scope_->DeclareFunctionVar(function_name); |
+ if (!self_name.is_null()) { |
+ Variable* fvar = top_scope_->DeclareFunctionVar(self_name); |
VariableProxy* fproxy = |
- top_scope_->NewUnresolved(function_name, inside_with()); |
+ top_scope_->NewUnresolved(self_name, inside_with()); |
fproxy->BindTo(fvar); |
body->Add(new(zone()) ExpressionStatement( |
new(zone()) Assignment(isolate(), |
@@ -3739,7 +3740,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, |
end_pos = entry.end_pos(); |
if (end_pos <= function_block_pos) { |
// End position greater than end of stream is safe, and hard to check. |
- ReportInvalidPreparseData(name, CHECK_OK); |
+ ReportInvalidPreparseData(function_name, CHECK_OK); |
} |
isolate()->counters()->total_preparse_skipped()->Increment( |
end_pos - function_block_pos); |
@@ -3769,7 +3770,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, |
// Validate strict mode. |
if (top_scope_->is_strict_mode()) { |
- if (IsEvalOrArguments(name)) { |
+ if (IsEvalOrArguments(function_name)) { |
int position = function_token_position != RelocInfo::kNoPosition |
? function_token_position |
: (start_pos > 0 ? start_pos - 1 : start_pos); |
@@ -3813,7 +3814,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, |
FunctionLiteral* function_literal = |
new(zone()) FunctionLiteral(isolate(), |
- name, |
+ function_name, |
scope, |
body, |
materialized_literal_count, |
@@ -3823,11 +3824,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, |
num_parameters, |
start_pos, |
end_pos, |
- (function_name->length() > 0), |
Kevin Millikin (Chromium)
2011/08/04 16:32:09
This is the is_expression flag. It incorrectly ca
|
+ type == EXPRESSION, |
has_duplicate_parameters); |
function_literal->set_function_token_position(function_token_position); |
- if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal); |
+ if (fni_ != NULL && !has_name) fni_->AddFunction(function_literal); |
return function_literal; |
} |