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

Robert Jaros

10/11/2023, 7:03 PM
In Kotlin/JS javascript arrays are represented as
Array<T>
, with
size
property (Kotlin syntax). In Kotlin/Wasm, JS arrays are represented as
JsArray<T>
, with
length
property (JS syntax). This makes writing code compatible with both targets (e.g. in common target) very hard at least. I've come up with some hacks based on expect/actual and dirty casts. Anyone has better ideas how to deal with this?
b

bashor

10/11/2023, 7:19 PM
cc @Svyatoslav Kuzmich [JB]
Could you please provide more information why and how do you need JS Array
r

Robert Jaros

10/11/2023, 7:21 PM
In this case I try to use browser Drag and Drop API.
org.w3c.dom.DataTransfer.types
is an array
I just need to check the values.
It's trivial in Kotlin/JS, fairly easy in Kotlin/Wasm, but hard to do with the same code because of length/size property.
s

Svyatoslav Kuzmich [JB]

10/11/2023, 8:04 PM
Expect/actuals with casts is probably the best approach to commonise this for now. Ideally we’d want to have
JsArray<T>
and Wasm version of DOM API common between Kotlin/JS and Kotlin/Wasm, but the design is still in flux.