WASM: Properly handle nullable exported strings

This commit is contained in:
Igor Laevsky
2021-07-30 18:08:57 +03:00
committed by TeamCityServer
parent 468fe4196d
commit 80140207b5
3 changed files with 7 additions and 3 deletions
@@ -8,7 +8,10 @@ package kotlin.wasm.internal
// This is called when exported function returns a string. It writes [i32 length, [i16 chars ...]] into a temporary raw memory area and
// returns pointer to the start of it.
// Note: currently there is a single temporary raw memory area so it's not possible to export more than one string at a time.
internal fun exportString(src: String): Int {
internal fun exportString(src: String?): Int {
if (src == null)
throw IllegalArgumentException("Exporting null string")
val retAddr = unsafeGetScratchRawMemory(INT_SIZE_BYTES + src.length * CHAR_SIZE_BYTES)
wasm_i32_store(retAddr, src.length)
unsafeCharArrayToRawMemory(src.toCharArray(), retAddr + INT_SIZE_BYTES)