From c95b61723c6f9f36a4f3e04e025a10488e20489b Mon Sep 17 00:00:00 2001 From: Masatoshi Kimura Date: Tue, 6 Nov 2012 18:23:14 -0500 Subject: [PATCH] Bug 801487 - Change some exceptions from EncodingError to TypeError. r=sicking --- dom/encoding/TextDecoder.cpp | 7 +++---- dom/encoding/TextEncoder.cpp | 13 +++++-------- dom/encoding/test/test_BOMEncoding.js | 2 +- dom/encoding/test/test_TextDecoder.js | 10 +++++----- dom/encoding/test/test_TextEncoder.js | 10 +++++----- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/dom/encoding/TextDecoder.cpp b/dom/encoding/TextDecoder.cpp index 1f808f5b591..cc4c04d88b0 100644 --- a/dom/encoding/TextDecoder.cpp +++ b/dom/encoding/TextDecoder.cpp @@ -31,11 +31,10 @@ TextDecoder::Init(const nsAString& aEncoding, 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; } diff --git a/dom/encoding/TextEncoder.cpp b/dom/encoding/TextEncoder.cpp index 6d98af59fcf..8823a39a725 100644 --- a/dom/encoding/TextEncoder.cpp +++ b/dom/encoding/TextEncoder.cpp @@ -18,21 +18,18 @@ TextEncoder::Init(const nsAString& aEncoding, 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; } diff --git a/dom/encoding/test/test_BOMEncoding.js b/dom/encoding/test/test_BOMEncoding.js index b8b4a644e91..7b86fda2b1d 100644 --- a/dom/encoding/test/test_BOMEncoding.js +++ b/dom/encoding/test/test_BOMEncoding.js @@ -46,7 +46,7 @@ function testBOMEncodingUTF8() { // 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."}); } diff --git a/dom/encoding/test/test_TextDecoder.js b/dom/encoding/test/test_TextDecoder.js index 383f7a2a124..21ef1ca1c55 100644 --- a/dom/encoding/test/test_TextDecoder.js +++ b/dom/encoding/test/test_TextDecoder.js @@ -72,19 +72,19 @@ function testConstructorEncodingOption(aData, 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 @@ -337,7 +337,7 @@ function testDecoderGetEncoding() {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) { diff --git a/dom/encoding/test/test_TextEncoder.js b/dom/encoding/test/test_TextEncoder.js index bcb7fb524c5..180aab1320c 100644 --- a/dom/encoding/test/test_TextEncoder.js +++ b/dom/encoding/test/test_TextEncoder.js @@ -95,26 +95,26 @@ function testConstructorEncodingOption(aData, 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."}); }