JS: fix stack trace decoder with new CCE support

This commit is contained in:
Alexey Andreev 2021-03-17 21:49:06 +03:00
parent 4c0c7872a1
commit 67c639b875
2 changed files with 14 additions and 1 deletions

View File

@ -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,
"<init>", 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;

View File

@ -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) {