Revision: 9672
Author: [email protected]
Date: Fri Feb  4 08:47:41 2011
Log: Remove list of JavaScriptException object properties:
- In Development Mode: always
- In Production Mode: when compiler.stackTrace = emulated

Fixes Issues: 3974

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

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9672

Modified:
 /trunk/user/src/com/google/gwt/core/client/JavaScriptException.java
 /trunk/user/src/com/google/gwt/core/client/impl/StackTraceCreator.java
 /trunk/user/test/com/google/gwt/core/client/JavaScriptExceptionTest.java

=======================================
--- /trunk/user/src/com/google/gwt/core/client/JavaScriptException.java Thu Dec 16 11:33:51 2010 +++ /trunk/user/src/com/google/gwt/core/client/JavaScriptException.java Fri Feb 4 08:47:41 2011
@@ -74,30 +74,9 @@
   }-*/;

   private static String getProperties(Object e) {
-    return (e instanceof JavaScriptObject)
-        ? getProperties0((JavaScriptObject) e) : "";
-  }
-
-  /**
-   * Returns the list of properties of an unexpected JavaScript exception.
-   */
-  private static native String getProperties0(JavaScriptObject e) /*-{
-    var result = "";
-    try {
-      for (var prop in e) {
-        if (prop != "name" && prop != "message" && prop != "toString") {
-          try {
-            result += "\n " + prop + ": " + e[prop];
-          } catch (ignored) {
-            // Skip the property if it threw an exception.
-          }
-        }
-      }
-    } catch (ignored) {
-      // If we can't do "in" on the exception, just return what we have.
-    }
-    return result;
-  }-*/;
+    return (GWT.isScript() && e instanceof JavaScriptObject)
+        ? StackTraceCreator.getProperties((JavaScriptObject) e) : "";
+  }

   /**
    * The original description of the JavaScript exception this class wraps,
=======================================
--- /trunk/user/src/com/google/gwt/core/client/impl/StackTraceCreator.java Wed Jan 19 06:45:45 2011 +++ /trunk/user/src/com/google/gwt/core/client/impl/StackTraceCreator.java Fri Feb 4 08:47:41 2011
@@ -82,6 +82,27 @@
       }
       t.setStackTrace(stackTrace);
     }
+
+    /**
+ * Returns the list of properties of an unexpected JavaScript exception.
+     */
+    public native String getProperties(JavaScriptObject e) /*-{
+      var result = "";
+      try {
+        for (var prop in e) {
+          if (prop != "name" && prop != "message" && prop != "toString") {
+            try {
+              result += "\n " + prop + ": " + e[prop];
+            } catch (ignored) {
+              // Skip the property if it threw an exception.
+            }
+          }
+        }
+      } catch (ignored) {
+        // If we can't do "in" on the exception, just return what we have.
+      }
+      return result;
+    }-*/;

     /**
* Attempt to infer the stack from an unknown JavaScriptObject that had been
@@ -162,6 +183,17 @@
       t.setStackTrace(stackTrace);
     }

+    /**
+ * When compiler.stackMode = emulated, return an empty string, rather than a + * list of properties, since the additional information regarding the origin + * of the JavaScriptException, relative to compiled JavaScript source code,
+     * adds no real value, since we have fully emulated stack traces.
+     */
+    @Override
+    public String getProperties(JavaScriptObject e) {
+      return "";
+    }
+
     @Override
     public JsArrayString inferFrom(JavaScriptObject e) {
       throw new RuntimeException("Should not reach here");
@@ -388,6 +420,20 @@

     GWT.<Collector> create(Collector.class).fillInStackTrace(t);
   }
+
+  /**
+   * Returns the list of properties of an unexpected JavaScript exception,
+ * unless compiler.stackMode = emulated, in which case the empty string is
+   * returned. This method should only be called in Production Mode.
+   */
+  public static String getProperties(JavaScriptObject e) {
+    if (!GWT.isScript()) {
+      throw new RuntimeException(
+          "StackTraceCreator should only be called in Production Mode");
+    }
+
+    return GWT.<Collector> create(Collector.class).getProperties(e);
+  }

   /**
    * Create a stack trace based on the current execution stack. This method
=======================================
--- /trunk/user/test/com/google/gwt/core/client/JavaScriptExceptionTest.java Thu Dec 16 11:33:51 2010 +++ /trunk/user/test/com/google/gwt/core/client/JavaScriptExceptionTest.java Fri Feb 4 08:47:41 2011
@@ -16,6 +16,8 @@
 package com.google.gwt.core.client;

 import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.junit.client.WithProperties;
+import com.google.gwt.junit.client.WithProperties.Property;

 /**
* Any JavaScript exceptions occurring within JSNI methods are wrapped as this
@@ -53,6 +55,35 @@
@com.google.gwt.core.client.JavaScriptExceptionTest::throwJava(Ljava/lang/Throwable;)(t);
   }-*/;

+  public void assertJsoProperties(boolean extraPropertiesShouldBePresent) {
+    JavaScriptObject jso = makeJSO();
+    try {
+      throwNative(jso);
+      fail();
+    } catch (JavaScriptException e) {
+      assertEquals("myName", e.getName());
+      assertEquals("myDescription", e.getDescription());
+      assertSame(jso, e.getException());
+      assertTrue(e.getMessage().contains("myName"));
+      assertTrue(e.getMessage().contains("myDescription"));
+      if (extraPropertiesShouldBePresent) {
+        assertTrue(
+            "message does not contain 'extraField', but should: "
+                + e.getMessage(), e.getMessage().contains("extraField"));
+        assertTrue(
+            "message does not contain 'extraData', but should:"
+                + e.getMessage(), e.getMessage().contains("extraData"));
+      } else {
+        assertFalse(
+ "message contains 'extraField', but shouldn't: " + e.getMessage(),
+            e.getMessage().contains("extraField"));
+        assertFalse(
+ "message contains 'extraData', but shouldn't:" + e.getMessage(),
+            e.getMessage().contains("extraData"));
+      }
+    }
+  }
+
   /**
* This test doesn't work in Development Mode yet; we'd need a way to throw * true native objects as exceptions. Windows/IE is the deal killer right now
@@ -82,21 +113,46 @@
       assertSame(e, t);
     }
   }
-
-  public void testJso() {
-    JavaScriptObject jso = makeJSO();
-    try {
-      throwNative(jso);
-      fail();
-    } catch (JavaScriptException e) {
-      assertEquals("myName", e.getName());
-      assertEquals("myDescription", e.getDescription());
-      assertSame(jso, e.getException());
-      assertTrue(e.getMessage().contains("myName"));
-      assertTrue(e.getMessage().contains("myDescription"));
-      assertTrue(e.getMessage().contains("extraField"));
-      assertTrue(e.getMessage().contains("extraData"));
-    }
+
+  @WithProperties({
+    @Property(name = "compiler.stackMode", value = "emulated")
+  })
+  public void testJsoStackModeEmulated() {
+    /**
+     * Whether we're in Development Mode, or in Production Mode with
+ * compiler.stackMode = emulated, extra properties should not be present.
+     *
+     * @see StackTraceCreator#getProperties(JavaScriptObject)
+     */
+    assertJsoProperties(false);
+  }
+
+  @WithProperties({
+    @Property(name = "compiler.stackMode", value = "native")
+  })
+  public void testJsoStackModeNative() {
+    /**
+ * In Production Mode with compiler.stackMode = native, extra properties + * should be present. In Development Mode, extra properties should not be
+     * present.
+     *
+     * @see StackTraceCreator#getProperties(JavaScriptObject)
+     */
+    assertJsoProperties(GWT.isScript());
+  }
+
+  @WithProperties({
+    @Property(name = "compiler.stackMode", value = "strip")
+  })
+  public void testJsoStackModeStrip() {
+    /**
+     * In Production Mode with compiler.stackMode = strip, extra properties
+ * should be present. In Development Mode, extra properties should not be
+     * present.
+     *
+     * @see StackTraceCreator#getProperties(JavaScriptObject)
+     */
+    assertJsoProperties(GWT.isScript());
   }

   public void testNull() {

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

Reply via email to