Bug 1444329 - Remove nsIScriptableUnicodeConverter::convertFromByteArray. r?hsivonen draft
authorMark Banner <standard8@mozilla.com>
Mon, 04 Jun 2018 11:25:54 +0100
changeset 804033 777af1023eb1c5cc6cf269d44e00bc504846c193
parent 804032 48729f113647e19d2f24d71fbc84389e8c606b20
push id112283
push userbmo:standard8@mozilla.com
push dateTue, 05 Jun 2018 12:43:35 +0000
reviewershsivonen
bugs1444329
milestone62.0a1
Bug 1444329 - Remove nsIScriptableUnicodeConverter::convertFromByteArray. r?hsivonen MozReview-Commit-ID: IPgCK6slIqj
intl/uconv/nsIScriptableUConv.idl
intl/uconv/nsScriptableUConv.cpp
--- a/intl/uconv/nsIScriptableUConv.idl
+++ b/intl/uconv/nsIScriptableUConv.idl
@@ -37,22 +37,16 @@ interface nsIScriptableUnicodeConverter 
   ACString Finish();
 
   /**
    * Converts the data from one Charset to Unicode.
    */
   AString ConvertToUnicode(in ACString aSrc);
 
   /**
-   * Converts an array of bytes to a unicode string.
-   */
-  AString convertFromByteArray([const,array,size_is(aCount)] in octet aData,
-                               in unsigned long aCount);
-
-  /**
    * Convert a unicode string to an array of bytes. Finish does not need to be
    * called.
    */
   void convertToByteArray(in AString aString,
                           [optional] out unsigned long aLen,
                           [array, size_is(aLen),retval] out octet aData);
 
   /**
--- a/intl/uconv/nsScriptableUConv.cpp
+++ b/intl/uconv/nsScriptableUConv.cpp
@@ -109,40 +109,31 @@ nsScriptableUnicodeConverter::Finish(nsA
   mDecoder->Encoding()->NewDecoderWithBOMRemovalInto(*mDecoder);
   mEncoder->Encoding()->NewEncoderInto(*mEncoder);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsScriptableUnicodeConverter::ConvertToUnicode(const nsACString& aSrc, nsAString& _retval)
 {
-  return ConvertFromByteArray(
-    reinterpret_cast<const uint8_t*>(aSrc.BeginReading()),
-    aSrc.Length(),
-    _retval);
-}
-
-NS_IMETHODIMP
-nsScriptableUnicodeConverter::ConvertFromByteArray(const uint8_t* aData,
-                                                   uint32_t aCount,
-                                                   nsAString& _retval)
-{
   if (!mDecoder)
     return NS_ERROR_FAILURE;
 
-  CheckedInt<size_t> needed = mDecoder->MaxUTF16BufferLength(aCount);
+  uint32_t length = aSrc.Length();
+
+  CheckedInt<size_t> needed = mDecoder->MaxUTF16BufferLength(length);
   if (!needed.isValid() || needed.value() > UINT32_MAX) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   if (!_retval.SetLength(needed.value(), fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  auto src = MakeSpan(aData, aCount);
+  auto src = MakeSpan(reinterpret_cast<const uint8_t*>(aSrc.BeginReading()), length);
   uint32_t result;
   size_t read;
   size_t written;
   bool hadErrors;
   // The UTF-8 decoder used to throw regardless of the error behavior.
   // Simulating the old behavior for compatibility with legacy callers.
   // If callers want control over the behavior, they should switch to
   // TextDecoder.
@@ -152,17 +143,17 @@ nsScriptableUnicodeConverter::ConvertFro
     if (result != kInputEmpty) {
       return NS_ERROR_UDEC_ILLEGALINPUT;
     }
   } else {
     Tie(result, read, written, hadErrors) =
       mDecoder->DecodeToUTF16(src, _retval, false);
   }
   MOZ_ASSERT(result == kInputEmpty);
-  MOZ_ASSERT(read == aCount);
+  MOZ_ASSERT(read == length);
   MOZ_ASSERT(written <= needed.value());
   Unused << hadErrors;
   if (!_retval.SetLength(written, fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   return NS_OK;
 }