diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ThrowableLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ThrowableLowering.kt index 62d89244938..1b3ac75b13a 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ThrowableLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ThrowableLowering.kt @@ -27,12 +27,9 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformer class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass { - private val unitType get() = context.irBuiltIns.unitType private val nothingNType get() = context.irBuiltIns.nothingNType - private val stringType get() = context.irBuiltIns.stringType private val throwableConstructors = context.throwableConstructors - private val newThrowableFunction = context.newThrowableSymbol 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 { expression.transformChildren(this, data) if (expression.symbol !in throwableConstructors) return expression diff --git a/libraries/stdlib/js-ir/runtime/coreRuntime.kt b/libraries/stdlib/js-ir/runtime/coreRuntime.kt index 1e091cf010a..7350ed694d3 100644 --- a/libraries/stdlib/js-ir/runtime/coreRuntime.kt +++ b/libraries/stdlib/js-ir/runtime/coreRuntime.kt @@ -97,11 +97,16 @@ internal fun extendThrowable(this_: dynamic, message: String?, cause: Throwable? js("Error").call(this_) this_.message = message ?: cause?.toString() ?: undefined this_.cause = cause + this_.name = JsObject.getPrototypeOf(this_).constructor.name captureStack(this_) } @JsName("Object") -internal external class JsObject +internal external class JsObject { + companion object { + fun getPrototypeOf(obj: Any?): dynamic + } +} internal fun boxIntrinsic(x: T): R = error("Should be lowered") internal fun unboxIntrinsic(x: T): R = error("Should be lowered")