JS IR: fix throwable descendants
^ KT-43490 fixed
This commit is contained in:
committed by
Space Team
parent
48ed6c4cc7
commit
b0de442d76
@@ -103,7 +103,8 @@ internal fun extendThrowable(this_: dynamic, message: String?, cause: Throwable?
|
||||
}
|
||||
|
||||
internal fun setPropertiesToThrowableInstance(this_: dynamic, message: String?, cause: Throwable?) {
|
||||
if (!hasOwnPrototypeProperty(this_, "message")) {
|
||||
val errorInfo = calculateErrorInfo(JsObject.getPrototypeOf(this_))
|
||||
if ((errorInfo and 0x1) == 0) {
|
||||
@Suppress("IfThenToElvis")
|
||||
this_.message = if (message == null) {
|
||||
@Suppress("SENSELESS_COMPARISON")
|
||||
@@ -116,7 +117,7 @@ internal fun setPropertiesToThrowableInstance(this_: dynamic, message: String?,
|
||||
}
|
||||
} else message
|
||||
}
|
||||
if (!hasOwnPrototypeProperty(this_, "cause")) {
|
||||
if ((errorInfo and 0x2) == 0) {
|
||||
this_.cause = cause
|
||||
}
|
||||
this_.name = JsObject.getPrototypeOf(this_).constructor.name
|
||||
|
||||
@@ -90,6 +90,8 @@ internal external interface Metadata {
|
||||
val iid: Int?
|
||||
|
||||
var `$kClass$`: dynamic
|
||||
|
||||
var errorInfo: Int? // Bits set for overridden properties: "message" => 0x1, "cause" => 0x2
|
||||
}
|
||||
|
||||
internal external interface Ctor {
|
||||
@@ -99,9 +101,32 @@ internal external interface Ctor {
|
||||
val prototype: dynamic
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private fun getPrototypeOf(obj: dynamic) =
|
||||
js("Object.getPrototypeOf(obj)")
|
||||
private fun hasProp(proto: dynamic, propName: String): Boolean = proto.hasOwnProperty(propName)
|
||||
|
||||
internal fun calculateErrorInfo(proto: dynamic): Int {
|
||||
val metadata: Metadata? = proto.constructor?.`$metadata$`
|
||||
|
||||
metadata?.errorInfo?.let { return it } // cached
|
||||
|
||||
var result = 0
|
||||
if (hasProp(proto, "message")) result = result or 0x1
|
||||
if (hasProp(proto, "cause")) result = result or 0x2
|
||||
|
||||
if (result != 0x3) { //
|
||||
val parentProto = getPrototypeOf(proto)
|
||||
if (parentProto != js("Error").prototype) {
|
||||
result = result or calculateErrorInfo(parentProto)
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata != null) {
|
||||
metadata.errorInfo = result
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private fun getPrototypeOf(obj: dynamic) = JsObject.getPrototypeOf(obj)
|
||||
|
||||
private fun searchForMetadata(obj: dynamic): Metadata? {
|
||||
if (obj == null) {
|
||||
|
||||
Reference in New Issue
Block a user