From 9aa25ad1a0fb04a7e76b181b7dff3b6876f12c52 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Thu, 14 Mar 2013 14:29:10 +0000 Subject: [PATCH] Allow inlining of functions containing function literals. R=yangguo@chromium.org BUG=v8:1322 TEST=mjsunit/compiler/inline-literals Review URL: https://codereview.chromium.org/10702036 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13945 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/ast.cc | 2 +- test/mjsunit/compiler/inline-literals.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ast.cc b/src/ast.cc index 02c815c..f1967c2 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -1040,6 +1040,7 @@ REGULAR_NODE(Conditional) REGULAR_NODE(Literal) REGULAR_NODE(ObjectLiteral) REGULAR_NODE(RegExpLiteral) +REGULAR_NODE(FunctionLiteral) REGULAR_NODE(Assignment) REGULAR_NODE(Throw) REGULAR_NODE(Property) @@ -1071,7 +1072,6 @@ DONT_OPTIMIZE_NODE(DebuggerStatement) DONT_OPTIMIZE_NODE(SharedFunctionInfoLiteral) DONT_INLINE_NODE(ArrayLiteral) // TODO(1322): Allow materialized literals. -DONT_INLINE_NODE(FunctionLiteral) DONT_SELFOPTIMIZE_NODE(DoWhileStatement) DONT_SELFOPTIMIZE_NODE(WhileStatement) diff --git a/test/mjsunit/compiler/inline-literals.js b/test/mjsunit/compiler/inline-literals.js index 1422586..4487996 100644 --- a/test/mjsunit/compiler/inline-literals.js +++ b/test/mjsunit/compiler/inline-literals.js @@ -87,3 +87,24 @@ TestRegExpLiteral("-b", "reg", "exp", "-expreg"); %OptimizeFunctionOnNextCall(TestRegExpLiteral); TestRegExpLiteral("ab", "reg", "exp", "regexpexpreg"); TestRegExpLiteral("ab", 12345, 54321, "6666666666"); + +function f2(b, c) { + var closure = function(b, c) { return b + c; } + var value = b + c; + return closure; +} + +function f1(a, b, c) { + return a + f2(b, c)(b, c); +} + +function TestFunctionLiteral(a, b, c, expected) { + var result = f1(a, b, c); + assertEquals(expected, result, "TestFunctionLiteral"); +} + +TestFunctionLiteral(1, 2, 3, 6); +TestFunctionLiteral(4, 5, 6, 15); +%OptimizeFunctionOnNextCall(TestFunctionLiteral); +TestFunctionLiteral(7, 8, 9, 24); +TestFunctionLiteral("a", "b", "c", "abc"); -- 2.7.4