[K/JS] Add ability to use is checks on external objects
This commit is contained in:
@@ -95,6 +95,7 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
||||
|
||||
val jsInstanceOf = getInternalFunction("jsInstanceOfIntrinsic")
|
||||
val jsTypeOf = getInternalFunction("jsTypeOf")
|
||||
val isExternalObject = getInternalFunction("isExternalObject")
|
||||
|
||||
// Number conversions:
|
||||
|
||||
|
||||
+10
@@ -53,6 +53,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
||||
private val isObjectSymbol get() = context.intrinsics.isObjectSymbol
|
||||
|
||||
private val instanceOfIntrinsicSymbol = context.intrinsics.jsInstanceOf
|
||||
private val isExternalObjectSymbol = context.intrinsics.isExternalObject
|
||||
private val typeOfIntrinsicSymbol = context.intrinsics.jsTypeOf
|
||||
private val jsClassIntrinsicSymbol = context.intrinsics.jsClass
|
||||
|
||||
@@ -270,6 +271,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
||||
generateInterfaceCheck(argument, toType)
|
||||
}
|
||||
}
|
||||
toType.isExternalObject() -> generateIsExternalObject(argument, toType)
|
||||
else -> generateNativeInstanceOf(argument, toType)
|
||||
}
|
||||
}
|
||||
@@ -360,6 +362,14 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateIsExternalObject(argument: IrExpression, toType: IrType): IrExpression {
|
||||
val irType = wrapTypeReference(toType)
|
||||
return JsIrBuilder.buildCall(isExternalObjectSymbol).apply {
|
||||
putValueArgument(0, argument)
|
||||
putValueArgument(1, irType)
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateNativeInstanceOf(argument: IrExpression, toType: IrType): IrExpression {
|
||||
val irType = wrapTypeReference(toType)
|
||||
return JsIrBuilder.buildCall(instanceOfIntrinsicSymbol).apply {
|
||||
|
||||
@@ -57,6 +57,8 @@ fun IrType.isTypeParameter() = classifierOrNull is IrTypeParameterSymbol
|
||||
|
||||
fun IrType.isInterface() = classOrNull?.owner?.kind == ClassKind.INTERFACE
|
||||
|
||||
fun IrType.isExternalObject() = classOrNull?.owner.let { it?.kind == ClassKind.OBJECT && it.isExternal }
|
||||
|
||||
fun IrType.isAnnotation() = classOrNull?.owner?.kind == ClassKind.ANNOTATION_CLASS
|
||||
|
||||
fun IrType.isFunctionOrKFunction() = isFunction() || isKFunction()
|
||||
|
||||
Reference in New Issue
Block a user