Reduces JSNI in JRE tests
Change-Id: I89f13db6aa4a11af300df3456a26fa7f79a6518e
Review-Link: https://gwt-review.googlesource.com/#/c/18580/
diff --git a/user/super/com/google/gwt/emul/java/lang/NullPointerException.java b/user/super/com/google/gwt/emul/java/lang/NullPointerException.java
index 2425878..3bb6113 100644
--- a/user/super/com/google/gwt/emul/java/lang/NullPointerException.java
+++ b/user/super/com/google/gwt/emul/java/lang/NullPointerException.java
@@ -15,7 +15,6 @@
*/
package java.lang;
-import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;
/**
@@ -41,7 +40,7 @@
return new NativeTypeError(msg);
}
- @JsType(isNative = true, name = "TypeError", namespace = JsPackage.GLOBAL)
+ @JsType(isNative = true, name = "TypeError", namespace = "<window>")
private static class NativeTypeError {
NativeTypeError(String msg) { }
}
diff --git a/user/super/com/google/gwt/emul/java/lang/Throwable.java b/user/super/com/google/gwt/emul/java/lang/Throwable.java
index e636ec3..589e7aa 100644
--- a/user/super/com/google/gwt/emul/java/lang/Throwable.java
+++ b/user/super/com/google/gwt/emul/java/lang/Throwable.java
@@ -25,7 +25,6 @@
import javaemul.internal.JsUtils;
import javaemul.internal.annotations.DoNotInline;
import jsinterop.annotations.JsMethod;
-import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
@@ -297,11 +296,11 @@
return e instanceof NativeTypeError ? new NullPointerException(e) : new JsException(e);
}
- @JsType(isNative = true, name = "Error", namespace = JsPackage.GLOBAL)
+ @JsType(isNative = true, name = "Error", namespace = "<window>")
private static class NativeError {
NativeError(String msg) { }
}
- @JsType(isNative = true, name = "TypeError", namespace = JsPackage.GLOBAL)
+ @JsType(isNative = true, name = "TypeError", namespace = "<window>")
private static class NativeTypeError { }
}
diff --git a/user/test/com/google/gwt/core/client/impl/StackTraceEmulTest.java b/user/test/com/google/gwt/core/client/impl/StackTraceEmulTest.java
index 4553093..6a3822a 100644
--- a/user/test/com/google/gwt/core/client/impl/StackTraceEmulTest.java
+++ b/user/test/com/google/gwt/core/client/impl/StackTraceEmulTest.java
@@ -67,7 +67,7 @@
String[] methodNames = getTraceJava();
StackTraceElement[] expectedTrace = new StackTraceElement[] {
- createSTE(methodNames[0], "Throwable.java", 67),
+ createSTE(methodNames[0], "Throwable.java", 66),
createSTE(methodNames[1], "Exception.java", 29),
createSTE(methodNames[2], "StackTraceExamples.java", 57),
createSTE(methodNames[3], "StackTraceExamples.java", 52),
diff --git a/user/test/com/google/gwt/emultest/java/lang/JsExceptionTest.java b/user/test/com/google/gwt/emultest/java/lang/JsExceptionTest.java
index 245ee41..0040c55 100644
--- a/user/test/com/google/gwt/emultest/java/lang/JsExceptionTest.java
+++ b/user/test/com/google/gwt/emultest/java/lang/JsExceptionTest.java
@@ -18,6 +18,10 @@
import com.google.gwt.testing.TestUtils;
+import jsinterop.annotations.JsMethod;
+import jsinterop.annotations.JsPackage;
+import jsinterop.annotations.JsType;
+
/**
* Unit tests for JsException behavior.
*/
@@ -37,21 +41,21 @@
}
public void testCatchJava() {
- Object jso = makeJSO();
- Exception e = createJsException(jso);
- assertJsException(jso, catchJava(createThrower(e)));
+ Object obj = new Object();
+ Exception e = createJsException(obj);
+ assertJsException(obj, catchJava(createThrower(e)));
}
public void testCatchNative() {
- Object jso = makeJSO();
- Exception e = createJsException(jso);
- assertSame(jso, catchNative(createThrower(e)));
+ Object obj = new Object();
+ Exception e = createJsException(obj);
+ assertSame(obj, catchNative(createThrower(e)));
}
public void testCatchNativePropagatedFromFinally() {
- Object jso = makeJSO();
- Exception e = createJsException(jso);
- assertSame(jso, catchNative(wrapWithFinally(createThrower(e))));
+ Object obj = new Object();
+ Exception e = createJsException(obj);
+ assertSame(obj, catchNative(wrapWithFinally(createThrower(e))));
assertTrue(keepFinallyAlive);
}
@@ -70,17 +74,14 @@
}
public void testJavaNativeJavaSandwichCatch() {
- Object jso = makeJSO();
- Exception e = createJsException(jso);
- assertJsException(jso, javaNativeJavaSandwich(e));
+ Object obj = new Object();
+ Exception e = createJsException(obj);
+ assertJsException(obj, javaNativeJavaSandwich(e));
}
public void testCatchThrowNative() {
Object e;
- e = makeJSO();
- assertJsException(e, catchJava(createNativeThrower(e)));
-
e = "testing";
assertJsException(e, catchJava(createNativeThrower(e)));
@@ -95,9 +96,6 @@
public void testNativeJavaNativeSandwichCatch() {
Object e;
- e = makeJSO();
- assertSame(e, nativeJavaNativeSandwich(e));
-
e = "testing";
assertEquals(e, nativeJavaNativeSandwich(e));
// Devmode will not preserve the same String instance
@@ -125,12 +123,16 @@
}
}
- private static native void throwTypeError() /*-{
- "dummy".notExistsWillThrowTypeError();
- }-*/;
+ private static void throwTypeError() {
+ Object nullObject = null;
+ nullObject.toString();
+ }
- private static void assertTypeError(RuntimeException e) {
- assertInstanceOf("TypeError", getBackingJsObject(e));
+ @JsType(isNative = true, namespace = "<window>")
+ private static class TypeError { }
+
+ protected static void assertTypeError(RuntimeException e) {
+ assertTrue(getBackingJsObject(e) instanceof TypeError);
assertTrue(e.toString().contains("TypeError"));
}
@@ -143,26 +145,24 @@
}
}
- private static native void throwSvgError() /*-{
- // In Firefox, this throws an object (not Error):
- $doc.createElementNS("http://www.w3.org/2000/svg", "text").getBBox();
+ private static void throwSvgError() {
+ // In old Firefox, this throws an object (not Error):
+ createElementNS("http://www.w3.org/2000/svg", "text").getBBox();
// For other browsers, make sure an exception is thrown to keep the test simple
- throw new Error("NS_ERROR_FAILURE");
- }-*/;
+ throw new RuntimeException("NS_ERROR_FAILURE");
+ }
+
+ @JsMethod(name = "document.createElementNS", namespace = JsPackage.GLOBAL)
+ private static native SVGElement createElementNS(String arg1, String arg2);
+
+ @JsType(isNative = true, namespace = JsPackage.GLOBAL)
+ private interface SVGElement {
+ void getBBox();
+ }
private static void assertJsException(Object expected, Throwable exception) {
assertTrue(exception instanceof RuntimeException);
assertEquals(expected, getBackingJsObject(exception));
}
-
- private static native Object makeJSO() /*-{
- return {
- toString : function() {
- return "jso";
- },
- name : "myName",
- message : "myDescription",
- };
- }-*/;
}
diff --git a/user/test/com/google/gwt/emultest/java/lang/NullPointerExceptionTest.java b/user/test/com/google/gwt/emultest/java/lang/NullPointerExceptionTest.java
index 750f21b..900d97c 100644
--- a/user/test/com/google/gwt/emultest/java/lang/NullPointerExceptionTest.java
+++ b/user/test/com/google/gwt/emultest/java/lang/NullPointerExceptionTest.java
@@ -17,6 +17,8 @@
import com.google.gwt.testing.TestUtils;
+import jsinterop.annotations.JsType;
+
/**
* Unit tests for the GWT emulation of java.lang.NullPointerException class.
*/
@@ -27,6 +29,9 @@
return "com.google.gwt.emultest.EmulSuite";
}
+ @JsType(isNative = true, namespace = "<window>")
+ private static class TypeError { }
+
public void testBackingJsObject() {
// Do not run the test in JVM.
if (TestUtils.isJvm()) {
@@ -34,7 +39,7 @@
}
Object caughtNative = catchNative(createThrower(new NullPointerException("<my msg>")));
- assertInstanceOf("TypeError", caughtNative);
+ assertTrue(caughtNative instanceof TypeError);
assertTrue(caughtNative.toString().startsWith("TypeError:"));
assertTrue(caughtNative.toString().contains("<my msg>"));
assertTrue(caughtNative.toString().contains(NullPointerException.class.getName()));
diff --git a/user/test/com/google/gwt/emultest/java/lang/ThrowableTest.java b/user/test/com/google/gwt/emultest/java/lang/ThrowableTest.java
index bb08ca7..8e72a6f 100644
--- a/user/test/com/google/gwt/emultest/java/lang/ThrowableTest.java
+++ b/user/test/com/google/gwt/emultest/java/lang/ThrowableTest.java
@@ -17,6 +17,8 @@
import com.google.gwt.testing.TestUtils;
+import jsinterop.annotations.JsType;
+
/**
* Unit tests for the GWT emulation of java.lang.Throwable class.
*/
@@ -72,7 +74,7 @@
}
Throwable e = new Throwable("<my msg>");
Object caughtNative = catchNative(createThrower(e));
- assertInstanceOf("Error", caughtNative);
+ assertTrue(caughtNative instanceof Error);
assertTrue(caughtNative.toString().contains("<my msg>"));
assertTrue(caughtNative.toString().contains(Throwable.class.getName()));
}
@@ -89,7 +91,7 @@
};
Object caughtNative = catchNative(createThrower(e));
- assertInstanceOf("Error", caughtNative);
+ assertTrue(caughtNative instanceof Error);
assertTrue(caughtNative.toString().contains("<my msg>"));
assertTrue(caughtNative.toString().contains(e.getClass().getName()));
}
@@ -101,4 +103,7 @@
Throwable e = new Throwable();
assertSame(e, javaNativeJavaSandwich(e));
}
+
+ @JsType(isNative = true, namespace = "<window>")
+ private static class Error { }
}
diff --git a/user/test/com/google/gwt/emultest/java/lang/ThrowableTestBase.java b/user/test/com/google/gwt/emultest/java/lang/ThrowableTestBase.java
index 08f24dc..c5bea6f 100644
--- a/user/test/com/google/gwt/emultest/java/lang/ThrowableTestBase.java
+++ b/user/test/com/google/gwt/emultest/java/lang/ThrowableTestBase.java
@@ -71,8 +71,4 @@
protected Throwable javaNativeJavaSandwich(Throwable e) {
return catchJava(createNativeThrower(catchNative(createThrower(e))));
}
-
- protected static native void assertInstanceOf(String expectedType, Object e) /*-{
- return e instanceof window[expectedType];
- }-*/;
-}
\ No newline at end of file
+}
diff --git a/user/test/org/apache/commons/collections/TestMap.java b/user/test/org/apache/commons/collections/TestMap.java
index 1825d5e..1c4cf29 100644
--- a/user/test/org/apache/commons/collections/TestMap.java
+++ b/user/test/org/apache/commons/collections/TestMap.java
@@ -25,6 +25,9 @@
import java.util.Map;
import java.util.Set;
+import jsinterop.annotations.JsPackage;
+import jsinterop.annotations.JsProperty;
+
/**
* Tests base {@link java.util.Map} methods and contracts.
* <p>
@@ -370,12 +373,11 @@
if (TestUtils.isJvm()) {
return null;
}
- return getUndefined0();
+ return getUndefinedImpl();
}
- private static native Object getUndefined0() /*-{
- return undefined;
- }-*/;
+ @JsProperty(name = "undefined", namespace = JsPackage.GLOBAL)
+ private native static Object getUndefinedImpl();
/**
* Test to ensure the test setup is working properly. This method checks