Reviewers: Mads Ager,
Description:
Fix issue 380.
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
Please review this at http://codereview.chromium.org/126195
Affected files:
M src/rewriter.cc
M test/cctest/test-func-name-inference.cc
Index: src/rewriter.cc
diff --git a/src/rewriter.cc b/src/rewriter.cc
index
e0a0226ec8b8dda96a87357776d995f7fbddb6b9..4d1fbd9dd7a973c757145b82ae7a5e0096515880
100644
--- a/src/rewriter.cc
+++ b/src/rewriter.cc
@@ -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: test/cctest/test-func-name-inference.cc
diff --git a/test/cctest/test-func-name-inference.cc
b/test/cctest/test-func-name-inference.cc
index
1bfc8834aba321300b7b844c64a4c120a84b9ea2..28e8649f9fd2677a196faef79e7676cecee5d124
100644
--- a/test/cctest/test-func-name-inference.cc
+++ b/test/cctest/test-func-name-inference.cc
@@ -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", "");
+}
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---