Bug 801487 - Change some exceptions from EncodingError to TypeError. r=sicking
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Tue, 06 Nov 2012 18:23:14 -0500
changeset 112476 4aeebb3cacfa9bd7093cd4580ea40037e58af7ea
parent 112475 71c0fa0964c3a7a667357bb82d4a7d3f9986f807
child 112477 6c91d0bc259e203a2adb9fbe803d73b587eaaa67
push id17604
push userryanvm@gmail.com
push dateTue, 06 Nov 2012 23:23:20 +0000
treeherdermozilla-inbound@11ff92705a23 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs801487
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 801487 - Change some exceptions from EncodingError to TypeError. r=sicking
dom/encoding/TextDecoder.cpp
dom/encoding/TextEncoder.cpp
dom/encoding/test/test_BOMEncoding.js
dom/encoding/test/test_TextDecoder.js
dom/encoding/test/test_TextEncoder.js
--- a/dom/encoding/TextDecoder.cpp
+++ b/dom/encoding/TextDecoder.cpp
@@ -26,21 +26,20 @@ TextDecoder::Init(const nsAString& aEnco
   if (label.LowerCaseEqualsLiteral("utf-16")) {
     mUseBOM = true;
     mIsUTF16Family = true;
     mEncoding = "utf-16le";
     // If BOM is used, we can't determine the converter yet.
     return;
   }
 
-  // Run the steps to get an encoding from Encoding.
+  // Let encoding be the result of getting an encoding from label.
+  // If encoding is failure, throw a TypeError.
   if (!EncodingUtils::FindEncodingForLabel(label, mEncoding)) {
-    // If the steps result in failure,
-    // throw a "EncodingError" exception and terminate these steps.
-    aRv.Throw(NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
+    aRv.ThrowTypeError(MSG_ENCODING_NOT_SUPPORTED, &label);
     return;
   }
 
   mIsUTF16Family = !strcmp(mEncoding, "utf-16le") ||
                    !strcmp(mEncoding, "utf-16be");
 
   // If the constructor is called with an options argument,
   // and the fatal property of the dictionary is set,
--- a/dom/encoding/TextEncoder.cpp
+++ b/dom/encoding/TextEncoder.cpp
@@ -13,31 +13,28 @@ namespace dom {
 
 void
 TextEncoder::Init(const nsAString& aEncoding,
                   ErrorResult& aRv)
 {
   nsAutoString label(aEncoding);
   EncodingUtils::TrimSpaceCharacters(label);
 
-  // Run the steps to get an encoding from Encoding.
+  // Let encoding be the result of getting an encoding from label.
+  // If encoding is failure, or is none of utf-8, utf-16, and utf-16be,
+  // throw a TypeError.
   if (!EncodingUtils::FindEncodingForLabel(label, mEncoding)) {
-    // If the steps result in failure,
-    // throw an "EncodingError" exception and terminate these steps.
-    aRv.Throw(NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
+    aRv.ThrowTypeError(MSG_ENCODING_NOT_SUPPORTED, &label);
     return;
   }
 
-  // Otherwise, if the Name of the returned encoding is not one of
-  // "utf-8", "utf-16", or "utf-16be" throw an "EncodingError" exception
-  // and terminate these steps.
   if (PL_strcasecmp(mEncoding, "utf-8") &&
       PL_strcasecmp(mEncoding, "utf-16le") &&
       PL_strcasecmp(mEncoding, "utf-16be")) {
-    aRv.Throw(NS_ERROR_DOM_ENCODING_NOT_UTF_ERR);
+    aRv.ThrowTypeError(MSG_DOM_ENCODING_NOT_UTF);
     return;
   }
 
   // Create an encoder object for mEncoding.
   nsCOMPtr<nsICharsetConverterManager> ccm =
     do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID);
   if (!ccm) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
--- a/dom/encoding/test/test_BOMEncoding.js
+++ b/dom/encoding/test/test_BOMEncoding.js
@@ -41,17 +41,17 @@ function testBOMEncodingUTF8() {
   // test valid encoding provided with invalid byte OM also provided.
   data = [0xFF, 0xFE, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27];
   expectedString = "\ufffd\ufffd !\"#$%&'";
   testBOMCharset({encoding: "utf-8", data: data, expected: expectedString,
                   msg: "valid utf-8 encoding provided with invalid utf-8 BOM test."});
 
   // test empty encoding provided with invalid byte OM also provided.
   data = [0xFF, 0xFE, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27];
-  testBOMCharset({encoding: "", data: data, error: "EncodingError",
+  testBOMCharset({encoding: "", data: data, error: "TypeError",
                   msg: "empty encoding provided with invalid utf-8 BOM test."});
 }
 
 function testMoreBOMEncoding() {
   var expectedString = "\"\u0412\u0441\u0435 \u0441\u0447\u0430\u0441\u0442\u043B\u0438\u0432\u044B\u0435 \u0441\u0435\u043C\u044C\u0438 \u043F\u043E\u0445\u043E\u0436\u0438 \u0434\u0440\u0443\u0433 \u043D\u0430 \u0434\u0440\u0443\u0433\u0430, \u043A\u0430\u0436\u0434\u0430\u044F \u043D\u0435\u0441\u0447\u0430\u0441\u0442\u043B\u0438\u0432\u0430\u044F \u0441\u0435\u043C\u044C\u044F \u043D\u0435\u0441\u0447\u0430\u0441\u0442\u043B\u0438\u0432\u0430 \u043F\u043E-\u0441\u0432\u043E\u0435\u043C\u0443.\"";
 
  // Testing user provided encoding is UTF-16BE & bom encoding is utf-16le
   var data = [0xFF, 0xFE, 0x00, 0x22, 0x04, 0x12, 0x04, 0x41, 0x04, 0x35, 0x00, 0x20, 0x04, 0x41, 0x04, 0x47, 0x04, 0x30, 0x04, 0x41, 0x04, 0x42, 0x04, 0x3B, 0x04, 0x38, 0x04, 0x32, 0x04, 0x4B, 0x04, 0x35, 0x00, 0x20, 0x04, 0x41, 0x04, 0x35, 0x04, 0x3C, 0x04, 0x4C, 0x04, 0x38, 0x00, 0x20, 0x04, 0x3F, 0x04, 0x3E, 0x04, 0x45, 0x04, 0x3E, 0x04, 0x36, 0x04, 0x38, 0x00, 0x20, 0x04, 0x34, 0x04, 0x40, 0x04, 0x43, 0x04, 0x33, 0x00, 0x20, 0x04, 0x3D, 0x04, 0x30, 0x00, 0x20, 0x04, 0x34, 0x04, 0x40, 0x04, 0x43, 0x04, 0x33, 0x04, 0x30, 0x00, 0x2C, 0x00, 0x20, 0x04, 0x3A, 0x04, 0x30, 0x04, 0x36, 0x04, 0x34, 0x04, 0x30, 0x04, 0x4F, 0x00, 0x20, 0x04, 0x3D, 0x04, 0x35, 0x04, 0x41, 0x04, 0x47, 0x04, 0x30, 0x04, 0x41, 0x04, 0x42, 0x04, 0x3B, 0x04, 0x38, 0x04, 0x32, 0x04, 0x30, 0x04, 0x4F, 0x00, 0x20, 0x04, 0x41, 0x04, 0x35, 0x04, 0x3C, 0x04, 0x4C, 0x04, 0x4F, 0x00, 0x20, 0x04, 0x3D, 0x04, 0x35, 0x04, 0x41, 0x04, 0x47, 0x04, 0x30, 0x04, 0x41, 0x04, 0x42, 0x04, 0x3B, 0x04, 0x38, 0x04, 0x32, 0x04, 0x30, 0x00, 0x20, 0x04, 0x3F, 0x04, 0x3E, 0x00, 0x2D, 0x04, 0x41, 0x04, 0x32, 0x04, 0x3E, 0x04, 0x35, 0x04, 0x3C, 0x04, 0x43, 0x00, 0x2E, 0x00, 0x22];
--- a/dom/encoding/test/test_TextDecoder.js
+++ b/dom/encoding/test/test_TextDecoder.js
@@ -67,29 +67,29 @@ function testConstructorFatalOption(data
 
 function testConstructorEncodingOption(aData, aExpectedString)
 {
   // valid encoding passed
   testCharset({encoding: "iso-8859-11", input: aData, expected: aExpectedString,
     msg: "decoder testing constructor valid encoding."});
 
   // invalid encoding passed
-  testCharset({encoding: "asdfasdf", input: aData, error: "EncodingError",
+  testCharset({encoding: "asdfasdf", input: aData, error: "TypeError",
     msg: "constructor encoding, invalid encoding test."});
 
   // passing spaces for encoding
-  testCharset({encoding: "   ", input: aData, error: "EncodingError",
+  testCharset({encoding: "   ", input: aData, error: "TypeError",
     msg: "constructor encoding, spaces encoding test."});
 
   // passing null for encoding
-  testCharset({encoding: null, input: aData, error: "EncodingError",
+  testCharset({encoding: null, input: aData, error: "TypeError",
     msg: "constructor encoding, \"null\" encoding test."});
 
   // empty encoding passed
-  testCharset({encoding: "", input: aData, error: "EncodingError",
+  testCharset({encoding: "", input: aData, error: "TypeError",
     msg: "constuctor encoding, empty encoding test."});
 
   // replacement character test
   aExpectedString = "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd"
                   + "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd"
                   + "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd"
                   + "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd"
                   + "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd"
@@ -332,17 +332,17 @@ function testDecoderGetEncoding()
     {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-16be", labels: ["utf-16be"]},
     {encoding: "x-user-defined", labels: ["x-user-defined"]},
-    {error: "EncodingError", labels: ["x-windows-949", "\u0130SO-8859-1"]},
+    {error: "TypeError", labels: ["x-windows-949", "\u0130SO-8859-1"]},
   ];
 
   for (var le of labelEncodings) {
     for (var label of le.labels) {
       try {
         var decoder = TextDecoder(label);
       } catch (e) {
         assert_true(!!le.error, label + " shoud not throw " + e.name);
--- a/dom/encoding/test/test_TextEncoder.js
+++ b/dom/encoding/test/test_TextEncoder.js
@@ -90,36 +90,36 @@ function testEncodeUTF16ToUTF16()
 
 function testConstructorEncodingOption(aData, aExpectedString)
 {
   // valid encoding passed
   testSingleString({encoding: "UTF-8", input: aData, expected: aExpectedString,
     msg: "testing encoding with valid utf-8 encoding."});
 
   // passing spaces for encoding
-  testSingleString({encoding: "   ", input: aData, error: "EncodingError",
+  testSingleString({encoding: "   ", input: aData, error: "TypeError",
     msg: "constructor encoding, spaces encoding test."});
 
   // invalid encoding passed
-  testSingleString({encoding: "asdfasdf", input: aData, error: "EncodingError",
+  testSingleString({encoding: "asdfasdf", input: aData, error: "TypeError",
     msg: "constructor encoding, invalid encoding test."});
 
   // null encoding passed
-  testSingleString({encoding: null, input: aData, error: "EncodingError",
+  testSingleString({encoding: null, input: aData, error: "TypeError",
     msg: "constructor encoding, \"null\" encoding test."});
 
   // null encoding passed
-  testSingleString({encoding: "", input: aData, error: "EncodingError",
+  testSingleString({encoding: "", input: aData, error: "TypeError",
     msg: "constructor encoding, empty encoding test."});
 }
 
 function testEncodingValues(aData, aExpectedString)
 {
   var encoding = "ISO-8859-11";
-  testSingleString({encoding: aData, input: encoding, error: "EncodingError",
+  testSingleString({encoding: aData, input: encoding, error: "TypeError",
     msg: "encoder encoding values test."});
 }
 
 function testInputString(aData, aExpectedString)
 {
   //Test null input string
   testSingleString({encoding: "utf-8", input: "", expected: [],
     msg: "encoder null input string test."});