News for hackers. Stuff that matters.
Re:Strings in WebAssembly by Benmcdonald__ on Monday February 24, 2020 @06:12AM (#22403121)
The Mozilla developer working on web assembly wrote some good articles on types

https://hacks.mozilla.org/2019/08/webassembly-interface-type...

Re:Strings in WebAssembly by phibz on Monday February 24, 2020 @12:27PM (#22406100)
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.
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.
Re:Strings in WebAssembly by continuational on Monday February 24, 2020 @10:42AM (#22404939)
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).

Re:Strings in WebAssembly by alexgmcm on Monday February 24, 2020 @04:29AM (#22402734)
Medium delenda est.
Re:Strings in WebAssembly by LessDmesg on Monday February 24, 2020 @05:44AM (#22403011)
"Delendum". Medium delendum est. It's neuter gender unlike Carthage which was feminine like many city names.
Re:Strings in WebAssembly by alexgmcm on Monday February 24, 2020 @06:12AM (#22403120)
Re:Strings in WebAssembly by BiteCode_dev on Monday February 24, 2020 @10:44AM (#22404973)
A joke is not meant to be accurate. This one is funnier if you only change one word of the original quote, even if the resulting one is wrong.
Re:Strings in WebAssembly by earthboundkid on Monday February 24, 2020 @10:58AM (#22405147)
Medium should be "media," no?
Re:Strings in WebAssembly by BiteCode_dev on Monday February 24, 2020 @10:48AM (#22405011)
I hate medium myself, but before going that route it is important to recognize the success of it and ponder why.

- why so many tech users use medium to write tech articles and not ghost, wix, tumblr or a wordpress provider?

- why so many people post links to article from medium?

Unless we answers those questions and provide an alternative can we destroy it, otherwise people will just keep doing that.

Re:Strings in WebAssembly by drfuchs on Monday February 24, 2020 @04:40AM (#22402775)
For the Greek-impaired: “Medium must be destroyed.” [Edit: Latin! I meant Latin! Oy, vey!]
Re:Strings in WebAssembly by alexgmcm on Monday February 24, 2020 @05:02AM (#22402847)
It is Latin, no?
Re:Strings in WebAssembly by saagarjha on Monday February 24, 2020 @05:15AM (#22402901)
Of course. For those who aren't familiar with the phrase: https://en.wikipedia.org/wiki/Carthago_delenda_est
Re:Strings in WebAssembly by tyingq on Monday February 24, 2020 @07:14AM (#22403408)
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.
Re:Strings in WebAssembly by kbumsik on Monday February 24, 2020 @08:02AM (#22403644)
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.

Re:Strings in WebAssembly by tyingq on Monday February 24, 2020 @08:14AM (#22403698)
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 :)
Re:Strings in WebAssembly by kbumsik on Monday February 24, 2020 @08:41AM (#22403855)
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.
Re:Strings in WebAssembly by AndrewDucker on Monday February 24, 2020 @08:15AM (#22403709)
The problem is that WebAssembly exists for other languages to be compiled into.

And those other languages don't agree what a string looks like.

So do you have a Rust string? Or a C string? Or a C# string? Or one of the other representations?

By just giving you a bunch of bytes to play with, and letting different languages use them differently, WebAssembly stays out of the way and lets the compiler decide how it wants to make strings.

Re:Strings in WebAssembly by tyingq on Monday February 24, 2020 @08:20AM (#22403732)
"By just giving you a bunch of bytes to play with"

It doesn't appear to do even that though. You get i32, i64, f32, and f64. The linear memory is some multiple of the 64KiB page size.

Re:Strings in WebAssembly by kaoD on Monday February 24, 2020 @08:35AM (#22403818)
And linear memory, which is just an array of bytes.
Re:Strings in WebAssembly by AndrewDucker on Monday February 24, 2020 @08:32AM (#22403801)
An i32 is a byte.
Re:Strings in WebAssembly by kaoD on Monday February 24, 2020 @08:35AM (#22403815)
The common definition of byte nowadays is an octet.
Re:Strings in WebAssembly by kbumsik on Monday February 24, 2020 @08:42AM (#22403861)
In WASM i32 can be treated like a 8-bit byte too.
Re:Strings in WebAssembly by kaoD on Monday February 24, 2020 @08:56AM (#22403951)
Can you elaborate? I'm not well-versed in WASM internals and I might be missing something.

I mean, any integer with 8+ bits can be treated like an octet, but memory layout is very different (e.g. an array of i8 and an array of i32 look very different even if they represent the same values).

Re:Strings in WebAssembly by kbumsik on Monday February 24, 2020 @09:04AM (#22404005)
Although WASM types only have 32/64 bits it has 8/16 bit operations too. So it won't matter much:

https://webassembly.org/docs/semantics/