Bug 811127 - Text(De|En)coder("utf-16").encoding should return "utf-16le", not "utf-16". r=hsivonen
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Wed, 14 Nov 2012 21:01:07 -0500
changeset 113334 62fc36842e4417b2c999d40910bfdaf8e12410f7
parent 113333 3d61038df8830adbcb892d8a9de3ab35f4637f84
child 113335 2ce122f1e050b94ab3a97cf1a4de36586a99ddee
push id23869
push useremorley@mozilla.com
push dateThu, 15 Nov 2012 16:18:16 +0000
treeherdermozilla-central@a37525d304d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs811127
milestone19.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 811127 - Text(De|En)coder("utf-16").encoding should return "utf-16le", not "utf-16". r=hsivonen
dom/encoding/TextDecoder.cpp
dom/encoding/TextEncoder.cpp
dom/encoding/test/test_TextDecoder.js
dom/encoding/test/test_TextEncoder.js
dom/encoding/test/unit/test_singlebytes.js
--- a/dom/encoding/TextDecoder.cpp
+++ b/dom/encoding/TextDecoder.cpp
@@ -191,26 +191,16 @@ TextDecoder::FeedBytes(const char* aByte
   if (aOutString) {
     aOutString->Assign(buf, dstLen);
   }
 }
 
 void
 TextDecoder::GetEncoding(nsAString& aEncoding)
 {
-  // Our utf-16 converter does not comply with the Encoding Standard.
-  // As a result the utf-16le converter is used for the encoding label
-  // "utf-16".
-  // This workaround should not be exposed to the public API and so "utf-16"
-  // is returned by GetEncoding() if the internal encoding name is "utf-16le".
-  if (mEncoding.EqualsLiteral("UTF-16LE")) {
-    aEncoding.AssignLiteral("utf-16");
-    return;
-  }
-
   CopyASCIItoUTF16(mEncoding, aEncoding);
   nsContentUtils::ASCIIToLower(aEncoding);
 }
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(TextDecoder)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(TextDecoder)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextDecoder)
--- a/dom/encoding/TextEncoder.cpp
+++ b/dom/encoding/TextEncoder.cpp
@@ -96,26 +96,16 @@ TextEncoder::Encode(JSContext* aCx,
     aRv.Throw(rv);
   }
   return outView;
 }
 
 void
 TextEncoder::GetEncoding(nsAString& aEncoding)
 {
-  // Our utf-16 converter does not comply with the Encoding Standard.
-  // As a result the utf-16le converter is used for the encoding label
-  // "utf-16".
-  // This workaround should not be exposed to the public API and so "utf-16"
-  // is returned by GetEncoding() if the internal encoding name is "utf-16le".
-  if (mEncoding.EqualsLiteral("UTF-16LE")) {
-    aEncoding.AssignLiteral("utf-16");
-    return;
-  }
-
   CopyASCIItoUTF16(mEncoding, aEncoding);
   nsContentUtils::ASCIIToLower(aEncoding);
 }
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(TextEncoder)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(TextEncoder)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextEncoder)
--- a/dom/encoding/test/test_TextDecoder.js
+++ b/dom/encoding/test/test_TextDecoder.js
@@ -329,17 +329,17 @@ function testDecoderGetEncoding()
     {encoding: "gb18030", labels: ["gb18030"]},
     {encoding: "hz-gb-2312", labels: ["hz-gb-2312"]},
     {encoding: "big5", labels: ["big5", "big5-hkscs", "cn-big5", "csbig5", "x-x-big5"]},
     {encoding: "euc-jp", labels: ["cseucpkdfmtjapanese", "euc-jp", "x-euc-jp"]},
     {encoding: "iso-2022-jp", labels: ["csiso2022jp", "iso-2022-jp"]},
     {encoding: "shift_jis", labels: ["csshiftjis", "ms_kanji", "shift-jis", "shift_jis", "sjis", "windows-31j", "x-sjis"]},
     {encoding: "euc-kr", labels: ["cseuckr", "csksc56011987", "euc-kr", "iso-ir-149", "korean", "ks_c_5601-1987", "ks_c_5601-1989", "ksc5601", "ksc_5601", "windows-949"]},
     {encoding: "iso-2022-kr", labels: ["csiso2022kr", "iso-2022-kr"]},
-    {encoding: "utf-16", labels: ["utf-16", "utf-16le"]},
+    {encoding: "utf-16le", labels: ["utf-16", "utf-16le"]},
     {encoding: "utf-16be", labels: ["utf-16be"]},
     {encoding: "x-user-defined", labels: ["x-user-defined"]},
     {error: "TypeError", labels: ["x-windows-949", "\u0130SO-8859-1"]},
   ];
 
   for (var le of labelEncodings) {
     for (var label of le.labels) {
       try {
--- a/dom/encoding/test/test_TextEncoder.js
+++ b/dom/encoding/test/test_TextEncoder.js
@@ -259,17 +259,17 @@ function testArrayOfStrings(test)
     }
   }
 }
 
 function testEncoderGetEncoding()
 {
   var labelEncodings = [
     {encoding: "utf-8", labels: ["unicode-1-1-utf-8", "utf-8", "utf8"]},
-    {encoding: "utf-16", labels: ["utf-16", "utf-16le"]},
+    {encoding: "utf-16le", labels: ["utf-16", "utf-16"]},
     {encoding: "utf-16be", labels: ["utf-16be"]},
   ];
 
   for (var le of labelEncodings) {
     for (var label of le.labels) {
       var encoder = TextEncoder(label);
       assert_equals(encoder.encoding, le.encoding, label + " label encoding test.");
     }
--- a/dom/encoding/test/unit/test_singlebytes.js
+++ b/dom/encoding/test/unit/test_singlebytes.js
@@ -198,18 +198,18 @@ test(
   },
   "fatal flag"
 );
 
 test(
   function() {
     var encodings = [
       { label: 'utf-8', encoding: 'utf-8' },
-      { label: 'utf-16', encoding: 'utf-16' },
-      { label: 'utf-16le', encoding: 'utf-16' },
+      { label: 'utf-16', encoding: 'utf-16le' },
+      { label: 'utf-16le', encoding: 'utf-16le' },
       { label: 'utf-16be', encoding: 'utf-16be' },
       { label: 'ascii', encoding: 'windows-1252' },
       { label: 'iso-8859-1', encoding: 'windows-1252' }
     ];
 
     encodings.forEach(
       function(test) {
         assert_equals(TextDecoder(test.label.toLowerCase()).encoding, test.encoding);
@@ -251,17 +251,17 @@ test(
     assert_not_equals(TextDecoder('utf-16be').decode(new Uint8Array(utf16le_bom.concat(utf16be))), string);
   },
   "Byte-order marks"
 );
 
 test(
   function () {
     assert_equals(TextDecoder("utf-8").encoding, "utf-8"); // canonical case
-    assert_equals(TextDecoder("UTF-16").encoding, "utf-16"); // canonical case and name
+    assert_equals(TextDecoder("UTF-16").encoding, "utf-16le"); // canonical case and name
     assert_equals(TextDecoder("UTF-16BE").encoding, "utf-16be"); // canonical case and name
     assert_equals(TextDecoder("iso8859-1").encoding, "windows-1252"); // canonical case and name
     assert_equals(TextDecoder("iso-8859-1").encoding, "windows-1252"); // canonical case and name
   },
   "Encoding names"
 );
 
 test(
@@ -338,17 +338,17 @@ test(
     TextDecoder("utf-16be").decode(new Uint8Array([0x00]));
   },
   "Non-fatal errors at EOF"
 );
 
 test(
   function () {
 
-    var utf_encodings = ["utf-8", "utf-16", "utf-16be"];
+    var utf_encodings = ["utf-8", "utf-16le", "utf-16be"];
 
     var legacy_encodings = ["ibm866", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-8-i", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "iso-8859-16", "koi8-r", "koi8-u", "macintosh", "windows-874", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255", "windows-1256", "windows-1257", "windows-1258", "x-mac-cyrillic", "gbk", "gb18030", "hz-gb-2312", "big5", "euc-jp", "iso-2022-jp", "shift_jis", "euc-kr", "iso-2022-kr", "x-user-defined"];
 
     utf_encodings.forEach(function(encoding) {
       assert_equals(TextDecoder(encoding).encoding, encoding);
       assert_equals(TextEncoder(encoding).encoding, encoding);
     });