JS: fix toString in case of kotlin.Throwable

This commit is contained in:
Alexey Andreev
2017-01-24 17:18:54 +03:00
parent 6b2f1ba4e4
commit aef7b83932
2 changed files with 9 additions and 1 deletions
+7 -1
View File
@@ -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")