mirror of
https://github.com/servo/servo.git
synced 2025-06-23 16:44:33 +01:00
Make DOMTokenList.contains not throw anymore
This commit is contained in:
parent
51d41c5161
commit
66b0568bb3
5 changed files with 9 additions and 70 deletions
|
@ -70,15 +70,14 @@ impl DOMTokenListMethods for DOMTokenList {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-contains
|
// https://dom.spec.whatwg.org/#dom-domtokenlist-contains
|
||||||
fn Contains(&self, token: DOMString) -> Fallible<bool> {
|
fn Contains(&self, token: DOMString) -> bool {
|
||||||
self.check_token_exceptions(&token).map(|token| {
|
let token = Atom::from(token);
|
||||||
self.attribute().map_or(false, |attr| {
|
self.attribute().map_or(false, |attr| {
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
attr.value()
|
attr.value()
|
||||||
.as_tokens()
|
.as_tokens()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|atom: &Atom| *atom == token)
|
.any(|atom: &Atom| *atom == token)
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ interface DOMTokenList {
|
||||||
[Pure]
|
[Pure]
|
||||||
getter DOMString? item(unsigned long index);
|
getter DOMString? item(unsigned long index);
|
||||||
|
|
||||||
[Pure, Throws]
|
[Pure]
|
||||||
boolean contains(DOMString token);
|
boolean contains(DOMString token);
|
||||||
[Throws]
|
[Throws]
|
||||||
void add(DOMString... tokens);
|
void add(DOMString... tokens);
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
[Element-classlist.html]
|
|
||||||
type: testharness
|
|
||||||
[.contains(empty_string) must return false]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[.contains(string_with_spaces) must return false]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -6286,12 +6286,6 @@
|
||||||
"url": "/_mozilla/mozilla/document_url.html"
|
"url": "/_mozilla/mozilla/document_url.html"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"mozilla/domtokenlist.html": [
|
|
||||||
{
|
|
||||||
"path": "mozilla/domtokenlist.html",
|
|
||||||
"url": "/_mozilla/mozilla/domtokenlist.html"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"mozilla/element_attribute.html": [
|
"mozilla/element_attribute.html": [
|
||||||
{
|
{
|
||||||
"path": "mozilla/element_attribute.html",
|
"path": "mozilla/element_attribute.html",
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<script src="/resources/testharness.js"></script>
|
|
||||||
<script src="/resources/testharnessreport.js"></script>
|
|
||||||
<script>
|
|
||||||
test(function() {
|
|
||||||
var div = document.createElement("div");
|
|
||||||
var classList = div.classList;
|
|
||||||
|
|
||||||
assert_equals(classList.length, 0);
|
|
||||||
assert_equals(classList.item(0), null);
|
|
||||||
assert_throws(null, function () {
|
|
||||||
classList.contains("");
|
|
||||||
});
|
|
||||||
assert_throws(null, function () {
|
|
||||||
classList.contains(" ");
|
|
||||||
});
|
|
||||||
|
|
||||||
var list = ["foo", " foo", "foo ", " foo ", " foo "];
|
|
||||||
for(var i = 0; i < list.length; i++) {
|
|
||||||
div.className = list[i];
|
|
||||||
assert_equals(div.className, list[i]);
|
|
||||||
assert_equals(classList.length, 1);
|
|
||||||
assert_equals(classList.item(0), "foo");
|
|
||||||
assert_equals(classList.item(1), null);
|
|
||||||
assert_equals(classList.contains("foo"), true);
|
|
||||||
assert_equals(classList.contains("bar"), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
list = ["foo bar", " foo bar", " foo bar ", " foo bar "];
|
|
||||||
for(var i = 0; i < list.length; i++) {
|
|
||||||
div.className = list[i];
|
|
||||||
assert_equals(div.className, list[i]);
|
|
||||||
assert_equals(classList.length, 2);
|
|
||||||
assert_equals(classList.item(0), "foo");
|
|
||||||
assert_equals(classList.item(1), "bar");
|
|
||||||
assert_equals(classList.item(2), null);
|
|
||||||
assert_equals(classList.contains("foo"), true);
|
|
||||||
assert_equals(classList.contains("bar"), true);
|
|
||||||
assert_equals(classList.contains("baz"), false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
</html>
|
|
Loading…
Add table
Add a link
Reference in a new issue