1) Adds a test to MiscellaneousTest to ensure that virtual dispatch to String works correctly.
2) Removes an old typeName reference from GenerateJavaScriptAST
3) Fixes two problems in DeadCodeElimination's compile time determination of calls on String constants:
  a) String.hashCode() computed at compile time differs from our implementation
  b) The code could potentially break if some of the parameters had been pruned.

Patch by: scottb, zundel


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1632 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
index 210ba0e..dcd896a 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
@@ -671,6 +671,17 @@
       if (method.getType() == program.getTypeVoid()) {
         return;
       }
+      
+      if (method.getOriginalParamTypes().size() != method.params.size()) {
+        // One or more parameters were pruned, abort.
+        return;
+      }
+      
+      if (method.getName().endsWith("hashCode")) {
+        // This cannot be computed at compile time because our implementation
+        // differs from the JRE.
+        return;
+      }
 
       int skip = 0;
       Object instance;
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
index 32f6a92..b06740c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
@@ -1649,7 +1649,6 @@
 
     // Object fields
     specialObfuscatedIdents.put("typeId", "tI");
-    specialObfuscatedIdents.put("typeName", "tN");
 
     // String polymorphic
     specialObfuscatedIdents.put("charAt", "cA");
diff --git a/user/test/com/google/gwt/dev/jjs/test/MiscellaneousTest.java b/user/test/com/google/gwt/dev/jjs/test/MiscellaneousTest.java
index b2adab6..31f6f2a 100644
--- a/user/test/com/google/gwt/dev/jjs/test/MiscellaneousTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/MiscellaneousTest.java
@@ -61,7 +61,7 @@
     }
 
     private static native void clinitInNative() /*-{
-    }-*/;
+                }-*/;
 
     private int foo() {
       this.toString();
@@ -70,8 +70,8 @@
   }
 
   public static native boolean noOptimizeFalse() /*-{
-    return false;
-  }-*/;
+        return false;
+      }-*/;
 
   private static void assertAllCanStore(Object[] dest, Object[] src) {
     for (int i = 0; i < src.length; ++i) {
@@ -90,20 +90,20 @@
   }
 
   private static native void clinitFromNative() /*-{
-    @com.google.gwt.dev.jjs.test.MiscellaneousTest$HasClinit::i = 5;
-  }-*/;
+        @com.google.gwt.dev.jjs.test.MiscellaneousTest$HasClinit::i = 5;
+      }-*/;
 
   private static native Foo getFoo() /*-{
-    return {};
-  }-*/;
+        return {};
+      }-*/;
 
   private static native JavaScriptObject getJso() /*-{
-    return {toString:function(){return 'jso';}}; 
-  }-*/;
+        return {toString:function(){return 'jso';}}; 
+      }-*/;
 
   private static native void throwNativeException() /*-{
-    var a; a.asdf();
-  }-*/;
+        var a; a.asdf();
+      }-*/;
 
   public String getModuleName() {
     return "com.google.gwt.dev.jjs.CompilerSuite";
@@ -345,6 +345,37 @@
             + false + null + 'c' + 27));
   }
 
+  /**
+   * Ensures that polymorphic dispatch to String works correctly.
+   */
+  @SuppressWarnings("unchecked")
+  public void testStringPrototype() {
+    Object s = noOptimizeFalse() ? new Object() : "Hello, World!";
+    assertEquals(String.class, s.getClass());
+    assertEquals("Hello, World!".hashCode(), s.hashCode());
+    assertTrue(s.equals("Hello, World!"));
+    assertTrue("Hello, World!".equals(s));
+    assertFalse(s.equals(""));
+    assertFalse("".equals(s));
+    assertEquals("Hello, World!", s.toString());
+    assertTrue(s instanceof String);
+
+    Comparable b = noOptimizeFalse() ? new Integer(1) : "Hello, World!";
+    assertTrue(((Comparable) "Hello, World!").compareTo(b) == 0);
+    assertTrue(b.compareTo("Hello, World!") == 0);
+    assertTrue(((Comparable) "A").compareTo(b) < 0);
+    assertTrue(b.compareTo("A") > 0);
+    assertTrue(((Comparable) "Z").compareTo(b) > 0);
+    assertTrue(b.compareTo("Z") < 0);
+    assertTrue(b instanceof String);
+
+    CharSequence c = noOptimizeFalse() ? new StringBuffer() : "Hello, World!";
+    assertEquals('e', c.charAt(1));
+    assertEquals(13, c.length());
+    assertEquals("ello", c.subSequence(1, 5));
+    assertTrue(c instanceof String);
+  }
+
   public String toString() {
     return "com.google.gwt.dev.jjs.test.MiscellaneousTest";
   }