title: How to convert an unicode JavaScript string into a byte array?
body: <p>I have a service writing remote files, but it requires a byte array as input. Rest of the interface provides only JavaScript unicode strings. No way to write them then.</p>
  
  <p>I found something like this in MDC:</p>
  
  <pre><code>var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
                  .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  var s = {};
  var tt = 'test string';
  var data = converter.convertToByteArray(tt, s);
  </code></pre>
  
  <p>According to what they say in MDC, this should do exactly what I need, but it fails with this:</p>
  
  <blockquote>
    <p>Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIScriptableUnicodeConverter.convertToByteArray]</p>
  </blockquote>
  
  <p>In docs there is the string must not be UTF-16, and I've read JS uses UTF-16 by default.</p>
  
  <p>Any other ways to produce this damn byte array from string?</p>