From 521a272acbbca898ee32ba724ff17336703cf58e Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Mon, 17 Apr 2023 14:38:19 +0200 Subject: [PATCH] [Wasm] Pass js stack value directly when replacing a wasm exception with JS one In this case, we don't need to convert a value to and from wasm String. --- compiler/testData/codegen/box/size/add.kt | 4 ++-- compiler/testData/codegen/box/size/helloWorld.kt | 4 ++-- compiler/testData/codegen/box/size/helloWorldDOM.kt | 4 ++-- compiler/testData/codegen/box/size/ok.kt | 4 ++-- libraries/stdlib/wasm/builtins/kotlin/Throwable.kt | 2 +- .../wasm/internal/kotlin/wasm/internal/ExceptionHelpers.kt | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/testData/codegen/box/size/add.kt b/compiler/testData/codegen/box/size/add.kt index cda03981236..667a2e0db21 100644 --- a/compiler/testData/codegen/box/size/add.kt +++ b/compiler/testData/codegen/box/size/add.kt @@ -1,7 +1,7 @@ // TARGET_BACKEND: WASM -// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 17_726 -// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_104 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_217 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_579 // FILE: test.kt diff --git a/compiler/testData/codegen/box/size/helloWorld.kt b/compiler/testData/codegen/box/size/helloWorld.kt index 7d559a0f0c9..fcc6a4455af 100644 --- a/compiler/testData/codegen/box/size/helloWorld.kt +++ b/compiler/testData/codegen/box/size/helloWorld.kt @@ -1,7 +1,7 @@ // TARGET_BACKEND: WASM -// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 51_463 -// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_130 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 49_207 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_605 fun box(): String { println("Hello, World!") diff --git a/compiler/testData/codegen/box/size/helloWorldDOM.kt b/compiler/testData/codegen/box/size/helloWorldDOM.kt index 09e108a87cd..5871713da96 100644 --- a/compiler/testData/codegen/box/size/helloWorldDOM.kt +++ b/compiler/testData/codegen/box/size/helloWorldDOM.kt @@ -1,7 +1,7 @@ // TARGET_BACKEND: WASM -// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 19_102 -// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_659 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 15_582 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_134 // FILE: test.kt diff --git a/compiler/testData/codegen/box/size/ok.kt b/compiler/testData/codegen/box/size/ok.kt index a04300d63b7..6fa8e62df26 100644 --- a/compiler/testData/codegen/box/size/ok.kt +++ b/compiler/testData/codegen/box/size/ok.kt @@ -1,6 +1,6 @@ // TARGET_BACKEND: WASM -// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 17_768 -// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_976 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_259 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_451 fun box() = "OK" \ No newline at end of file diff --git a/libraries/stdlib/wasm/builtins/kotlin/Throwable.kt b/libraries/stdlib/wasm/builtins/kotlin/Throwable.kt index 54132d34d9c..ca47635834f 100644 --- a/libraries/stdlib/wasm/builtins/kotlin/Throwable.kt +++ b/libraries/stdlib/wasm/builtins/kotlin/Throwable.kt @@ -22,7 +22,7 @@ public open class Throwable(open val message: String?, open val cause: kotlin.Th constructor() : this(null, null) - private val jsStack: ExternalInterfaceType = captureStackTrace() + internal val jsStack: ExternalInterfaceType = captureStackTrace() private var _stack: String? = null internal val stack: String diff --git a/libraries/stdlib/wasm/internal/kotlin/wasm/internal/ExceptionHelpers.kt b/libraries/stdlib/wasm/internal/kotlin/wasm/internal/ExceptionHelpers.kt index 368fb604a3f..893899e0680 100644 --- a/libraries/stdlib/wasm/internal/kotlin/wasm/internal/ExceptionHelpers.kt +++ b/libraries/stdlib/wasm/internal/kotlin/wasm/internal/ExceptionHelpers.kt @@ -6,7 +6,7 @@ package kotlin.wasm.internal @Suppress("UNUSED_PARAMETER") // TODO: Remove after bootstrap update -private fun throwJsError(message: String?, wasmTypeName: String?, stack: String): Nothing { +private fun throwJsError(message: String?, wasmTypeName: String?, stack: ExternalInterfaceType): Nothing { js(""" const error = new Error(); error.message = message; @@ -17,7 +17,7 @@ private fun throwJsError(message: String?, wasmTypeName: String?, stack: String) } internal fun throwAsJsException(t: Throwable): Nothing { - throwJsError(t.message, getSimpleName(t.typeInfo), t.stack) + throwJsError(t.message, getSimpleName(t.typeInfo), t.jsStack) } internal var isNotFirstWasmExportCall: Boolean = false \ No newline at end of file