Revision: 8040
Author: [email protected]
Date: Mon May  3 10:39:37 2010
Log: Fixing division by zero while evaluating constant expression.

Review at http://gwt-code-reviews.appspot.com/435801

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

Modified:
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluator.java /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluatorTest.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluator.java Tue Mar 9 10:54:56 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluator.java Mon May 3 10:39:37 2010
@@ -133,7 +133,11 @@
         case SUB:
           return new JIntLiteral(x.getSourceInfo(), a - b);
         case DIV:
-          return new JIntLiteral(x.getSourceInfo(), a / b);
+          if (b != 0) {
+            return new JIntLiteral(x.getSourceInfo(), a / b);
+          } else {
+            return null;
+          }
         case EQ:
           return JBooleanLiteral.get(a == b);
         case NEQ:
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluatorTest.java Tue Mar 9 10:54:56 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluatorTest.java Mon May 3 10:39:37 2010
@@ -69,6 +69,9 @@
     assertThat("1 + i", "int", "int i; i = 1;").evaluatesInto("<null>");
     assertThat("2 + i", "int", "int i = 1;").evaluatesInto("3");
     assertThat("i + 3", "int", "int i = 1;").evaluatesInto("4");
+    assertThat("i / 2", "int", "int i = 6;").evaluatesInto("3");
+    assertThat("i / 0", "int", "int i = 1;").evaluatesInto("<null>");
+    assertThat("4 / 0", "int", "int i = 0;").evaluatesInto("<null>");
   }

   private static class Result {

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

Reply via email to