[JS IR] Support throwing linkage error in JS IR BE

- lower it into runtime API call
This commit is contained in:
Roman Artemev
2021-11-16 13:52:59 +03:00
committed by TeamCityServer
parent 7f27ebc589
commit a0d67cb2e3
2 changed files with 8 additions and 2 deletions
@@ -322,6 +322,10 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
val jsUndefined = getInternalFunction("jsUndefined")
val linkageErrorSymbol = getInternalFunction("throwLinkageError")
// Helpers:
private fun getInternalFunction(name: String) =
context.symbolTable.referenceSimpleFunction(context.getJsInternalFunction(name))
@@ -6,14 +6,15 @@
package org.jetbrains.kotlin.ir.backend.js.lower.calls
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
import org.jetbrains.kotlin.ir.util.irCall
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
import org.jetbrains.kotlin.ir.util.irCall
import org.jetbrains.kotlin.ir.util.kotlinPackageFqn
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
class ExceptionHelperCallsTransformer(private val context: JsIrBackendContext) : CallsTransformer {
// TODO: move symbol resolve into context
private fun referenceFunction(fqn: FqName) =
context.getFunctions(fqn).singleOrNull()?.let {
context.symbolTable.referenceSimpleFunction(it)
@@ -24,7 +25,8 @@ class ExceptionHelperCallsTransformer(private val context: JsIrBackendContext) :
context.irBuiltIns.throwCceSymbol to referenceFunction(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))),
context.irBuiltIns.throwIseSymbol to referenceFunction(kotlinPackageFqn.child(Name.identifier("THROW_ISE"))),
context.irBuiltIns.illegalArgumentExceptionSymbol to referenceFunction(kotlinPackageFqn.child(Name.identifier("THROW_IAE"))),
context.irBuiltIns.noWhenBranchMatchedExceptionSymbol to referenceFunction(kotlinPackageFqn.child(Name.identifier("noWhenBranchMatchedException")))
context.irBuiltIns.noWhenBranchMatchedExceptionSymbol to referenceFunction(kotlinPackageFqn.child(Name.identifier("noWhenBranchMatchedException"))),
context.irBuiltIns.linkageErrorSymbol to context.intrinsics.linkageErrorSymbol
)
override fun transformFunctionAccess(call: IrFunctionAccessExpression, doNotIntrinsify: Boolean) =