Revision: 9508
Author:   [email protected]
Date:     Mon Oct  3 12:18:05 2011
Log: Fix incorrect function name inference in case of assignment / global assignment.

[email protected]
BUG=v8:1732
TEST=test-func-name-inference/GlobalAssignmentAndCall,AssignmentAndCall

Review URL: http://codereview.chromium.org/8112007
http://code.google.com/p/v8/source/detail?r=9508

Modified:
 /branches/bleeding_edge/src/func-name-inferrer.h
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/test/cctest/test-func-name-inference.cc

=======================================
--- /branches/bleeding_edge/src/func-name-inferrer.h Wed Jun 22 13:23:48 2011 +++ /branches/bleeding_edge/src/func-name-inferrer.h Mon Oct 3 12:18:05 2011
@@ -69,6 +69,12 @@
       funcs_to_infer_.Add(func_to_infer);
     }
   }
+
+  void RemoveLastFunction() {
+    if (IsOpen() && !funcs_to_infer_.is_empty()) {
+      funcs_to_infer_.RemoveLast();
+    }
+  }

   // Infers a function name and leaves names collection state.
   void Infer() {
=======================================
--- /branches/bleeding_edge/src/parser.cc       Wed Sep 21 05:27:07 2011
+++ /branches/bleeding_edge/src/parser.cc       Mon Oct  3 12:18:05 2011
@@ -1765,6 +1765,8 @@
           value->AsCall() == NULL &&
           value->AsCallNew() == NULL) {
         fni_->Infer();
+      } else {
+        fni_->RemoveLastFunction();
       }
     }

@@ -2515,6 +2517,8 @@
          || op == Token::ASSIGN)
         && (right->AsCall() == NULL && right->AsCallNew() == NULL)) {
       fni_->Infer();
+    } else {
+      fni_->RemoveLastFunction();
     }
     fni_->Leave();
   }
=======================================
--- /branches/bleeding_edge/test/cctest/test-func-name-inference.cc Fri Sep 9 15:39:47 2011 +++ /branches/bleeding_edge/test/cctest/test-func-name-inference.cc Mon Oct 3 12:18:05 2011
@@ -361,3 +361,42 @@
   // 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");
+}

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to