Strange code in an extension

Add-ons for Pale Moon and other applications
General discussion, compatibility, contributed extensions, themes, plugins, and more.

Moderators: FranklinDM, Lootyhoof

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Strange code in an extension

Unread post by thosrtanner » 2018-05-09, 20:27

I found this code in the extension I'm maintaining, and it confuses me

Code: Select all

      const UTF8Converter = Components.Constructor("@mozilla.org/intl/utf8converterservice;1",  "nsIUTF8ConverterService");
...
      //read outputstr from a file via a ScriptableInputStream
      let uConv = new UTF8Converter();
      outputStr = uConv.convertStringToUTF8(output, "UTF-8", false);
If I read the documentation right, Isn't that taking a string and converting if it's not in UTF8 converting it from UTF8 to UTF8? So effectively doing nothing.

JustOff

Re: Strange code in an extension

Unread post by JustOff » 2018-05-09, 21:22

It could also be a way to ensure the string is encoded in UTF-8, see nsCookie.cpp.

Locked