Revision: 6404
Author: cromwellian
Date: Fri Oct 16 16:16:55 2009
Log: Fix JsInliner improperly inlining array, object, and function literals.
Patch by: cromwellian
Review by: spoon, scottb

http://code.google.com/p/google-web-toolkit/source/detail?r=6404

Modified:
  /trunk/dev/core/src/com/google/gwt/dev/js/JsInliner.java
  /trunk/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/js/JsInliner.java    Mon Jun 22  
10:19:32 2009
+++ /trunk/dev/core/src/com/google/gwt/dev/js/JsInliner.java    Fri Oct 16  
16:16:55 2009
@@ -96,6 +96,16 @@
      public boolean affectedBySideEffects() {
        return affectedBySideEffects;
      }
+
+    @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) {
@@ -126,6 +136,11 @@
         */
        affectedBySideEffects = true;
      }
+
+    @Override
+    public void endVisit(JsObjectLiteral x, JsContext<JsExpression> ctx) {
+      affectedBySideEffects = true;
+    }
    }

    /**
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java       Mon Jun 
 
22 10:19:32 2009
+++ /trunk/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java       Fri Oct 
 
16 16:16:55 2009
@@ -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);
    }
  }

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to