Skip to content

Commit

Permalink
Throw JS exception instead of Java wrapping object
Browse files Browse the repository at this point in the history
  • Loading branch information
Zbynek Konecny authored and zbynek committed Dec 11, 2024
1 parent bbda91d commit ec0e3d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testReportUncaughtError() {
DomGlobal.setTimeout(
(ignore) -> {
assertEquals(1, caught.size());
assertEquals("java.lang.JsException", caught.get(0).getClass().getName());
assertEquals("java.lang.RuntimeException", caught.get(0).getClass().getName());
finishTest();
},
1000);
Expand Down
19 changes: 12 additions & 7 deletions gwt-core/src/main/java/org/gwtproject/core/client/GWT.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import elemental2.dom.DomGlobal;
import elemental2.dom.Window;
import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;
import jsinterop.base.Js;
Expand Down Expand Up @@ -58,11 +59,10 @@ public static <T> T create(Class<?> clazz) {
public static void reportUncaughtException(Throwable e) {
// throw an exception "later" so that it ends up handled by the global
// error handler. Same code as in GWT2's Impl.reportToBrowser()
DomGlobal.setTimeout(
ignore -> {
throw_(e);
},
0);
setTimeout(
() -> {
throw e;
});
}

/**
Expand Down Expand Up @@ -160,8 +160,13 @@ private static class InnerWindow {
static Window window;
}

@JsMethod(namespace = "<window>", name = "throw")
private static native void throw_(Object object);
@JsFunction
private interface Throwing {
void run() throws Throwable;
}

@JsMethod(namespace = "<window>", name = "setTimeout")
private static native void setTimeout(Throwing throwingFunction);

public static boolean isClient() {
return org.gwtproject.core.shared.GWT.isClient();
Expand Down

0 comments on commit ec0e3d1

Please sign in to comment.