From 83ecafe8d18f46d1169edc4ec7cd8a9392b10bec Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Tue, 31 May 2022 19:56:34 +0200 Subject: [PATCH] [WASM] Add toString implementation to Throwable --- libraries/stdlib/wasm/builtins/kotlin/Throwable.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/stdlib/wasm/builtins/kotlin/Throwable.kt b/libraries/stdlib/wasm/builtins/kotlin/Throwable.kt index 6f5ad876aaf..fd14cb7f1ce 100644 --- a/libraries/stdlib/wasm/builtins/kotlin/Throwable.kt +++ b/libraries/stdlib/wasm/builtins/kotlin/Throwable.kt @@ -28,6 +28,16 @@ public open class Throwable(open val message: String?, open val cause: kotlin.Th } internal var suppressedExceptionsList: MutableList? = null + + /** + * Returns the short description of this throwable consisting of the exception class name + * followed by the exception message if it is not null. + */ + public override fun toString(): String { + val kClass = this::class + val s = kClass.simpleName ?: "Throwable" + return if (message != null) s + ": " + message.toString() else s + } } @JsFun("() => new Error().stack")