Bug 801487 - Change some exceptions from EncodingError to TypeError. r=sicking

This commit is contained in:
Masatoshi Kimura 2012-11-06 18:23:14 -05:00
parent 32a0cfd0f7
commit c95b61723c
5 changed files with 19 additions and 23 deletions

View File

@ -31,11 +31,10 @@ TextDecoder::Init(const nsAString& aEncoding,
return; 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 (!EncodingUtils::FindEncodingForLabel(label, mEncoding)) {
// If the steps result in failure, aRv.ThrowTypeError(MSG_ENCODING_NOT_SUPPORTED, &label);
// throw a "EncodingError" exception and terminate these steps.
aRv.Throw(NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
return; return;
} }

View File

@ -18,21 +18,18 @@ TextEncoder::Init(const nsAString& aEncoding,
nsAutoString label(aEncoding); nsAutoString label(aEncoding);
EncodingUtils::TrimSpaceCharacters(label); 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 (!EncodingUtils::FindEncodingForLabel(label, mEncoding)) {
// If the steps result in failure, aRv.ThrowTypeError(MSG_ENCODING_NOT_SUPPORTED, &label);
// throw an "EncodingError" exception and terminate these steps.
aRv.Throw(NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
return; 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") && if (PL_strcasecmp(mEncoding, "utf-8") &&
PL_strcasecmp(mEncoding, "utf-16le") && PL_strcasecmp(mEncoding, "utf-16le") &&
PL_strcasecmp(mEncoding, "utf-16be")) { PL_strcasecmp(mEncoding, "utf-16be")) {
aRv.Throw(NS_ERROR_DOM_ENCODING_NOT_UTF_ERR); aRv.ThrowTypeError(MSG_DOM_ENCODING_NOT_UTF);
return; return;
} }

View File

@ -46,7 +46,7 @@ function testBOMEncodingUTF8() {
// test empty encoding provided with invalid byte OM also provided. // test empty encoding provided with invalid byte OM also provided.
data = [0xFF, 0xFE, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27]; 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."}); msg: "empty encoding provided with invalid utf-8 BOM test."});
} }

View File

@ -72,19 +72,19 @@ function testConstructorEncodingOption(aData, aExpectedString)
msg: "decoder testing constructor valid encoding."}); msg: "decoder testing constructor valid encoding."});
// invalid encoding passed // invalid encoding passed
testCharset({encoding: "asdfasdf", input: aData, error: "EncodingError", testCharset({encoding: "asdfasdf", input: aData, error: "TypeError",
msg: "constructor encoding, invalid encoding test."}); msg: "constructor encoding, invalid encoding test."});
// passing spaces for encoding // passing spaces for encoding
testCharset({encoding: " ", input: aData, error: "EncodingError", testCharset({encoding: " ", input: aData, error: "TypeError",
msg: "constructor encoding, spaces encoding test."}); msg: "constructor encoding, spaces encoding test."});
// passing null for encoding // passing null for encoding
testCharset({encoding: null, input: aData, error: "EncodingError", testCharset({encoding: null, input: aData, error: "TypeError",
msg: "constructor encoding, \"null\" encoding test."}); msg: "constructor encoding, \"null\" encoding test."});
// empty encoding passed // empty encoding passed
testCharset({encoding: "", input: aData, error: "EncodingError", testCharset({encoding: "", input: aData, error: "TypeError",
msg: "constuctor encoding, empty encoding test."}); msg: "constuctor encoding, empty encoding test."});
// replacement character test // replacement character test
@ -337,7 +337,7 @@ function testDecoderGetEncoding()
{encoding: "utf-16", labels: ["utf-16", "utf-16le"]}, {encoding: "utf-16", labels: ["utf-16", "utf-16le"]},
{encoding: "utf-16be", labels: ["utf-16be"]}, {encoding: "utf-16be", labels: ["utf-16be"]},
{encoding: "x-user-defined", labels: ["x-user-defined"]}, {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 le of labelEncodings) {

View File

@ -95,26 +95,26 @@ function testConstructorEncodingOption(aData, aExpectedString)
msg: "testing encoding with valid utf-8 encoding."}); msg: "testing encoding with valid utf-8 encoding."});
// passing spaces for encoding // passing spaces for encoding
testSingleString({encoding: " ", input: aData, error: "EncodingError", testSingleString({encoding: " ", input: aData, error: "TypeError",
msg: "constructor encoding, spaces encoding test."}); msg: "constructor encoding, spaces encoding test."});
// invalid encoding passed // invalid encoding passed
testSingleString({encoding: "asdfasdf", input: aData, error: "EncodingError", testSingleString({encoding: "asdfasdf", input: aData, error: "TypeError",
msg: "constructor encoding, invalid encoding test."}); msg: "constructor encoding, invalid encoding test."});
// null encoding passed // null encoding passed
testSingleString({encoding: null, input: aData, error: "EncodingError", testSingleString({encoding: null, input: aData, error: "TypeError",
msg: "constructor encoding, \"null\" encoding test."}); msg: "constructor encoding, \"null\" encoding test."});
// null encoding passed // null encoding passed
testSingleString({encoding: "", input: aData, error: "EncodingError", testSingleString({encoding: "", input: aData, error: "TypeError",
msg: "constructor encoding, empty encoding test."}); msg: "constructor encoding, empty encoding test."});
} }
function testEncodingValues(aData, aExpectedString) function testEncodingValues(aData, aExpectedString)
{ {
var encoding = "ISO-8859-11"; var encoding = "ISO-8859-11";
testSingleString({encoding: aData, input: encoding, error: "EncodingError", testSingleString({encoding: aData, input: encoding, error: "TypeError",
msg: "encoder encoding values test."}); msg: "encoder encoding values test."});
} }