Fix JsInliner improperly inlining array, object, and function literals.
Patch by: cromwellian
Review by: spoon, scottb
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6404 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/js/JsInliner.java b/dev/core/src/com/google/gwt/dev/js/JsInliner.java
index 0a8b1a2..02373c6 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsInliner.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsInliner.java
@@ -98,6 +98,16 @@
}
@Override
+ public void endVisit(JsArrayLiteral x, JsContext<JsExpression> ctx) {
+ affectedBySideEffects = true;
+ }
+
+ @Override
+ public void endVisit(JsFunction x, JsContext<JsExpression> ctx) {
+ affectedBySideEffects = true;
+ }
+
+ @Override
public void endVisit(JsInvocation x, JsContext<JsExpression> ctx) {
/*
* We could make this more accurate by analyzing the function that's being
@@ -126,6 +136,11 @@
*/
affectedBySideEffects = true;
}
+
+ @Override
+ public void endVisit(JsObjectLiteral x, JsContext<JsExpression> ctx) {
+ affectedBySideEffects = true;
+ }
}
/**
diff --git a/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java b/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java
index b652df4..4debe87 100644
--- a/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java
+++ b/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java
@@ -28,6 +28,7 @@
public class JsInlinerTest extends OptimizerTestBase {
private static class FixStaticRefsVisitor extends JsModVisitor {
+
public static void exec(JsProgram program) {
(new FixStaticRefsVisitor()).accept(program);
}
@@ -35,13 +36,35 @@
@Override
public void endVisit(JsFunction x, JsContext<JsExpression> ctx) {
JsName name = x.getName();
- name.setStaticRef(x);
+ if (name != null) {
+ name.setStaticRef(x);
+ }
}
}
+ public void testInlineArrayLiterals() throws Exception {
+ String input = "function a1(arg, x) { arg.x = x; return arg; }"
+ + "function b1() { var x=a1([], 10); } b1();";
+ compare(input, input);
+ }
+
+ public void testInlineFunctionLiterals() throws Exception {
+ String input = "function a1(arg, x) { arg.x = x; return arg; }"
+ + "function b1() { var x=a1(function (){}, 10); } b1();";
+ compare(input, input);
+ String input2 = "function a1(arg, x) { arg.x = x; return arg; }"
+ + "function b1() { var x=a1(function blah(){}, 10); } b1();";
+ compare(input2, input2);
+ }
+
+ public void testInlineObjectLiterals() throws Exception {
+ String input = "function a1(arg, x) { arg.x = x; return arg; }"
+ + "function b1() { var x=a1({}, 10); } b1();";
+ compare(input, input);
+ }
/**
* A test for mutually-recursive functions. Setup:
- *
+ *
* <pre>
* a -> b, c
* b -> a, c
@@ -71,6 +94,7 @@
input = optimize(input, JsSymbolResolver.class, FixStaticRefsVisitor.class,
JsInliner.class, JsUnusedFunctionRemover.class);
expected = optimize(expected);
+ System.err.println("Input vs ");
assertEquals(expected, input);
}
}