JS: support [suspend] fun main([args: Array<String>]) (KT-26628, KT-26572 fixed)

This commit is contained in:
Anton Bannykh
2018-09-10 19:33:04 +03:00
committed by Denis Zharkov
parent 7e9704e50d
commit ead9b31e03
10 changed files with 226 additions and 3 deletions
+11
View File
@@ -0,0 +1,11 @@
// EXPECTED_REACHABLE_NODES: 1281
// IGNORE_BACKEND: JS_IR
// CALL_MAIN
var ok: String = "fail"
fun main() {
ok = "OK"
}
fun box() = ok
+14
View File
@@ -0,0 +1,14 @@
// EXPECTED_REACHABLE_NODES: 1281
// IGNORE_BACKEND: JS_IR
// CALL_MAIN
var ok: String = "fail"
fun main(args: Array<String>) {
assertEquals(1, args.size)
assertEquals("testArg", args[0])
ok = "OK"
}
fun box() = ok
+28
View File
@@ -0,0 +1,28 @@
// EXPECTED_REACHABLE_NODES: 1296
// IGNORE_BACKEND: JS_IR
// CALL_MAIN
import kotlin.coroutines.*
var ok: String = "fail"
var callback: () -> Unit = {}
suspend fun main(args: Array<String>) {
assertEquals(1, args.size)
assertEquals("testArg", args[0])
suspendCoroutine<Unit> { cont ->
callback = {
cont.resume(Unit)
}
}
ok = "OK"
}
fun box(): String {
assertEquals("fail", ok)
callback()
return ok
}
+25
View File
@@ -0,0 +1,25 @@
// EXPECTED_REACHABLE_NODES: 1296
// IGNORE_BACKEND: JS_IR
// CALL_MAIN
import kotlin.coroutines.*
var ok: String = "fail"
var callback: () -> Unit = {}
suspend fun main() {
suspendCoroutine<Unit> { cont ->
callback = {
cont.resume(Unit)
}
}
ok = "OK"
}
fun box(): String {
assertEquals("fail", ok)
callback()
return ok
}
+30
View File
@@ -0,0 +1,30 @@
// EXPECTED_REACHABLE_NODES: 1299
// IGNORE_BACKEND: JS_IR
// CALL_MAIN
import kotlin.coroutines.*
var callback: () -> Unit = {}
val exception = Exception()
suspend fun main() {
suspendCoroutine<Unit> { cont ->
callback = {
cont.resume(Unit)
}
}
throw exception
}
fun box(): String {
try {
callback()
} catch (e: Exception) {
assertTrue(e === exception)
}
return "OK"
}