From bf87826dd130b8a3908037bec079e43f34bcdcd5 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 27 Sep 2017 13:54:34 +0300 Subject: [PATCH] JS: add test to prove that KT-15622 is no more reproducible --- .../js/test/semantics/BoxJsTestGenerated.java | 6 +++ .../box/coroutines/nativeExceptions.kt | 53 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 js/js.translator/testData/box/coroutines/nativeExceptions.kt diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 707fac75316..132db01c201 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -925,6 +925,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/coroutines/localVarOptimization.kt"); doTest(fileName); } + + @TestMetadata("nativeExceptions.kt") + public void testNativeExceptions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/coroutines/nativeExceptions.kt"); + doTest(fileName); + } } @TestMetadata("js/js.translator/testData/box/crossModuleRef") diff --git a/js/js.translator/testData/box/coroutines/nativeExceptions.kt b/js/js.translator/testData/box/coroutines/nativeExceptions.kt new file mode 100644 index 00000000000..b610f0b5807 --- /dev/null +++ b/js/js.translator/testData/box/coroutines/nativeExceptions.kt @@ -0,0 +1,53 @@ +// EXPECTED_REACHABLE_NODES: 1123 +import kotlin.coroutines.experimental.* +import kotlin.coroutines.experimental.intrinsics.* + +private var next: () -> Unit = {} +private var stopped = false + +suspend fun delay(): Unit = suspendCoroutine { c -> + next = { c.resume(Unit) } +} + +fun build(c: suspend () -> Unit) { + c.startCoroutine(object : Continuation { + override fun resume(x: Unit) { + stopped = true + } + + override fun resumeWithException(x: Throwable) { + stopped = true + } + + override val context = EmptyCoroutineContext + }) +} + +fun box(): String { + var log = "" + + build { + try { + log += "before delay;" + delay() + log += "after delay;" + js("undefined").lalala + log += "ignore;" + } + catch (e: dynamic) { + log += "caught ${e.name};" + } + finally { + log += "finally;" + } + } + + while (!stopped) { + log += "@;" + next() + } + + if (log != "before delay;@;after delay;caught TypeError;finally;") return "fail: $log" + + return "OK" +} \ No newline at end of file