Fix incorrect function name inference in case of assignment / global assignment.

R=kmillikin@chromium.org
BUG=v8:1732
TEST=test-func-name-inference/GlobalAssignmentAndCall,AssignmentAndCall

Review URL: http://codereview.chromium.org/8112007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9508 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a4e01037
......@@ -70,6 +70,12 @@ class FuncNameInferrer : public ZoneObject {
}
}
void RemoveLastFunction() {
if (IsOpen() && !funcs_to_infer_.is_empty()) {
funcs_to_infer_.RemoveLast();
}
}
// Infers a function name and leaves names collection state.
void Infer() {
ASSERT(IsOpen());
......
......@@ -1765,6 +1765,8 @@ Block* Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
value->AsCall() == NULL &&
value->AsCallNew() == NULL) {
fni_->Infer();
} else {
fni_->RemoveLastFunction();
}
}
......@@ -2515,6 +2517,8 @@ Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) {
|| op == Token::ASSIGN)
&& (right->AsCall() == NULL && right->AsCallNew() == NULL)) {
fni_->Infer();
} else {
fni_->RemoveLastFunction();
}
fni_->Leave();
}
......
......@@ -361,3 +361,42 @@ TEST(FactoryHashmapConditional) {
// Can't infer the function name statically.
CheckFunctionName(script, "return 1", "obj.(anonymous function)");
}
TEST(GlobalAssignmentAndCall) {
InitializeVM();
v8::HandleScope scope;
v8::Handle<v8::Script> script = Compile(
"var Foo = function() {\n"
" return 1;\n"
"}();\n"
"var Baz = Bar = function() {\n"
" return 2;\n"
"}");
// The inferred name is empty, because this is an assignment of a result.
CheckFunctionName(script, "return 1", "");
// See MultipleAssignments test.
CheckFunctionName(script, "return 2", "Bar");
}
TEST(AssignmentAndCall) {
InitializeVM();
v8::HandleScope scope;
v8::Handle<v8::Script> script = Compile(
"(function Enclosing() {\n"
" var Foo;\n"
" Foo = function() {\n"
" return 1;\n"
" }();\n"
" var Baz = Bar = function() {\n"
" return 2;\n"
" }\n"
"})();");
// The inferred name is empty, because this is an assignment of a result.
CheckFunctionName(script, "return 1", "");
// See MultipleAssignments test.
CheckFunctionName(script, "return 2", "Enclosing.Bar");
}
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