From daeaa502d6f426626341ea3353b3b996ac8ea323 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 30 Jan 2019 14:32:43 +0300 Subject: [PATCH] JS: deobfuscate stack traces for wrapped native exceptions --- .../org/teavm/backend/javascript/runtime.js | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) 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 831e6ee46..1695b0610 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -228,28 +228,31 @@ function $rt_exception(ex) { } err.$javaException = ex; ex.$jsException = err; - if (typeof $rt_decodeStack === "function" && err.stack) { - var stack = $rt_decodeStack(err.stack); - var javaStack = $rt_createArray($rt_objcls(), stack.length); - var elem; - var noStack = false; - for (var i = 0; i < stack.length; ++i) { - var element = stack[i]; - elem = $rt_createStackElement($rt_str(element.className), - $rt_str(element.methodName), $rt_str(element.fileName), element.lineNumber); - if (elem == null) { - noStack = true; - break; - } - javaStack.data[i] = elem; - } - if (!noStack) { - $rt_setStack(ex, javaStack); - } - } + $rt_fillStack(err, ex); } return err; } +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 elem; + var noStack = false; + for (var i = 0; i < stack.length; ++i) { + var element = stack[i]; + elem = $rt_createStackElement($rt_str(element.className), + $rt_str(element.methodName), $rt_str(element.fileName), element.lineNumber); + if (elem == null) { + noStack = true; + break; + } + javaStack.data[i] = elem; + } + if (!noStack) { + $rt_setStack(ex, javaStack); + } + } +} function $rt_createMultiArray(cls, dimensions) { var first = 0; for (var i = dimensions.length - 1; i >= 0; i = (i - 1) | 0) { @@ -553,6 +556,7 @@ function $rt_wrapException(err) { ex = $rt_createException($rt_str("(JavaScript) " + err.toString())); err.$javaException = ex; ex.$jsException = err; + $rt_fillStack(err, ex); } return ex; }