Skip to content

Commit ec0e3d1

Browse files
Zbynek Konecnyzbynek
Zbynek Konecny
authored andcommitted
Throw JS exception instead of Java wrapping object
1 parent bbda91d commit ec0e3d1

File tree

2 files changed

+13
-8
lines changed
  • gwt-core/src/main/java/org/gwtproject/core/client
  • gwt-core-gwt2-tests/src/test/java/org/gwtproject/core/client

2 files changed

+13
-8
lines changed

gwt-core-gwt2-tests/src/test/java/org/gwtproject/core/client/GWTTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void testReportUncaughtError() {
4545
DomGlobal.setTimeout(
4646
(ignore) -> {
4747
assertEquals(1, caught.size());
48-
assertEquals("java.lang.JsException", caught.get(0).getClass().getName());
48+
assertEquals("java.lang.RuntimeException", caught.get(0).getClass().getName());
4949
finishTest();
5050
},
5151
1000);

gwt-core/src/main/java/org/gwtproject/core/client/GWT.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import elemental2.dom.DomGlobal;
1919
import elemental2.dom.Window;
20+
import jsinterop.annotations.JsFunction;
2021
import jsinterop.annotations.JsMethod;
2122
import jsinterop.annotations.JsType;
2223
import jsinterop.base.Js;
@@ -58,11 +59,10 @@ public static <T> T create(Class<?> clazz) {
5859
public static void reportUncaughtException(Throwable e) {
5960
// throw an exception "later" so that it ends up handled by the global
6061
// error handler. Same code as in GWT2's Impl.reportToBrowser()
61-
DomGlobal.setTimeout(
62-
ignore -> {
63-
throw_(e);
64-
},
65-
0);
62+
setTimeout(
63+
() -> {
64+
throw e;
65+
});
6666
}
6767

6868
/**
@@ -160,8 +160,13 @@ private static class InnerWindow {
160160
static Window window;
161161
}
162162

163-
@JsMethod(namespace = "<window>", name = "throw")
164-
private static native void throw_(Object object);
163+
@JsFunction
164+
private interface Throwing {
165+
void run() throws Throwable;
166+
}
167+
168+
@JsMethod(namespace = "<window>", name = "setTimeout")
169+
private static native void setTimeout(Throwing throwingFunction);
165170

166171
public static boolean isClient() {
167172
return org.gwtproject.core.shared.GWT.isClient();

0 commit comments

Comments
 (0)