Skip to content

Commit

Permalink
[KT] Implement basic support for @jsasync in Kotlin
Browse files Browse the repository at this point in the history
For now this is only intended to cover Kotlin code coming in via J2KT.

PiperOrigin-RevId: 700520248
  • Loading branch information
kevinoconnor7 authored and copybara-github committed Nov 27, 2024
1 parent d6eb381 commit 7e23ca6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import com.google.j2cl.transpiler.frontend.kotlin.ir.getTypeSubstitutionMap
import com.google.j2cl.transpiler.frontend.kotlin.ir.hasVoidReturn
import com.google.j2cl.transpiler.frontend.kotlin.ir.isAdaptedFunctionReference
import com.google.j2cl.transpiler.frontend.kotlin.ir.isClinit
import com.google.j2cl.transpiler.frontend.kotlin.ir.isJsAsync
import com.google.j2cl.transpiler.frontend.kotlin.ir.isSuperCall
import com.google.j2cl.transpiler.frontend.kotlin.ir.isSynthetic
import com.google.j2cl.transpiler.frontend.kotlin.ir.isUnitInstanceReference
Expand Down Expand Up @@ -1342,6 +1343,7 @@ class CompilationUnitBuilder(
typeDescriptor: TypeDescriptor,
irFunctionExpression: IrFunctionExpression,
): FunctionExpression {
check(typeDescriptor.isFunctionalInterface)
val irFunction = irFunctionExpression.function
val parameters = irFunction.getParameters().map(this::createVariable)
val body =
Expand All @@ -1350,6 +1352,7 @@ class CompilationUnitBuilder(

return FunctionExpression.newBuilder()
.setTypeDescriptor(typeDescriptor)
.setJsAsync(typeDescriptor.functionalInterface!!.singleAbstractMethodDescriptor!!.isJsAsync)
.setParameters(parameters)
.setStatements(body.statements)
.setSourcePosition(getSourcePosition(irFunction))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ val IrClass.isJsFunction: Boolean
val IrClass.isJsType: Boolean
get() = findJsinteropAnnotation(JS_TYPE_ANNOTATION_FQ_NAME) != null

private val IrFunction.isJsAsync: Boolean
val IrFunction.isJsAsync: Boolean
get() = findJsinteropAnnotation(JS_ASYNC_ANNOTATION_FQ_NAME) != null

val IrClass.isJsEnum: Boolean
Expand Down Expand Up @@ -191,10 +191,10 @@ private val IrDeclaration.isJsOverlay: Boolean
}

fun IrDeclaration.getJsInfo(): JsInfo =
// TODO(b/225908831): Handle JsAsync
JsInfo.newBuilder()
.setJsMemberType(getJsMemberType())
.setJsOverlay(isJsOverlay)
.setJsAsync(this is IrFunction && isJsAsync)
.apply {
if (isJsMember()) {
getJsMemberAnnotationInfo()?.let {
Expand Down

0 comments on commit 7e23ca6

Please sign in to comment.