Reviewers: cromwellian, scottb, jgw, knorton, jaimeyap,
Description:
Fixes issue 4301: ensures all strings "generated" by GWT are JS string
values.
Note that, in prod mode, even an assertSame(s, s.toString()) failed!
Please review this at http://gwt-code-reviews.appspot.com/1623803/
Affected files:
M user/super/com/google/gwt/emul/java/lang/String.java
M user/test/com/google/gwt/emultest/java/lang/StringTest.java
Index: user/super/com/google/gwt/emul/java/lang/String.java
diff --git a/user/super/com/google/gwt/emul/java/lang/String.java
b/user/super/com/google/gwt/emul/java/lang/String.java
index
1eb19646d93a8e6c9b2a4a262e48fbc8ea7c0de5..b35acf04c464fa1c7325f744161f462eab38c717
100644
--- a/user/super/com/google/gwt/emul/java/lang/String.java
+++ b/user/super/com/google/gwt/emul/java/lang/String.java
@@ -957,9 +957,10 @@ public final class String implements
Comparable<String>, CharSequence,
}-*/;
@Override
- public String toString() {
- return this;
- }
+ public native String toString() /*-{
+ // make sure GWT strings are always JS string values (see issue 4301)
+ return String(this);
+ }-*/;
public native String toUpperCase() /*-{
return this.toUpperCase();
Index: user/test/com/google/gwt/emultest/java/lang/StringTest.java
diff --git a/user/test/com/google/gwt/emultest/java/lang/StringTest.java
b/user/test/com/google/gwt/emultest/java/lang/StringTest.java
index
46d0efb9562189a7d17b0d17365f0fe8aaf53f26..a94705c210d13cda35dd2fbe2ab860db1db9f2b7
100644
--- a/user/test/com/google/gwt/emultest/java/lang/StringTest.java
+++ b/user/test/com/google/gwt/emultest/java/lang/StringTest.java
@@ -16,6 +16,7 @@
package com.google.gwt.emultest.java.lang;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.junit.client.GWTTestCase;
import java.io.UnsupportedEncodingException;
@@ -601,6 +602,13 @@ public class StringTest extends GWTTestCase {
}
}
+ public void testToString() {
+ Object s = Math.random() < 1 ? "abc" : JavaScriptObject.createObject();
+ assertSame(s, s.toString());
+ // issue 4301
+ assertTrue("issue4301", isJsStringValue(s.toString()));
+ }
+
/*
* TODO: needs rewriting to avoid compiler optimizations.
*/
@@ -666,6 +674,10 @@ public class StringTest extends GWTTestCase {
}
}
+ private native boolean isJsStringValue(String s) /*-{
+ return typeof s == 'string';
+ }-*/;
+
private String returnNull() {
return null;
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors