diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index a889f3e73e3..099536e068b 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -33,6 +33,8 @@ import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.types.impl.IrDynamicTypeImpl import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.ir.util.getPropertyDeclaration +import org.jetbrains.kotlin.ir.util.kotlinPackageFqn +import org.jetbrains.kotlin.ir.util.referenceFunction import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.MemberScope @@ -177,14 +179,14 @@ class JsIrBackendContext( override val areEqual get () = TODO("not implemented") - override val ThrowNullPointerException - get () = irBuiltIns.throwNpeSymbol + override val ThrowNullPointerException = getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).singleOrNull()?.let { + symbolTable.referenceSimpleFunction(it) } ?: irBuiltIns.throwNpeSymbol override val ThrowNoWhenBranchMatchedException get () = irBuiltIns.noWhenBranchMatchedExceptionSymbol - override val ThrowTypeCastException - get () = irBuiltIns.throwCceSymbol + override val ThrowTypeCastException = getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))).singleOrNull()?.let { + symbolTable.referenceSimpleFunction(it) } ?: irBuiltIns.throwCceSymbol override val ThrowUninitializedPropertyAccessException= symbolTable.referenceSimpleFunction(getFunctions(FqName("kotlin.throwUninitializedPropertyAccessException")).single()) @@ -205,6 +207,9 @@ class JsIrBackendContext( override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true } + val throwISEymbol = getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))).singleOrNull()?.let { + symbolTable.referenceSimpleFunction(it) } ?: irBuiltIns.throwIseSymbol + val coroutineImplLabelProperty by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("state")!! } val coroutineImplResultSymbol by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("result")!! } val coroutineImplExceptionProperty by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("exception")!! } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt index d7d08cc7e3b..9ff7e7d60ba 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt @@ -60,6 +60,7 @@ class EnumClassTransformer(val context: JsIrBackendContext, private val irClass: private val enumEntries = irClass.declarations.filterIsInstance() private val loweredEnumConstructors = HashMap() private val enumName = irClass.name.identifier + private val throwISESymbol = context.throwISEymbol fun transform(): List { // Add `name` and `ordinal` parameters to enum class constructors @@ -140,7 +141,7 @@ class EnumClassTransformer(val context: JsIrBackendContext, private val irClass: irBranch( irEquals(irString(it.name.identifier), irGet(nameParameter)), irCall(getInstance) ) - } + irElseBranch(irCall(context.irBuiltIns.throwIseSymbol)) + } + irElseBranch(irCall(throwISESymbol)) ) ) } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/TypeOperatorLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/TypeOperatorLowering.kt index 5bfa5ea28b4..f767205dc09 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/TypeOperatorLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/TypeOperatorLowering.kt @@ -42,8 +42,8 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : FileLoweringPass { private val calculator = JsIrArithBuilder(context) //NOTE: Should we define JS-own functions similar to current implementation? - private val throwCCE = context.irBuiltIns.throwCceSymbol - private val throwNPE = context.irBuiltIns.throwNpeSymbol + private val throwCCE = context.ir.symbols.ThrowTypeCastException + private val throwNPE = context.ir.symbols.ThrowNullPointerException private val eqeq = context.irBuiltIns.eqeqSymbol diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrDeclarationToJsTransformer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrDeclarationToJsTransformer.kt index 6ca24e7b70f..0dd1ff158b8 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrDeclarationToJsTransformer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrDeclarationToJsTransformer.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs import org.jetbrains.kotlin.ir.backend.js.utils.JsGenerationContext import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.js.backend.ast.JsDeclarationScope import org.jetbrains.kotlin.js.backend.ast.JsEmpty import org.jetbrains.kotlin.js.backend.ast.JsStatement import org.jetbrains.kotlin.js.backend.ast.JsVars @@ -23,7 +24,15 @@ class IrDeclarationToJsTransformer : BaseIrElementToJsNodeTransformer