https://kotlinlang.org logo
#webassembly
Title
# webassembly
s

sdeleuze

02/25/2023, 4:40 PM
Unless I am mistaken, KT-22635 looks like fixed with Kotlin/JS but not Kotlin/Wasm. Is it expected? This is fine with Kotlin/JS (thanks for fixing that BTW):
Copy code
fun main() {
	window.onload = { document.body?.sayHello() }
}
With Kotlin/Wasm, I need to write:
Copy code
fun main() {
    window.onload = {
        document.body?.sayHello()
        null
    }
}
To make it compile.
s

Svyatoslav Kuzmich [JB]

02/26/2023, 8:07 AM
We don’t plan to support
dynamic
in K/Wasm. These lambda types are generated from EventHandler IDL and it seems that return value can be used to cancel the event. I agree that most of the time we don’t need to return anything and having to put
null
is inconvenient. We’ll see what can be done.
s

sdeleuze

02/26/2023, 10:18 AM
Make sense to not support
dynamic
with Wasm but I am a bit confused by the fact
asDynamic()
can be invoked. Is it just returning
this
or is it a noop operation currently? Maybe you did this temporarily for better compat with Kotlin/JS? Would that make sense to ensure it is not used at compile time to avoid any confusion like the one I had when porting kotlinx-html (silent failure)?
s

Svyatoslav Kuzmich [JB]

02/26/2023, 10:25 AM
asDynamic()
wasm a temporarily stub to make our code ported from Kotlin/JS compile and run in some cases. It usually works as
as
, but it is overloaded for
String
where it converts Kotlin String to JS. We should probably drop it from stdlib, please don’t use it.
Sorry for causing the confusion, we should’ve handled it better :)
s

sdeleuze

02/26/2023, 10:27 AM
Ok I will remove any usage of it.
Np I am working on this early I know the risks 😉