[K/JS] Change js-call inlining strategy and + ability to referencethis safely from the js call ^Fixed KT-54134

This commit is contained in:
Artem Kobzar
2022-11-30 11:43:22 +00:00
committed by Space Team
parent b1f2f733fe
commit 67048151fb
7 changed files with 105 additions and 65 deletions
@@ -814,6 +814,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
runTest("js/js.translator/testData/box/coroutines/dynamicSuspendReturnWithOperator.kt");
}
@Test
@TestMetadata("jsCallInsideCoroutine.kt")
public void testJsCallInsideCoroutine() throws Exception {
runTest("js/js.translator/testData/box/coroutines/jsCallInsideCoroutine.kt");
}
@Test
@TestMetadata("kt54382.kt")
public void testKt54382() throws Exception {
@@ -878,6 +878,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
runTest("js/js.translator/testData/box/coroutines/dynamicSuspendReturnWithOperator.kt");
}
@Test
@TestMetadata("jsCallInsideCoroutine.kt")
public void testJsCallInsideCoroutine() throws Exception {
runTest("js/js.translator/testData/box/coroutines/jsCallInsideCoroutine.kt");
}
@Test
@TestMetadata("kt54382.kt")
public void testKt54382() throws Exception {
@@ -878,6 +878,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/coroutines/dynamicSuspendReturnWithOperator.kt");
}
@Test
@TestMetadata("jsCallInsideCoroutine.kt")
public void testJsCallInsideCoroutine() throws Exception {
runTest("js/js.translator/testData/box/coroutines/jsCallInsideCoroutine.kt");
}
@Test
@TestMetadata("kt54382.kt")
public void testKt54382() throws Exception {
@@ -0,0 +1,44 @@
// KT-54134
// WITH_STDLIB
// EXPECTED_REACHABLE_NODES: 1292
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
external interface Test {
val test: String
}
suspend fun <T> smth(xx: T): T = xx
suspend fun foo(): Test {
val x1 = smth(js("{}"))
val node = js("Object.assign({ test: 'O' }, x1)")
return smth(node)
}
suspend fun bar(): Test {
val x1 = smth(js("{}"))
val node = js("""
x1.test = 'K'
Object.assign({}, x1)
""")
return smth(node)
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(object : Continuation<Unit> {
override val context = EmptyCoroutineContext
override fun resumeWith(result: Result<Unit>) {}
})
}
fun box(): String {
var result = ""
builder {
result += foo().test
result += bar().test
}
return result
}