diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java index 9d3fee864..1692275d1 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java @@ -37,6 +37,7 @@ import org.teavm.vm.RenderingException; public class RuntimeRenderer { private static final String STRING_CLASS = String.class.getName(); private static final String THREAD_CLASS = Thread.class.getName(); + private static final String STE_CLASS = StackTraceElement.class.getName(); private static final MethodReference NPE_INIT_METHOD = new MethodReference(NullPointerException.class, "", void.class); @@ -68,6 +69,7 @@ public class RuntimeRenderer { renderRuntimeString(); renderRuntimeUnwrapString(); renderRuntimeObjcls(); + renderRuntimeThrowablecls(); renderRuntimeNullCheck(); renderRuntimeIntern(); renderRuntimeThreads(); @@ -190,6 +192,17 @@ public class RuntimeRenderer { writer.append("function $rt_objcls() { return ").appendClass("java.lang.Object").append("; }").newLine(); } + private void renderRuntimeThrowablecls() throws IOException { + writer.append("function $rt_stecls()").ws().append("{").indent().softNewLine(); + writer.append("return "); + if (classSource.get(STE_CLASS) != null) { + writer.appendClass(STE_CLASS); + } else { + writer.appendClass("java.lang.Object"); + } + writer.append(";").softNewLine().outdent().append("}").newLine(); + } + private void renderRuntimeThreads() throws IOException { ClassReader threadCls = classSource.get(THREAD_CLASS); MethodReader currentThreadMethod = threadCls != null ? threadCls.getMethod(CURRENT_THREAD_METHOD) : null; diff --git a/core/src/main/resources/org/teavm/backend/javascript/runtime.js b/core/src/main/resources/org/teavm/backend/javascript/runtime.js index a9ebb2443..eac6e1c74 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -297,7 +297,7 @@ function $rt_exception(ex) { function $rt_fillStack(err, ex) { if (typeof $rt_decodeStack === "function" && err.stack) { var stack = $rt_decodeStack(err.stack); - var javaStack = $rt_createArray($rt_objcls(), stack.length); + var javaStack = $rt_createArray($rt_stecls(), stack.length); var elem; var noStack = false; for (var i = 0; i < stack.length; ++i) {