Clear pending functions list in FuncNameInferrer when it closes
authoryurys@chromium.org <yurys@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 24 May 2012 12:41:55 +0000 (12:41 +0000)
committeryurys@chromium.org <yurys@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 24 May 2012 12:41:55 +0000 (12:41 +0000)
BUG=v8:2146
Review URL: https://chromiumcodereview.appspot.com/10414075

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

src/func-name-inferrer.h
test/cctest/test-func-name-inference.cc

index 1a572683260a1d89ab6fd670edeb8036554f8eb0..ccd962a9826af2d81d04f780f6ebca02be574f87 100644 (file)
@@ -88,6 +88,8 @@ class FuncNameInferrer : public ZoneObject {
   void Leave() {
     ASSERT(IsOpen());
     names_stack_.Rewind(entries_stack_.RemoveLast());
+    if (entries_stack_.is_empty())
+      funcs_to_infer_.Clear();
   }
 
  private:
index 8f405b726e2dfca24eb60360edb0585917710886..762cc9f0fab1eae4406914222112edb8ef3855eb 100644 (file)
@@ -400,3 +400,41 @@ TEST(AssignmentAndCall) {
   // See MultipleAssignments test.
   CheckFunctionName(script, "return 2", "Enclosing.Bar");
 }
+
+
+TEST(MethodAssignmentInAnonymousFunctionCall) {
+  InitializeVM();
+  v8::HandleScope scope;
+
+  v8::Handle<v8::Script> script = Compile(
+      "(function () {\n"
+      "    var EventSource = function () { };\n"
+      "    EventSource.prototype.addListener = function () {\n"
+      "        return 2012;\n"
+      "    };\n"
+      "    this.PublicEventSource = EventSource;\n"
+      "})();");
+  CheckFunctionName(script, "return 2012", "EventSource.addListener");
+}
+
+
+TEST(ReturnAnonymousFunction) {
+  InitializeVM();
+  v8::HandleScope scope;
+
+  v8::Handle<v8::Script> script = Compile(
+      "(function() {\n"
+      "  function wrapCode() {\n"
+      "    return function () {\n"
+      "      return 2012;\n"
+      "    };\n"
+      "  };\n"
+      "  var foo = 10;\n"
+      "  function f() {\n"
+      "    return wrapCode();\n"
+      "  }\n"
+      "  this.ref = f;\n"
+      "})()");
+  script->Run();
+  CheckFunctionName(script, "return 2012", "");
+}