
Strings in WebAssembly - dmit
https://medium.com/wasm/strings-in-webassembly-wasm-57a05c1ea333
======
Benmcdonald__
The Mozilla developer working on web assembly wrote some good articles on
types

[https://hacks.mozilla.org/2019/08/webassembly-interface-
type...](https://hacks.mozilla.org/2019/08/webassembly-interface-types/)

------
phibz
Maybe it was just me but this felt a bit overly pedantic. Understanding the
internals of wasm bindgen is important for understanding how rust handles
strings in WASM, but I was expecting a higher level discussion of how strings
are passed to WASM.

------
brainsmith
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](https://github.com/onsails/wasmer-as).

~~~
kbumsik
I'm wondering why AssemblyScript uses UCS-2 instead of UTF-8. Do browsers use
UCS-2 as well?

~~~
austincheney
[https://mathiasbynens.be/notes/javascript-
encoding](https://mathiasbynens.be/notes/javascript-encoding)

------
continuational
To quote the Medium comment from Masklinn:

> Actually, humans generally think in terms of graphemes, which may or may not
> be composed of multiple Unicode code points (irrespective of the
> normalization form being used).

------
alexgmcm
Medium delenda est.

~~~
LessDmesg
"Delendum". Medium delendum est. It's neuter gender unlike Carthage which was
feminine like many city names.

~~~
alexgmcm
How many Romans?
[https://www.youtube.com/watch?v=IIAdHEwiAy8](https://www.youtube.com/watch?v=IIAdHEwiAy8)

------
tyingq
Is it unusual for a VM not to have a string (or at least a bytes) type? I have
little experience in the space, but it seems clunky. Curious why WASM went
this direction.

~~~
kbumsik
WASM just reached MVP. The design goal of the MVP seems to be a small spec
that includes the minimum amount of requirements.

I guess that is the reason why all four major browsers cloud adopt it almost
in the same time, without having many proposal ping-pongs between Google vs
Mozilla vs Apple vs Microsoft.

~~~
tyingq
This article, and proposals for reference types, though, make it sound like
working around the lack of strings/bytes/chars might have been more work in
the end. Sort of like a unicycle isn't really a bicycle MVP :)

~~~
kbumsik
Right, but it is better than having to wait more years until browsers reach
consensus. I'm not sure but specifying a WASM-native string representation
might be more favorable to a specific JS engine than the others, depending on
its existing JS string implementation. This might cause disagreements.

