str = JS_NewUCString(cx, unichars, unicharLength);
str = JS_NewUCString(cx, NS_REINTERPRET_CAST(jschar*, unichars), unicharLength);
LocaleToUnicode(JSContext *cx, char *src, jsval *rval){  nsresult rv;  if (!gDecoder) {    // use app default locale    nsCOMPtr<nsILocaleService> localeService =       do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);    if (NS_SUCCEEDED(rv)) {      nsCOMPtr<nsILocale> appLocale;      rv = localeService->GetApplicationLocale(getter_AddRefs(appLocale));      if (NS_SUCCEEDED(rv)) {        nsXPIDLString locale;        rv = appLocale->          GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME##PLATFORM").get(),                      getter_Copies(locale));        NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get app locale info");        nsCOMPtr<nsIPlatformCharset> platformCharset =          do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);        if (NS_SUCCEEDED(rv)) {          nsCAutoString charset;          rv = platformCharset->GetDefaultCharsetForLocale(locale, charset);          if (NS_SUCCEEDED(rv)) {            // get/create unicode decoder for charset            nsCOMPtr<nsICharsetConverterManager> ccm =              do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);            if (NS_SUCCEEDED(rv))              ccm->GetUnicodeDecoder(charset.get(), &gDecoder);          }        }      }    }  }  JSString *str = nsnull;  PRInt32 srcLength = PL_strlen(src);  if (gDecoder) {    PRInt32 unicharLength = srcLength;    PRUnichar *unichars = (PRUnichar *)malloc(srcLength * sizeof(PRUnichar));    if (unichars) {      rv = gDecoder->Convert(src, &srcLength, unichars, &unicharLength);      if (NS_SUCCEEDED(rv)) {        // nsIUnicodeDecoder::Convert may use fewer than srcLength PRUnichars        if (unicharLength < srcLength) {          PRUnichar *shrunkUnichars =            (PRUnichar *)realloc(unichars, unicharLength * sizeof(PRUnichar));          if (shrunkUnichars)            unichars = shrunkUnichars;        }        str = JS_NewUCString(cx, unichars, unicharLength);      }      if (!str)        free(unichars);    }  }  if (!str) {    nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED);    return JS_FALSE;  }  *rval = STRING_TO_JSVAL(str);  return JS_TRUE;}