Bug 903772: Part 6 - Remove TextDecoderBase. r=emk
authorKyle Huey <khuey@kylehuey.com>
Thu, 22 Aug 2013 22:17:09 -0700
changeset 156926 dabbf6275092114f9cbfd1f4b2f6283c5089bbc2
parent 156925 94d0b33d4d8a17758ccc556a3560fea674e2ca1a
child 156927 3d866e6ca83a609ac1e1435a4fcdecb4899c97d3
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs903772
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 903772: Part 6 - Remove TextDecoderBase. r=emk
content/base/src/nsContentUtils.cpp
dom/encoding/TextDecoder.cpp
dom/encoding/TextDecoder.h
dom/encoding/TextDecoderBase.h
dom/encoding/moz.build
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -29,17 +29,17 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/Base64.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 #include "mozilla/dom/HTMLTemplateElement.h"
-#include "mozilla/dom/TextDecoderBase.h"
+#include "mozilla/dom/TextDecoder.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Selection.h"
 #include "mozilla/Util.h"
 #include "nsAString.h"
 #include "nsAttrName.h"
 #include "nsAttrValue.h"
 #include "nsAttrValueInlines.h"
@@ -3417,25 +3417,25 @@ nsContentUtils::ConvertStringFromCharset
 {
   if (aCharset.IsEmpty()) {
     // Treat the string as UTF8
     CopyUTF8toUTF16(aInput, aOutput);
     return NS_OK;
   }
 
   ErrorResult rv;
-  TextDecoderBase decoder;
-  decoder.Init(NS_ConvertUTF8toUTF16(aCharset), false, rv);
+  nsAutoPtr<TextDecoder> decoder(new TextDecoder());
+  decoder->Init(NS_ConvertUTF8toUTF16(aCharset), false, rv);
   if (rv.Failed()) {
     rv.ClearMessage();
     return rv.ErrorCode();
   }
 
-  decoder.Decode(aInput.BeginReading(), aInput.Length(), false,
-                 aOutput, rv);
+  decoder->Decode(aInput.BeginReading(), aInput.Length(), false,
+                  aOutput, rv);
   return rv.ErrorCode();
 }
 
 /* static */
 bool
 nsContentUtils::CheckForBOM(const unsigned char* aBuffer, uint32_t aLength,
                             nsACString& aCharset)
 {
--- a/dom/encoding/TextDecoder.cpp
+++ b/dom/encoding/TextDecoder.cpp
@@ -9,18 +9,18 @@
 #include "nsServiceManagerUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 static const PRUnichar kReplacementChar = static_cast<PRUnichar>(0xFFFD);
 
 void
-TextDecoderBase::Init(const nsAString& aEncoding, const bool aFatal,
-                      ErrorResult& aRv)
+TextDecoder::Init(const nsAString& aEncoding, const bool aFatal,
+                  ErrorResult& aRv)
 {
   nsAutoString label(aEncoding);
   EncodingUtils::TrimSpaceCharacters(label);
 
   // Let encoding be the result of getting an encoding from label.
   // If encoding is failure, throw a TypeError.
   if (!EncodingUtils::FindEncodingForLabel(label, mEncoding)) {
     aRv.ThrowTypeError(MSG_ENCODING_NOT_SUPPORTED, &label);
@@ -47,19 +47,19 @@ TextDecoderBase::Init(const nsAString& a
   }
 
   if (mFatal) {
     mDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
   }
 }
 
 void
-TextDecoderBase::Decode(const char* aInput, const int32_t aLength,
-                        const bool aStream, nsAString& aOutDecodedString,
-                        ErrorResult& aRv)
+TextDecoder::Decode(const char* aInput, const int32_t aLength,
+                    const bool aStream, nsAString& aOutDecodedString,
+                    ErrorResult& aRv)
 {
   aOutDecodedString.Truncate();
 
   // Run or resume the decoder algorithm of the decoder object's encoder.
   int32_t outLen;
   nsresult rv = mDecoder->GetMaxLength(aInput, aLength, &outLen);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
@@ -96,16 +96,16 @@ TextDecoderBase::Decode(const char* aInp
   }
 
   if (NS_FAILED(rv)) {
     aRv.Throw(NS_ERROR_DOM_ENCODING_DECODE_ERR);
   }
 }
 
 void
-TextDecoderBase::GetEncoding(nsAString& aEncoding)
+TextDecoder::GetEncoding(nsAString& aEncoding)
 {
   CopyASCIItoUTF16(mEncoding, aEncoding);
   nsContentUtils::ASCIIToLower(aEncoding);
 }
 
 } // dom
 } // mozilla
--- a/dom/encoding/TextDecoder.h
+++ b/dom/encoding/TextDecoder.h
@@ -1,23 +1,28 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_textdecoder_h_
 #define mozilla_dom_textdecoder_h_
 
-#include "mozilla/dom/TextDecoderBase.h"
+#include "mozilla/dom/NonRefcountedDOMObject.h"
 #include "mozilla/dom/TextDecoderBinding.h"
+#include "mozilla/dom/TypedArray.h"
+#include "nsIUnicodeDecoder.h"
 
 namespace mozilla {
+
+class ErrorResult;
+
 namespace dom {
 
 class TextDecoder MOZ_FINAL
-  : public NonRefcountedDOMObject, public TextDecoderBase
+  : public NonRefcountedDOMObject
 {
 public:
   // The WebIDL constructor.
   static TextDecoder*
   Constructor(const GlobalObject& aGlobal,
               const nsAString& aEncoding,
               const TextDecoderOptions& aOptions,
               ErrorResult& aRv)
@@ -26,49 +31,92 @@ public:
     txtDecoder->Init(aEncoding, aOptions.mFatal, aRv);
     if (aRv.Failed()) {
       return nullptr;
     }
     return txtDecoder.forget();
   }
 
   TextDecoder()
+    : mFatal(false)
   {
+    MOZ_COUNT_CTOR(TextDecoder);
   }
 
-  virtual
   ~TextDecoder()
-  {}
+  {
+    MOZ_COUNT_DTOR(TextDecoder);
+  }
 
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope,
                        bool* aTookOwnership)
   {
     return TextDecoderBinding::Wrap(aCx, aScope, this, aTookOwnership);
   }
 
   nsISupports*
   GetParentObject()
   {
     return nullptr;
   }
 
+  /**
+   * Validates provided encoding and throws an exception if invalid encoding.
+   * If no encoding is provided then mEncoding is default initialised to "utf-8".
+   *
+   * @param aEncoding    Optional encoding (case insensitive) provided.
+   *                     Default value is "utf-8" if no encoding is provided.
+   * @param aFatal       aFatal, indicates whether to throw an 'EncodingError'
+   *                     exception or not.
+   * @return aRv         EncodingError exception else null.
+   */
+  void Init(const nsAString& aEncoding, const bool aFatal, ErrorResult& aRv);
+
+  /**
+   * Return the encoding name.
+   *
+   * @param aEncoding, current encoding.
+   */
+  void GetEncoding(nsAString& aEncoding);
+
+  /**
+   * Decodes incoming byte stream of characters in charset indicated by
+   * encoding.
+   *
+   * The encoding algorithm state is reset if aOptions.mStream is not set.
+   *
+   * If the fatal flag is set then a decoding error will throw EncodingError.
+   * Else the decoder will return a decoded string with replacement
+   * character(s) for unidentified character(s).
+   *
+   * @param      aView, incoming byte stream of characters to be decoded to
+   *                    to UTF-16 code points.
+   * @param      aOptions, indicates if streaming or not.
+   * @param      aOutDecodedString, decoded string of UTF-16 code points.
+   * @param      aRv, error result.
+   */
+  void Decode(const char* aInput, const int32_t aLength,
+              const bool aStream, nsAString& aOutDecodedString,
+              ErrorResult& aRv);
+
   void Decode(nsAString& aOutDecodedString,
               ErrorResult& aRv) {
-    TextDecoderBase::Decode(nullptr, 0, false,
-                            aOutDecodedString, aRv);
+    Decode(nullptr, 0, false, aOutDecodedString, aRv);
   }
 
   void Decode(const ArrayBufferView& aView,
               const TextDecodeOptions& aOptions,
               nsAString& aOutDecodedString,
               ErrorResult& aRv) {
-    TextDecoderBase::Decode(reinterpret_cast<char*>(aView.Data()),
-                            aView.Length(), aOptions.mStream,
-                            aOutDecodedString, aRv);
+    Decode(reinterpret_cast<char*>(aView.Data()), aView.Length(),
+           aOptions.mStream, aOutDecodedString, aRv);
   }
 
 private:
+  nsCString mEncoding;
+  nsCOMPtr<nsIUnicodeDecoder> mDecoder;
+  bool mFatal;
 };
 
 } // dom
 } // mozilla
 
 #endif // mozilla_dom_textdecoder_h_
deleted file mode 100644
--- a/dom/encoding/TextDecoderBase.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_textdecoderbase_h_
-#define mozilla_dom_textdecoderbase_h_
-
-#include "mozilla/dom/BindingUtils.h"
-#include "mozilla/dom/TypedArray.h"
-#include "nsIUnicodeDecoder.h"
-
-namespace mozilla {
-class ErrorResult;
-
-namespace dom {
-
-class TextDecoderBase
-{
-public:
-  TextDecoderBase()
-    : mFatal(false)
-  {}
-
-  virtual
-  ~TextDecoderBase()
-  {}
-
-  /**
-   * Validates provided encoding and throws an exception if invalid encoding.
-   * If no encoding is provided then mEncoding is default initialised to "utf-8".
-   *
-   * @param aEncoding    Optional encoding (case insensitive) provided.
-   *                     Default value is "utf-8" if no encoding is provided.
-   * @param aFatal       aFatal, indicates whether to throw an 'EncodingError'
-   *                     exception or not.
-   * @return aRv         EncodingError exception else null.
-   */
-  void Init(const nsAString& aEncoding, const bool aFatal, ErrorResult& aRv);
-
-  /**
-   * Return the encoding name.
-   *
-   * @param aEncoding, current encoding.
-   */
-  void GetEncoding(nsAString& aEncoding);
-
-  /**
-   * Decodes incoming byte stream of characters in charset indicated by
-   * encoding.
-   *
-   * The encoding algorithm state is reset if aOptions.mStream is not set.
-   *
-   * If the fatal flag is set then a decoding error will throw EncodingError.
-   * Else the decoder will return a decoded string with replacement
-   * character(s) for unidentified character(s).
-   *
-   * @param      aView, incoming byte stream of characters to be decoded to
-   *                    to UTF-16 code points.
-   * @param      aOptions, indicates if streaming or not.
-   * @param      aOutDecodedString, decoded string of UTF-16 code points.
-   * @param      aRv, error result.
-   */
-  void Decode(const char* aInput, const int32_t aLength,
-              const bool aStream, nsAString& aOutDecodedString,
-              ErrorResult& aRv);
-
-private:
-  nsCString mEncoding;
-  nsCOMPtr<nsIUnicodeDecoder> mDecoder;
-  bool mFatal;
-};
-
-} // dom
-} // mozilla
-
-#endif // mozilla_dom_textdecoderbase_h_
--- a/dom/encoding/moz.build
+++ b/dom/encoding/moz.build
@@ -6,17 +6,16 @@
 
 TEST_DIRS += ['test']
 
 MODULE = 'dom'
 
 EXPORTS.mozilla.dom += [
     'EncodingUtils.h',
     'TextDecoder.h',
-    'TextDecoderBase.h',
     'TextEncoder.h',
     'TextEncoderBase.h',
 ]
 
 CPP_SOURCES += [
     'EncodingUtils.cpp',
     'TextDecoder.cpp',
     'TextEncoder.cpp',