[JS IR BE] ThrowableLowering: Use dynamic operators instead of jsSetJSField intrinsic
This commit is contained in:
@@ -145,8 +145,8 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
|||||||
// Other:
|
// Other:
|
||||||
|
|
||||||
val jsObjectCreate = defineObjectCreateIntrinsic() // Object.create
|
val jsObjectCreate = defineObjectCreateIntrinsic() // Object.create
|
||||||
val jsGetJSField = defineGetJSPropertyIntrinsic() // till we don't have dynamic type we use intrinsic which sets a field with any name
|
val jsGetJSField = defineGetJSPropertyIntrinsic() // TODO: Replace with dynamic operators
|
||||||
val jsSetJSField = defineSetJSPropertyIntrinsic() // till we don't have dynamic type we use intrinsic which sets a field with any name
|
val jsSetJSField = defineSetJSPropertyIntrinsic() // TODO: Replace with dynamic operators
|
||||||
val jsCode = getInternalFunction("js") // js("<code>")
|
val jsCode = getInternalFunction("js") // js("<code>")
|
||||||
val jsHashCode = getInternalFunction("hashCode")
|
val jsHashCode = getInternalFunction("hashCode")
|
||||||
val jsGetObjectHashCode = getInternalFunction("getObjectHashCode")
|
val jsGetObjectHashCode = getInternalFunction("getObjectHashCode")
|
||||||
|
|||||||
+22
-13
@@ -16,9 +16,9 @@ import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
import org.jetbrains.kotlin.ir.types.isNullableString
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
import org.jetbrains.kotlin.ir.types.isString
|
||||||
import org.jetbrains.kotlin.ir.types.makeNotNull
|
import org.jetbrains.kotlin.ir.types.makeNotNull
|
||||||
import org.jetbrains.kotlin.ir.util.defaultType
|
import org.jetbrains.kotlin.ir.util.defaultType
|
||||||
import org.jetbrains.kotlin.ir.util.isThrowable
|
import org.jetbrains.kotlin.ir.util.isThrowable
|
||||||
@@ -30,8 +30,6 @@ class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
|||||||
private val unitType get() = context.irBuiltIns.unitType
|
private val unitType get() = context.irBuiltIns.unitType
|
||||||
private val nothingNType get() = context.irBuiltIns.nothingNType
|
private val nothingNType get() = context.irBuiltIns.nothingNType
|
||||||
private val stringType get() = context.irBuiltIns.stringType
|
private val stringType get() = context.irBuiltIns.stringType
|
||||||
private val propertySetter get() = context.intrinsics.jsSetJSField.symbol
|
|
||||||
private val nameName get() = JsIrBuilder.buildString(stringType, "name")
|
|
||||||
|
|
||||||
private val throwableConstructors = context.throwableConstructors
|
private val throwableConstructors = context.throwableConstructors
|
||||||
|
|
||||||
@@ -58,9 +56,13 @@ class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
|||||||
)
|
)
|
||||||
else -> {
|
else -> {
|
||||||
val arg = getValueArgument(0)!!
|
val arg = getValueArgument(0)!!
|
||||||
|
val parameter = symbol.owner.valueParameters[0]
|
||||||
when {
|
when {
|
||||||
arg.type.makeNotNull().isThrowable() -> ThrowableArguments(message = nullValue(), cause = arg)
|
parameter.type.isNullableString() -> ThrowableArguments(message = arg, cause = nullValue())
|
||||||
else -> ThrowableArguments(message = arg, cause = nullValue())
|
else -> {
|
||||||
|
assert(parameter.type.makeNotNull().isThrowable())
|
||||||
|
ThrowableArguments(message = nullValue(), cause = arg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,12 +87,19 @@ class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
|||||||
override fun visitConstructor(declaration: IrConstructor, data: IrDeclarationParent): IrStatement {
|
override fun visitConstructor(declaration: IrConstructor, data: IrDeclarationParent): IrStatement {
|
||||||
val klass = data as IrClass
|
val klass = data as IrClass
|
||||||
if (klass.defaultType.isThrowableTypeOrSubtype() && declaration.callsSuper(context.irBuiltIns)) {
|
if (klass.defaultType.isThrowableTypeOrSubtype() && declaration.callsSuper(context.irBuiltIns)) {
|
||||||
(declaration.body as? IrBlockBody)?.let {
|
val body = declaration.body as IrBlockBody
|
||||||
it.statements += JsIrBuilder.buildCall(propertySetter, unitType).apply {
|
body.statements += IrDynamicOperatorExpressionImpl(
|
||||||
putValueArgument(0, JsIrBuilder.buildGetValue(klass.thisReceiver!!.symbol))
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||||
putValueArgument(1, nameName)
|
unitType,
|
||||||
putValueArgument(2, JsIrBuilder.buildString(stringType, klass.name.asString()))
|
IrDynamicOperator.EQ
|
||||||
}
|
).also {
|
||||||
|
it.receiver = IrDynamicMemberExpressionImpl(
|
||||||
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||||
|
context.dynamicType,
|
||||||
|
"name",
|
||||||
|
JsIrBuilder.buildGetValue(klass.thisReceiver!!.symbol)
|
||||||
|
)
|
||||||
|
it.arguments.add(JsIrBuilder.buildString(stringType, klass.name.asString()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user