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

darkmoon_uk

02/29/2024, 3:50 AM
Will Weak References to Kotlin objects be supported in the WASM target? They're an important mechanism for implementing some types of caches. Direct expect/actual to JS WeakRef will only bridge 'external, primitive, string and function types' which is too limiting. See: • WASM proposal for WeakRef support • Kotlin WeakReference type for Native • WeakReference type for JVM (inc. Kotlin)
4
a

Artem Kobzar

02/29/2024, 9:36 AM
Could I ask you to create an issue in YouTrack with this description? We'll take a look at what we could do with it.
👍 1
d

darkmoon_uk

02/29/2024, 10:18 AM
☝️ @jessewilson @PHondogo @Alexander Girke @Artem Kobzar
👍 3
🙏 1
thank you color 1
🙏🏻 1
s

Svyatoslav Kuzmich [JB]

02/29/2024, 2:17 PM
Thanks for the report! Wasm GC does not have weak references yet, we have to go through JS.
Direct expect/actual to JS WeakRef will only bridge ‘external, primitive, string and function types’ which is too limiting.
You can use JsReference<T> to send any Kotlin object to JS and retrieve it back. An example of WeakReference implemented in wasmJs
d

darkmoon_uk

03/01/2024, 3:50 AM
Many thanks @Svyatoslav Kuzmich [JB] for taking the time to provide this 🙌 - I've added it as a 'workaround method' to the YouTrack ticket also.
3 Views