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

Unified Diff: src/parser.cc

Issue 7584005: Revert "Fix a bug in scope analysis." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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/parser.h ('k') | src/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 2c45f1503e55023b683a89a03871bb22776079cc..ed6ff493133e54de3a27a2a267a5f2198b0e69e7 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2842,11 +2842,8 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
CHECK_OK);
}
- result = ParseFunctionLiteral(name,
- is_strict_reserved_name,
- function_token_position,
- EXPRESSION,
- CHECK_OK);
+ result = ParseFunctionLiteral(name, is_strict_reserved_name,
+ function_token_position, NESTED, CHECK_OK);
} else {
result = ParsePrimaryExpression(CHECK_OK);
}
@@ -3415,7 +3412,7 @@ ObjectLiteral::Property* Parser::ParseObjectLiteralGetSet(bool is_getter,
ParseFunctionLiteral(name,
false, // reserved words are allowed here
RelocInfo::kNoPosition,
- EXPRESSION,
+ DECLARATION,
CHECK_OK);
// Allow any number of parameters for compatiabilty with JSC.
// Specification only allows zero parameters for get and one for set.
@@ -3622,23 +3619,25 @@ ZoneList<Expression*>* Parser::ParseArguments(bool* ok) {
}
-FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name,
+FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
bool name_is_strict_reserved,
int function_token_position,
FunctionLiteralType type,
bool* ok) {
// Function ::
// '(' FormalParameterList? ')' '{' FunctionBody '}'
- 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();
- }
+ bool is_named = !var_name.is_null();
- // 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;
+ // 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).
+ 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;
}
int num_parameters = 0;
@@ -3656,7 +3655,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name,
bool has_duplicate_parameters = false;
// Parse function body.
{ LexicalScope lexical_scope(this, scope, isolate());
- top_scope_->SetScopeName(function_name);
+ top_scope_->SetScopeName(name);
// FormalParameterList ::
// '(' (Identifier)*[','] ')'
@@ -3706,10 +3705,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_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 (!self_name.is_null()) {
- Variable* fvar = top_scope_->DeclareFunctionVar(self_name);
+ if (!function_name.is_null() && function_name->length() > 0) {
+ Variable* fvar = top_scope_->DeclareFunctionVar(function_name);
VariableProxy* fproxy =
- top_scope_->NewUnresolved(self_name, inside_with());
+ top_scope_->NewUnresolved(function_name, inside_with());
fproxy->BindTo(fvar);
body->Add(new(zone()) ExpressionStatement(
new(zone()) Assignment(isolate(),
@@ -3740,7 +3739,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_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(function_name, CHECK_OK);
+ ReportInvalidPreparseData(name, CHECK_OK);
}
isolate()->counters()->total_preparse_skipped()->Increment(
end_pos - function_block_pos);
@@ -3770,7 +3769,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name,
// Validate strict mode.
if (top_scope_->is_strict_mode()) {
- if (IsEvalOrArguments(function_name)) {
+ if (IsEvalOrArguments(name)) {
int position = function_token_position != RelocInfo::kNoPosition
? function_token_position
: (start_pos > 0 ? start_pos - 1 : start_pos);
@@ -3814,7 +3813,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name,
FunctionLiteral* function_literal =
new(zone()) FunctionLiteral(isolate(),
- function_name,
+ name,
scope,
body,
materialized_literal_count,
@@ -3824,11 +3823,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name,
num_parameters,
start_pos,
end_pos,
- type == EXPRESSION,
+ (function_name->length() > 0),
has_duplicate_parameters);
function_literal->set_function_token_position(function_token_position);
- if (fni_ != NULL && !has_name) fni_->AddFunction(function_literal);
+ if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal);
return function_literal;
}
« no previous file with comments | « src/parser.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698