Bug 1263116 - Stop throwing for DOMTokenList's.contains() when using empty string or ASCII whitespace, r=baku

This commit is contained in:
Ben Tian 2016-05-05 18:07:22 +08:00
parent a2b3ad3b63
commit 88d03021fb
6 changed files with 11 additions and 27 deletions

View File

@ -119,13 +119,8 @@ nsDOMTokenList::CheckTokens(const nsTArray<nsString>& aTokens)
}
bool
nsDOMTokenList::Contains(const nsAString& aToken, ErrorResult& aError)
nsDOMTokenList::Contains(const nsAString& aToken)
{
aError = CheckToken(aToken);
if (aError.Failed()) {
return false;
}
const nsAttrValue* attr = GetParsedAttr();
return attr && attr->Contains(aToken);
}

View File

@ -58,7 +58,7 @@ public:
}
}
void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult);
bool Contains(const nsAString& aToken, mozilla::ErrorResult& aError);
bool Contains(const nsAString& aToken);
void Add(const nsAString& aToken, mozilla::ErrorResult& aError);
void Add(const nsTArray<nsString>& aTokens,
mozilla::ErrorResult& aError);

View File

@ -100,7 +100,7 @@ function assignToClassListStrict(e) {
e.classList = "foo";
ok(true, "assigning to classList didn't throw");
e.removeAttribute("class");
} catch (e) {
} catch (e) {
ok(false, "assigning to classList threw");
}
}
@ -216,24 +216,21 @@ function testClassList(e) {
is(e.classList.contains("a"), false, "wrong classList.contains() result");
try {
e.classList.contains("");
ok(false, "classList.contains() didn't throw");
ok(true, "classList.contains(empty_string) didn't throw");
} catch (e) {
is(e.name, "SyntaxError", "wrong exception thrown");
is(e.code, DOMException.SYNTAX_ERR, "wrong exception thrown");
ok(false, "classList.contains(empty_string) threw");
}
try {
e.classList.contains(" ");
ok(false, "classList.contains() didn't throw");
ok(true, "classList.contains(string_with_spaces) didn't throw");
} catch (e) {
is(e.name, "InvalidCharacterError", "wrong exception thrown");
is(e.code, DOMException.INVALID_CHARACTER_ERR, "wrong exception thrown");
ok(false, "classList.contains(string_with_spaces) threw");
}
try {
e.classList.contains("aa ");
ok(false, "classList.contains() didn't throw");
ok(true, "classList.contains(string_with_spaces) didn't throw");
} catch (e) {
is(e.name, "InvalidCharacterError", "wrong exception thrown");
is(e.code, DOMException.INVALID_CHARACTER_ERR, "wrong exception thrown");
ok(false, "classList.contains(string_with_spaces) threw");
}
e.setAttribute("class", "");
@ -382,7 +379,7 @@ function testClassList(e) {
// tests for the force argument handling
function checkForceToggle(before, argument, force, expectedRes, after, expectedException) {
checkModification(e, "toggle", [argument, force], expectedRes, before, after, expectedException);
}

View File

@ -13,7 +13,6 @@
interface DOMTokenList {
readonly attribute unsigned long length;
getter DOMString? item(unsigned long index);
[Throws]
boolean contains(DOMString token);
[Throws]
void add(DOMString... tokens);

View File

@ -973,9 +973,8 @@ nsDisplayListBuilder::MarkFramesForDisplayList(nsIFrame* aDirtyFrame,
if (!IsBuildingCaret()) {
nsIContent* content = e->GetContent();
if (content && content->IsInNativeAnonymousSubtree() && content->IsElement()) {
ErrorResult rv;
auto classList = content->AsElement()->ClassList();
if (classList->Contains(NS_LITERAL_STRING("moz-accessiblecaret"), rv)) {
if (classList->Contains(NS_LITERAL_STRING("moz-accessiblecaret"))) {
continue;
}
}

View File

@ -65,9 +65,6 @@ test(function () {
assert_equals( elem.classList + '', ' ', 'implicit' );
assert_equals( elem.classList.toString(), ' ', 'explicit' );
}, 'classList should contain initial markup whitespace');
test(function () {
assert_throws( 'SYNTAX_ERR', function () { elem.classList.contains(''); } );
}, '.contains(empty_string) must throw a SYNTAX_ERR');
test(function () {
assert_throws( 'SYNTAX_ERR', function () { elem.classList.add(''); } );
}, '.add(empty_string) must throw a SYNTAX_ERR');
@ -84,9 +81,6 @@ test(function () {
assert_throws( 'SYNTAX_ERR', function () { elem.classList.replace('foo bar', ''); } );
assert_throws( 'SYNTAX_ERR', function () { elem.classList.replace('', ''); } );
}, '.replace with empty_string must throw a SYNTAX_ERR');
test(function () {
assert_throws( 'INVALID_CHARACTER_ERR', function () { elem.classList.contains('a b'); } );
}, '.contains(string_with_spaces) must throw an INVALID_CHARACTER_ERR');
test(function () {
assert_throws( 'INVALID_CHARACTER_ERR', function () { elem.classList.add('a b'); } );
}, '.add(string_with_spaces) must throw an INVALID_CHARACTER_ERR');