[K/JS] Capture stackTrace before the init function call ^Fixed KT-55315

This commit is contained in:
Artem Kobzar
2022-12-20 18:15:02 +00:00
committed by Space Team
parent 48daf0befe
commit cd0ae20c38
6 changed files with 65 additions and 10 deletions
@@ -3627,6 +3627,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
runTest("js/js.translator/testData/box/expression/misc/safeCallComputesExpressionOnlyOnce.kt");
}
@Test
@TestMetadata("stackTraceAccessInsideInitBlock.kt")
public void testStackTraceAccessInsideInitBlock() throws Exception {
runTest("js/js.translator/testData/box/expression/misc/stackTraceAccessInsideInitBlock.kt");
}
@Test
@TestMetadata("stackTraceCapturing.kt")
public void testStackTraceCapturing() throws Exception {
@@ -4249,6 +4249,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
runTest("js/js.translator/testData/box/expression/misc/safeCallComputesExpressionOnlyOnce.kt");
}
@Test
@TestMetadata("stackTraceAccessInsideInitBlock.kt")
public void testStackTraceAccessInsideInitBlock() throws Exception {
runTest("js/js.translator/testData/box/expression/misc/stackTraceAccessInsideInitBlock.kt");
}
@Test
@TestMetadata("stackTraceCapturing.kt")
public void testStackTraceCapturing() throws Exception {
@@ -4249,6 +4249,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/expression/misc/safeCallComputesExpressionOnlyOnce.kt");
}
@Test
@TestMetadata("stackTraceAccessInsideInitBlock.kt")
public void testStackTraceAccessInsideInitBlock() throws Exception {
runTest("js/js.translator/testData/box/expression/misc/stackTraceAccessInsideInitBlock.kt");
}
@Test
@TestMetadata("stackTraceCapturing.kt")
public void testStackTraceCapturing() throws Exception {
@@ -0,0 +1,32 @@
// EXPECTED_REACHABLE_NODES: 1462
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND: JS
// KT-55315
var stackTrace: String = ""
open class MyOwnException1: Throwable("Test message 1") {
init {
stackTrace = asDynamic().stack
}
}
class MyOwnException2: MyOwnException1() {
init {
stackTrace = asDynamic().stack
}
}
fun box(): String {
try {
throw MyOwnException1()
} catch (e: Throwable) {
if (!stackTrace.contains("MyOwnException1: Test message 1\n")) return "fail"
}
try {
throw MyOwnException2()
} catch (e: Throwable) {
if (!stackTrace.contains("MyOwnException2: Test message 1\n")) return "fail"
}
return "OK"
}