From a5c629cc11a4ab615e7cf37fb48c8027b9ccdcef Mon Sep 17 00:00:00 2001 From: "yurys@chromium.org" Date: Fri, 31 May 2013 12:52:28 +0000 Subject: [PATCH] Fix function name inferring inside closures BUG=224884 R=loislo@chromium.org, yangguo@chromium.org Review URL: https://codereview.chromium.org/16125007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14903 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/parser.cc | 1 + test/cctest/test-func-name-inference.cc | 51 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/parser.cc b/src/parser.cc index a93600f960..6b53cb5356 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -3435,6 +3435,7 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) { top_scope_->DeclarationScope()->RecordEvalCall(); } result = factory()->NewCall(result, args, pos); + if (fni_ != NULL) fni_->RemoveLastFunction(); break; } diff --git a/test/cctest/test-func-name-inference.cc b/test/cctest/test-func-name-inference.cc index a86dfd28a1..dcc6272a39 100644 --- a/test/cctest/test-func-name-inference.cc +++ b/test/cctest/test-func-name-inference.cc @@ -258,6 +258,57 @@ TEST(MultipleFuncsInLiteral) { } +TEST(AnonymousInAnonymousClosure1) { + CcTest::InitializeVM(); + v8::HandleScope scope(CcTest::isolate()); + + v8::Handle script = Compile( + "(function() {\n" + " (function() {\n" + " var a = 1;\n" + " return;\n" + " })();\n" + " var b = function() {\n" + " var c = 1;\n" + " return;\n" + " };\n" + "})();"); + CheckFunctionName(script, "return", ""); +} + + +TEST(AnonymousInAnonymousClosure2) { + CcTest::InitializeVM(); + v8::HandleScope scope(CcTest::isolate()); + + v8::Handle script = Compile( + "(function() {\n" + " (function() {\n" + " var a = 1;\n" + " return;\n" + " })();\n" + " var c = 1;\n" + "})();"); + CheckFunctionName(script, "return", ""); +} + + +TEST(NamedInAnonymousClosure) { + CcTest::InitializeVM(); + v8::HandleScope scope(CcTest::isolate()); + + v8::Handle script = Compile( + "var foo = function() {\n" + " (function named() {\n" + " var a = 1;\n" + " })();\n" + " var c = 1;\n" + " return;\n" + "};"); + CheckFunctionName(script, "return", "foo"); +} + + // See http://code.google.com/p/v8/issues/detail?id=380 TEST(Issue380) { CcTest::InitializeVM();