News for hackers. Stuff that matters.
Re:Strings in WebAssembly by brainsmith on Monday February 24, 2020 @07:21AM (#22403435)
Due to the the lack of native strings in WebAssembly different Wasm compilers have different memory layouts and string encodings. For example assemblyscript uses ucs2 for the sake fo compatibility with JavaScript. This obliges to carefully work with memory bounds, string length estimation due to difference in host native and guest string encodings.

For the specific goal of working with Strings in rust and assemblyscript I've created this project: https://github.com/onsails/wasmer-as.

Re:Strings in WebAssembly by miracle2k on Monday February 24, 2020 @12:10PM (#22405930)
I've created an equivalent library for Python and used your project as a reference:

https://github.com/miracle2k/wasmbind

Re:Strings in WebAssembly by kbumsik on Monday February 24, 2020 @08:57AM (#22403957)
I'm wondering why AssemblyScript uses UCS-2 instead of UTF-8. Do browsers use UCS-2 as well?
Re:Strings in WebAssembly by austincheney on Monday February 24, 2020 @09:05AM (#22404011)
Re:Strings in WebAssembly by maxgraey on Monday February 24, 2020 @11:37AM (#22405551)
AS as well as JS interpret code strings as UTF16-LE during follow methods: String.p.codePointAt, String.p.toUpperCase/toLowerCase, String.p.localeCompare, String.p.normalize, String.fromCodePoint, Array.from(str). In rest cases strings interprets as UCS-2.
Re:Strings in WebAssembly by johncolanduoni on Monday February 24, 2020 @12:53PM (#22406411)
The do in all the observable JS APIs, but behind the scenes there are a number of optimizations in each JS engine to deal with the fact that most JS and JSON source comes off the wire in UTF-8 or ASCII.