Fix issue 380.
authormikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 16 Jun 2009 11:47:00 +0000 (11:47 +0000)
committermikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 16 Jun 2009 11:47:00 +0000 (11:47 +0000)
Don't infer name for a function if a result of its call is assigned to a variable / property. E.g., in this case:

  a = function() { ... } ();

the function must remain anonymous because 'a' doesn't receive a function reference, but instead a result of its call.

BUG=http://code.google.com/p/v8/issues/detail?id=380
TEST=cctest/test-func-name-inference/Issue380

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2185 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/rewriter.cc
test/cctest/test-func-name-inference.cc

index e0a0226..4d1fbd9 100644 (file)
@@ -283,7 +283,10 @@ void AstOptimizer::VisitAssignment(Assignment* node) {
     case Token::ASSIGN:
       // No type can be infered from the general assignment.
 
-      scoped_fni.Enter();
+      // Don't infer if it is "a = function(){...}();"-like expression.
+      if (node->value()->AsCall() == NULL) {
+        scoped_fni.Enter();
+      }
       break;
     case Token::ASSIGN_BIT_OR:
     case Token::ASSIGN_BIT_XOR:
index 1bfc883..28e8649 100644 (file)
@@ -251,3 +251,17 @@ TEST(MultipleFuncsInLiteral) {
   CheckFunctionName(script, "return 1", "MyClass.method1");
   CheckFunctionName(script, "return 2", "MyClass.method1");
 }
+
+
+// See http://code.google.com/p/v8/issues/detail?id=380
+TEST(Issue380) {
+  InitializeVM();
+  v8::HandleScope scope;
+
+  v8::Handle<v8::Script> script = Compile(
+      "function a() {\n"
+      "var result = function(p,a,c,k,e,d)"
+      "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n"
+      "}");
+  CheckFunctionName(script, "return p", "");
+}