JS: fix toString in case of kotlin.Throwable
This commit is contained in:
@@ -61,7 +61,13 @@ internal fun captureStack(baseClass: JsClass<in Throwable>, instance: Throwable)
|
|||||||
@JsName("newThrowable")
|
@JsName("newThrowable")
|
||||||
internal fun newThrowable(message: String?, cause: Throwable?): Throwable {
|
internal fun newThrowable(message: String?, cause: Throwable?): Throwable {
|
||||||
val throwable = js("new Error()")
|
val throwable = js("new Error()")
|
||||||
throwable.message = if (jsTypeOf(message) == "undefined" && cause != null) cause.toString() else message
|
throwable.message = if (jsTypeOf(message) == "undefined") {
|
||||||
|
if (cause != null) cause.toString() else null
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message
|
||||||
|
}
|
||||||
throwable.cause = cause
|
throwable.cause = cause
|
||||||
|
throwable.name = "Throwable"
|
||||||
return throwable
|
return throwable
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,8 @@ fun check(e: Throwable, expectedString: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
|
check(Throwable(), "Throwable: null")
|
||||||
|
check(Throwable("ccc"), "Throwable: ccc")
|
||||||
check(Exception(), "Exception: null")
|
check(Exception(), "Exception: null")
|
||||||
check(Exception("bbb"), "Exception: bbb")
|
check(Exception("bbb"), "Exception: bbb")
|
||||||
check(MyException(), "MyException: null")
|
check(MyException(), "MyException: null")
|
||||||
|
|||||||
Reference in New Issue
Block a user