Skip to content

Commit bbda91d

Browse files
committed
Fix JS to Java exception conversion for UncaughtExceptionHandler
1 parent 6f9f451 commit bbda91d

File tree

2 files changed

+25
-1
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

+25
-1
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@
1616
package org.gwtproject.core.client;
1717

1818
import com.google.gwt.junit.client.GWTTestCase;
19+
import elemental2.dom.DomGlobal;
20+
import java.util.ArrayList;
21+
import java.util.List;
1922

2023
public class GWTTest extends GWTTestCase {
24+
25+
private List<Throwable> caught = new ArrayList<>();
26+
2127
@Override
2228
public String getModuleName() {
2329
return "org.gwtproject.core.Core";
@@ -32,4 +38,22 @@ public void testIsClient() {
3238
assertTrue(GWT.isClient());
3339
assertTrue(org.gwtproject.core.shared.GWT.isClient());
3440
}
41+
42+
public void testReportUncaughtError() {
43+
GWT.setUncaughtExceptionHandler(caught::add);
44+
GWT.reportUncaughtException(new RuntimeException());
45+
DomGlobal.setTimeout(
46+
(ignore) -> {
47+
assertEquals(1, caught.size());
48+
assertEquals("java.lang.JsException", caught.get(0).getClass().getName());
49+
finishTest();
50+
},
51+
1000);
52+
delayTestFinish(3000);
53+
}
54+
55+
@Override
56+
public boolean catchExceptions() {
57+
return false;
58+
}
3559
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private static void addOnErrorHandler(Window window, Window.OnerrorFn onerrorFn)
152152
@JsMethod
153153
private static native Throwable fromObject(Object obj) /*-{
154154
//GWT2 impl using JSNI, see GWT.native.js for the j2cl impl
155-
var throwable = @java.lang.Throwable::of(*)(obj);
155+
return @java.lang.Throwable::of(*)(obj);
156156
}-*/;
157157

158158
@JsType(isNative = true, name = "window", namespace = "<window>")

0 commit comments

Comments
 (0)