We have a bunch of places where JS code uses extremely old XPCOM components to convert between UTF-16 JS strings and UTF-8 bytes. Typically, code using the old XPCOM facilities represents byte buffers as JavaScript strings where the upper half of each UTF-16 code unit is a zeroed and the lower half is the scalar value of the byte.
The Web platform now has a way to represent bytes efficiently via ArrayBuffers and a way to convert between UTF-16 JS strings and UTF-8 ArrayBuffers. To convert from the UTF-8 ArrayBuffers to JS strings, use TextDecoder. To go the other way, use TextEncoder. When writing new code, please try to use ArrayBuffers for bytes and Text[En|De]coder for conversion when feasible. Also, please consider if you could be using XMLHttpRequest for whatever IO you are doing and letting XHR do the conversion for you. -- Henri Sivonen hsivo...@hsivonen.fi https://hsivonen.fi/ _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform