Reviewers: cromwellian,

Description:
When JsStaticEval converts a number to a string, use the JS
conversion rules rather than the Java ones.


Please review this at http://gwt-code-reviews.appspot.com/335801/show

Affected files:
  M dev/core/src/com/google/gwt/dev/js/JsStaticEval.java
  M dev/core/test/com/google/gwt/dev/js/JsStaticEvalTest.java


Index: dev/core/src/com/google/gwt/dev/js/JsStaticEval.java
===================================================================
--- dev/core/src/com/google/gwt/dev/js/JsStaticEval.java        (revision 7879)
+++ dev/core/src/com/google/gwt/dev/js/JsStaticEval.java        (working copy)
@@ -47,6 +47,7 @@
 import com.google.gwt.dev.js.ast.JsVisitor;
 import com.google.gwt.dev.js.ast.JsWhile;
 import com.google.gwt.dev.js.ast.JsVars.JsVar;
+import com.google.gwt.dev.js.rhino.ScriptRuntime;

 import java.util.ArrayList;
 import java.util.EnumSet;
@@ -516,7 +517,7 @@
private boolean appendLiteral(StringBuilder result, JsValueLiteral val) {
       if (val instanceof JsNumberLiteral) {
         double number = ((JsNumberLiteral) val).getValue();
-        result.append(fixTrailingZeroes(String.valueOf(number)));
+        result.append(ScriptRuntime.numberToString(number, 10));
       } else if (val instanceof JsStringLiteral) {
         result.append(((JsStringLiteral) val).getValue());
       } else if (val instanceof JsBooleanLiteral) {
@@ -558,20 +559,6 @@
         jsBlock.getStatements().addAll(stmts);
         return jsBlock;
       }
-    }
-
-    /*
-     * String.valueOf(Double) produces trailing .0 on integers which is
- * incorrect for Javascript which produces conversions to string without
-     * trailing zeroes. Without this, int + String will turn out wrong.
-     */
-    private String fixTrailingZeroes(String num) {
-      if (num.endsWith(".0")) {
-        String fixNum = num.substring(0, num.length() - 2);
-        assert Double.parseDouble(fixNum) == Double.parseDouble(num);
-        num = fixNum;
-      }
-      return num;
     }

     private SourceInfo makeSourceInfo(HasSourceInfo x, String m) {
Index: dev/core/test/com/google/gwt/dev/js/JsStaticEvalTest.java
===================================================================
--- dev/core/test/com/google/gwt/dev/js/JsStaticEvalTest.java (revision 7879)
+++ dev/core/test/com/google/gwt/dev/js/JsStaticEvalTest.java   (working copy)
@@ -28,6 +28,7 @@
assertEquals("alert('42 Hello');", optimize("alert(42.0 + ' Hello');")); assertEquals("alert('42.2 Hello');", optimize("alert(42.2 + ' Hello');")); assertEquals("alert('Hello 42.2');", optimize("alert('Hello ' + 42.2);")); + assertEquals("alert('2004318071');", optimize("alert(2004318071 + '');"));
   }

   public void testAssociativity() throws Exception {


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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to