[JS IR BE] Set Throwable subtype name in extendThrowable function
This commit is contained in:
-27
@@ -27,12 +27,9 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
|||||||
|
|
||||||
|
|
||||||
class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
||||||
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 throwableConstructors = context.throwableConstructors
|
private val throwableConstructors = context.throwableConstructors
|
||||||
|
|
||||||
private val newThrowableFunction = context.newThrowableSymbol
|
private val newThrowableFunction = context.newThrowableSymbol
|
||||||
private val extendThrowableFunction = context.extendThrowableSymbol
|
private val extendThrowableFunction = context.extendThrowableSymbol
|
||||||
|
|
||||||
@@ -84,30 +81,6 @@ class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitConstructor(declaration: IrConstructor, data: IrDeclarationParent): IrStatement {
|
|
||||||
val klass = data as IrClass
|
|
||||||
if (klass.defaultType.isThrowableTypeOrSubtype() && declaration.callsSuper(context.irBuiltIns)) {
|
|
||||||
val body = declaration.body as IrBlockBody
|
|
||||||
body.statements += IrDynamicOperatorExpressionImpl(
|
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
|
||||||
unitType,
|
|
||||||
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()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declaration.transformChildren(this, data)
|
|
||||||
|
|
||||||
return declaration
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: IrDeclarationParent): IrExpression {
|
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: IrDeclarationParent): IrExpression {
|
||||||
expression.transformChildren(this, data)
|
expression.transformChildren(this, data)
|
||||||
if (expression.symbol !in throwableConstructors) return expression
|
if (expression.symbol !in throwableConstructors) return expression
|
||||||
|
|||||||
@@ -97,11 +97,16 @@ internal fun extendThrowable(this_: dynamic, message: String?, cause: Throwable?
|
|||||||
js("Error").call(this_)
|
js("Error").call(this_)
|
||||||
this_.message = message ?: cause?.toString() ?: undefined
|
this_.message = message ?: cause?.toString() ?: undefined
|
||||||
this_.cause = cause
|
this_.cause = cause
|
||||||
|
this_.name = JsObject.getPrototypeOf(this_).constructor.name
|
||||||
captureStack(this_)
|
captureStack(this_)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsName("Object")
|
@JsName("Object")
|
||||||
internal external class JsObject
|
internal external class JsObject {
|
||||||
|
companion object {
|
||||||
|
fun getPrototypeOf(obj: Any?): dynamic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal fun <T, R> boxIntrinsic(x: T): R = error("Should be lowered")
|
internal fun <T, R> boxIntrinsic(x: T): R = error("Should be lowered")
|
||||||
internal fun <T, R> unboxIntrinsic(x: T): R = error("Should be lowered")
|
internal fun <T, R> unboxIntrinsic(x: T): R = error("Should be lowered")
|
||||||
|
|||||||
Reference in New Issue
Block a user