Skip to content

Commit

Permalink
Fix JS to Java exception conversion for UncaughtExceptionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
zbynek committed Dec 11, 2024
1 parent 6f9f451 commit bbda91d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
package org.gwtproject.core.client;

import com.google.gwt.junit.client.GWTTestCase;
import elemental2.dom.DomGlobal;
import java.util.ArrayList;
import java.util.List;

public class GWTTest extends GWTTestCase {

private List<Throwable> caught = new ArrayList<>();

@Override
public String getModuleName() {
return "org.gwtproject.core.Core";
Expand All @@ -32,4 +38,22 @@ public void testIsClient() {
assertTrue(GWT.isClient());
assertTrue(org.gwtproject.core.shared.GWT.isClient());
}

public void testReportUncaughtError() {
GWT.setUncaughtExceptionHandler(caught::add);
GWT.reportUncaughtException(new RuntimeException());
DomGlobal.setTimeout(
(ignore) -> {
assertEquals(1, caught.size());
assertEquals("java.lang.JsException", caught.get(0).getClass().getName());
finishTest();
},
1000);
delayTestFinish(3000);
}

@Override
public boolean catchExceptions() {
return false;
}
}
2 changes: 1 addition & 1 deletion gwt-core/src/main/java/org/gwtproject/core/client/GWT.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private static void addOnErrorHandler(Window window, Window.OnerrorFn onerrorFn)
@JsMethod
private static native Throwable fromObject(Object obj) /*-{
//GWT2 impl using JSNI, see GWT.native.js for the j2cl impl
var throwable = @java.lang.Throwable::of(*)(obj);
return @java.lang.Throwable::of(*)(obj);
}-*/;

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

0 comments on commit bbda91d

Please sign in to comment.