Bug 825195 - Update method signatures of TextDecoder and TextEncoder per the latest spec. r=jonas
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 29 Dec 2012 09:55:32 +0900
changeset 117206 abfe3957551b2a11ba2dc601a0d5a24ba24e8f38
parent 117205 8aa341f3e3a6736c12104bf57701db9ffc2d983c
child 117207 0ed0898de7b509b5fe273b760c351ac64b79ef1c
push id24087
push usergraememcc_firefox@graeme-online.co.uk
push dateSat, 29 Dec 2012 12:13:53 +0000
treeherdermozilla-central@b5ea211f23a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonas
bugs825195
milestone20.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 825195 - Update method signatures of TextDecoder and TextEncoder per the latest spec. r=jonas
dom/encoding/TextDecoder.cpp
dom/encoding/TextDecoder.h
dom/encoding/TextDecoderBase.h
dom/encoding/test/test_TextDecoder.js
dom/webidl/TextDecoder.webidl
dom/webidl/TextEncoder.webidl
dom/workers/TextDecoder.h
--- a/dom/encoding/TextDecoder.cpp
+++ b/dom/encoding/TextDecoder.cpp
@@ -47,51 +47,40 @@ TextDecoderBase::Init(const nsAString& a
   }
 
   if (mFatal) {
     mDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
   }
 }
 
 void
-TextDecoderBase::Decode(const ArrayBufferView* aView,
-                        const bool aStream,
-                        nsAString& aOutDecodedString,
+TextDecoderBase::Decode(const char* aInput, const int32_t aLength,
+                        const bool aStream, nsAString& aOutDecodedString,
                         ErrorResult& aRv)
 {
-  const char* data;
-  int32_t length;
-  // If view is not specified, let view be a Uint8Array of length 0.
-  if (!aView) {
-    data = EmptyCString().BeginReading();
-    length = EmptyCString().Length();
-  } else {
-    data = reinterpret_cast<const char*>(aView->Data());
-    length = aView->Length();
-  }
-
   aOutDecodedString.Truncate();
 
   // Run or resume the decoder algorithm of the decoder object's encoder.
   int32_t outLen;
-  nsresult rv = mDecoder->GetMaxLength(data, length, &outLen);
+  nsresult rv = mDecoder->GetMaxLength(aInput, aLength, &outLen);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return;
   }
   // Need a fallible allocator because the caller may be a content
   // and the content can specify the length of the string.
   static const fallible_t fallible = fallible_t();
   nsAutoArrayPtr<PRUnichar> buf(new (fallible) PRUnichar[outLen + 1]);
   if (!buf) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return;
   }
 
-  rv = mDecoder->Convert(data, &length, buf, &outLen);
+  int32_t length = aLength;
+  rv = mDecoder->Convert(aInput, &length, buf, &outLen);
   MOZ_ASSERT(mFatal || rv != NS_ERROR_ILLEGAL_INPUT);
   buf[outLen] = 0;
   aOutDecodedString.Append(buf, outLen);
 
   // If the internal streaming flag of the decoder object is not set,
   // then reset the encoding algorithm state to the default values
   if (!aStream) {
     mDecoder->Reset();
--- a/dom/encoding/TextDecoder.h
+++ b/dom/encoding/TextDecoder.h
@@ -51,22 +51,29 @@ public:
   }
 
   nsISupports*
   GetParentObject()
   {
     return mGlobal;
   }
 
-  void Decode(const ArrayBufferView* aView,
+  void Decode(nsAString& aOutDecodedString,
+              ErrorResult& aRv) {
+    TextDecoderBase::Decode(nullptr, 0, false,
+                            aOutDecodedString, aRv);
+  }
+
+  void Decode(const ArrayBufferView& aView,
               const TextDecodeOptions& aOptions,
               nsAString& aOutDecodedString,
               ErrorResult& aRv) {
-    return TextDecoderBase::Decode(aView, aOptions.mStream,
-                                   aOutDecodedString, aRv);
+    TextDecoderBase::Decode(reinterpret_cast<char*>(aView.Data()),
+                            aView.Length(), aOptions.mStream,
+                            aOutDecodedString, aRv);
   }
 
 private:
   nsCOMPtr<nsISupports> mGlobal;
 };
 
 } // dom
 } // mozilla
--- a/dom/encoding/TextDecoderBase.h
+++ b/dom/encoding/TextDecoderBase.h
@@ -56,18 +56,19 @@ public:
    * 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 ArrayBufferView* aView, const bool aStream,
-              nsAString& aOutDecodedString, ErrorResult& aRv);
+  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
--- a/dom/encoding/test/test_TextDecoder.js
+++ b/dom/encoding/test/test_TextDecoder.js
@@ -256,17 +256,17 @@ function testDecodeABVOption(data, expec
   // spaces
   testCharset({encoding: "iso-8859-11", input: ["\u0020\u0020"], expected: "\0",
     msg: "text decoding ABV string test."});
 
   testCharset({encoding: "iso-8859-11", input: [""], expected: "\0",
     msg: "text decoding ABV empty string test."});
 
   // null for Array Buffer
-  testCharset({encoding: "iso-8859-11", input: null, expected: "",
+  testCharset({encoding: "iso-8859-11", input: null, error: "TypeError",
     msg: "text decoding ABV null test."});
 }
 
 function testDecodeGreek()
 {
   var data = [0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8,
               0xa9, 0xaa, 0xab, 0xac, 0xad, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
               0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
--- a/dom/webidl/TextDecoder.webidl
+++ b/dom/webidl/TextDecoder.webidl
@@ -10,17 +10,19 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 [Constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options)]
 interface TextDecoder {
   [Constant]
   readonly attribute DOMString encoding;
   [Throws]
-  DOMString decode(optional ArrayBufferView? input = null, optional TextDecodeOptions options);
+  DOMString decode();
+  [Throws]
+  DOMString decode(ArrayBufferView input, optional TextDecodeOptions options);
 };
 
 dictionary TextDecoderOptions {
   boolean fatal = false;
 };
 
 dictionary TextDecodeOptions {
   boolean stream = false;
--- a/dom/webidl/TextEncoder.webidl
+++ b/dom/webidl/TextEncoder.webidl
@@ -5,20 +5,20 @@
  *
  * The origin of this IDL file is
  * http://encoding.spec.whatwg.org/#interface-textencoder
  *
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-[Constructor(optional DOMString label = "utf-8")]
+[Constructor(optional DOMString utfLabel = "utf-8")]
 interface TextEncoder {
   [Constant]
   readonly attribute DOMString encoding;
   [Throws]
-  Uint8Array encode(optional DOMString? input = null, optional TextEncodeOptions options);
+  Uint8Array encode(optional DOMString input = "", optional TextEncodeOptions options);
 };
 
 dictionary TextEncodeOptions {
   boolean stream = false;
 };
 
--- a/dom/workers/TextDecoder.h
+++ b/dom/workers/TextDecoder.h
@@ -33,20 +33,28 @@ public:
 
   static TextDecoder*
   Constructor(JSContext* aCx, JSObject* aObj,
               const nsAString& aEncoding,
               const TextDecoderOptionsWorkers& aOptions,
               ErrorResult& aRv);
 
   void
-  Decode(const ArrayBufferView* aView,
+  Decode(nsAString& aOutDecodedString,
+         ErrorResult& aRv) {
+    TextDecoderBase::Decode(nullptr, 0, false,
+                            aOutDecodedString, aRv);
+  }
+
+  void
+  Decode(const ArrayBufferView& aView,
          const TextDecodeOptionsWorkers& aOptions,
          nsAString& aOutDecodedString,
          ErrorResult& aRv) {
-    return TextDecoderBase::Decode(aView, aOptions.mStream,
-                                   aOutDecodedString, aRv);
+    TextDecoderBase::Decode(reinterpret_cast<char*>(aView.Data()),
+                            aView.Length(), aOptions.mStream,
+                            aOutDecodedString, aRv);
   }
 };
 
 END_WORKERS_NAMESPACE
 
 #endif // mozilla_dom_workers_textdecoder_h_