JS: coroutines: fix handling of throw statement inside try/catch block when controller has handleSuspend function
This commit is contained in:
@@ -73,7 +73,7 @@ class CoroutineBodyTransformer(
|
||||
|
||||
val thenEntryBlock = CoroutineBlock()
|
||||
currentBlock = thenEntryBlock
|
||||
x.thenStatement?.accept(this)
|
||||
x.thenStatement.accept(this)
|
||||
val thenExitBlock = currentBlock
|
||||
|
||||
val elseEntryBlock = CoroutineBlock()
|
||||
@@ -322,8 +322,7 @@ class CoroutineBodyTransformer(
|
||||
}
|
||||
|
||||
override fun visitThrow(x: JsThrow) {
|
||||
if (throwFunctionName != null) {
|
||||
// TODO: what if we catch exception in coroutine?
|
||||
if (throwFunctionName != null && tryStack.isEmpty()) {
|
||||
val methodRef = JsNameRef(throwFunctionName, JsNameRef(context.controllerFieldName, JsLiteral.THIS))
|
||||
val invocation = JsInvocation(methodRef, x.expression).apply {
|
||||
source = x.source
|
||||
|
||||
@@ -5591,6 +5591,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("throwInTryWithHandleResult.kt")
|
||||
public void testThrowInTryWithHandleResult() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("whileStatement.kt")
|
||||
public void testWhileStatement() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt");
|
||||
|
||||
Reference in New Issue
Block a user