mirror of
https://github.com/servo/servo.git
synced 2025-08-02 12:10:29 +01:00
renaming tokens(), atom() and uint() and rewriting to return or panic
This commit is contained in:
parent
eaf90c0b1c
commit
105ea0d690
8 changed files with 31 additions and 35 deletions
|
@ -75,28 +75,28 @@ impl AttrValue {
|
|||
AttrValue::Atom(value)
|
||||
}
|
||||
|
||||
pub fn tokens<'a>(&'a self) -> Option<&'a [Atom]> {
|
||||
pub fn as_tokens<'a>(&'a self) -> &'a [Atom] {
|
||||
match *self {
|
||||
AttrValue::TokenList(_, ref tokens) => Some(tokens),
|
||||
_ => None
|
||||
AttrValue::TokenList(_, ref tokens) => tokens,
|
||||
_ => panic!("Tokens not found"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn atom<'a>(&'a self) -> Option<&'a Atom> {
|
||||
pub fn as_atom<'a>(&'a self) -> &'a Atom {
|
||||
match *self {
|
||||
AttrValue::Atom(ref value) => Some(value),
|
||||
_ => None
|
||||
AttrValue::Atom(ref value) => value,
|
||||
_ => panic!("Atom not found"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the AttrValue as its integer representation, if any.
|
||||
/// This corresponds to attribute values returned as `AttrValue::UInt(_)`
|
||||
/// by `VirtualMethods::parse_plain_attribute()`.
|
||||
pub fn uint(&self) -> Option<u32> {
|
||||
pub fn as_uint(&self) -> u32 {
|
||||
if let AttrValue::UInt(_, value) = *self {
|
||||
Some(value)
|
||||
value
|
||||
} else {
|
||||
None
|
||||
panic!("Uint not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1762,10 +1762,10 @@ impl DocumentMethods for Document {
|
|||
match html_elem_type {
|
||||
HTMLElementTypeId::HTMLAppletElement => {
|
||||
match elem.get_attribute(&ns!(""), &atom!("name")) {
|
||||
Some(ref attr) if attr.r().value().atom() == Some(name) => true,
|
||||
Some(ref attr) if attr.r().value().as_atom() == name => true,
|
||||
_ => {
|
||||
match elem.get_attribute(&ns!(""), &atom!("id")) {
|
||||
Some(ref attr) => attr.r().value().atom() == Some(name),
|
||||
Some(ref attr) => attr.r().value().as_atom() == name,
|
||||
None => false,
|
||||
}
|
||||
},
|
||||
|
@ -1773,18 +1773,18 @@ impl DocumentMethods for Document {
|
|||
},
|
||||
HTMLElementTypeId::HTMLFormElement => {
|
||||
match elem.get_attribute(&ns!(""), &atom!("name")) {
|
||||
Some(ref attr) => attr.r().value().atom() == Some(name),
|
||||
Some(ref attr) => attr.r().value().as_atom() == name,
|
||||
None => false,
|
||||
}
|
||||
},
|
||||
HTMLElementTypeId::HTMLImageElement => {
|
||||
match elem.get_attribute(&ns!(""), &atom!("name")) {
|
||||
Some(ref attr) => {
|
||||
if attr.r().value().atom() == Some(name) {
|
||||
if attr.r().value().as_atom() == name {
|
||||
true
|
||||
} else {
|
||||
match elem.get_attribute(&ns!(""), &atom!("id")) {
|
||||
Some(ref attr) => attr.r().value().atom() == Some(name),
|
||||
Some(ref attr) => attr.r().value().as_atom() == name,
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
fn Length(&self) -> u32 {
|
||||
self.attribute().map(|attr| {
|
||||
let attr = attr.r();
|
||||
attr.value().tokens().map(|tokens| tokens.len()).unwrap_or(0)
|
||||
attr.value().as_tokens().len()
|
||||
}).unwrap_or(0) as u32
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
fn Item(&self, index: u32) -> Option<DOMString> {
|
||||
self.attribute().and_then(|attr| {
|
||||
let attr = attr.r();
|
||||
attr.value().tokens().and_then(|tokens| {
|
||||
Some(attr.value().as_tokens()).and_then(|tokens| {
|
||||
tokens.get(index as usize).map(|token| (**token).to_owned())
|
||||
})
|
||||
})
|
||||
|
@ -81,10 +81,9 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
self.attribute().map(|attr| {
|
||||
let attr = attr.r();
|
||||
attr.value()
|
||||
.tokens()
|
||||
.expect("Should have parsed this attribute")
|
||||
.as_tokens()
|
||||
.iter()
|
||||
.any(|atom| *atom == token)
|
||||
.any(|atom: &Atom| *atom == token)
|
||||
}).unwrap_or(false)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -969,9 +969,7 @@ impl Element {
|
|||
Quirks => lhs.eq_ignore_ascii_case(&rhs)
|
||||
};
|
||||
self.get_attribute(&ns!(""), &atom!("class")).map(|attr| {
|
||||
attr.r().value().tokens().map(|tokens| {
|
||||
tokens.iter().any(|atom| is_equal(name, atom))
|
||||
}).unwrap_or(false)
|
||||
attr.r().value().as_tokens().iter().any(|atom| is_equal(name, atom))
|
||||
}).unwrap_or(false)
|
||||
}
|
||||
|
||||
|
@ -1031,8 +1029,7 @@ impl Element {
|
|||
self.get_attribute(&ns!(""), local_name).map(|attr| {
|
||||
attr.r()
|
||||
.value()
|
||||
.tokens()
|
||||
.expect("Expected a TokenListAttrValue")
|
||||
.as_tokens()
|
||||
.to_vec()
|
||||
}).unwrap_or(vec!())
|
||||
}
|
||||
|
@ -1469,11 +1466,11 @@ impl VirtualMethods for Element {
|
|||
},
|
||||
&atom!(id) => {
|
||||
if node.is_in_doc() {
|
||||
let value = attr.value().atom().unwrap().clone();
|
||||
let value = attr.value().as_atom().clone();
|
||||
match mutation {
|
||||
AttributeMutation::Set(old_value) => {
|
||||
if let Some(old_value) = old_value {
|
||||
let old_value = old_value.atom().unwrap().clone();
|
||||
let old_value = old_value.as_atom().clone();
|
||||
doc.unregister_named_element(self, old_value);
|
||||
}
|
||||
if value != atom!("") {
|
||||
|
@ -1659,10 +1656,10 @@ impl<'a> ::selectors::Element for Root<Element> {
|
|||
where F: FnMut(&Atom)
|
||||
{
|
||||
if let Some(ref attr) = self.get_attribute(&ns!(""), &atom!("class")) {
|
||||
if let Some(tokens) = attr.r().value().tokens() {
|
||||
for token in tokens {
|
||||
callback(token)
|
||||
}
|
||||
let tokens = attr.r().value();
|
||||
let tokens = tokens.as_tokens();
|
||||
for token in tokens {
|
||||
callback(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -362,7 +362,7 @@ impl VirtualMethods for HTMLIFrameElement {
|
|||
&atom!(sandbox) => {
|
||||
self.sandbox.set(mutation.new_value(attr).map(|value| {
|
||||
let mut modes = SandboxAllowance::AllowNothing as u8;
|
||||
for token in value.tokens().unwrap() {
|
||||
for token in value.as_tokens() {
|
||||
modes |= match &*token.to_ascii_lowercase() {
|
||||
"allow-same-origin" => SandboxAllowance::AllowSameOrigin,
|
||||
"allow-forms" => SandboxAllowance::AllowForms,
|
||||
|
|
|
@ -479,7 +479,7 @@ impl VirtualMethods for HTMLInputElement {
|
|||
},
|
||||
&atom!(size) => {
|
||||
let size = mutation.new_value(attr).map(|value| {
|
||||
value.uint().expect("Expected an AttrValue::UInt")
|
||||
value.as_uint()
|
||||
});
|
||||
self.size.set(size.unwrap_or(DEFAULT_INPUT_SIZE));
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ impl VirtualMethods for HTMLTableCellElement {
|
|||
},
|
||||
&atom!(colspan) => {
|
||||
self.colspan.set(mutation.new_value(attr).map(|value| {
|
||||
max(DEFAULT_COLSPAN, value.uint().unwrap())
|
||||
max(DEFAULT_COLSPAN, value.as_uint())
|
||||
}));
|
||||
},
|
||||
&atom!(width) => {
|
||||
|
|
|
@ -265,13 +265,13 @@ impl VirtualMethods for HTMLTextAreaElement {
|
|||
},
|
||||
&atom!(cols) => {
|
||||
let cols = mutation.new_value(attr).map(|value| {
|
||||
value.uint().expect("Expected an AttrValue::UInt")
|
||||
value.as_uint()
|
||||
});
|
||||
self.cols.set(cols.unwrap_or(DEFAULT_COLS));
|
||||
},
|
||||
&atom!(rows) => {
|
||||
let rows = mutation.new_value(attr).map(|value| {
|
||||
value.uint().expect("Expected an AttrValue::UInt")
|
||||
value.as_uint()
|
||||
});
|
||||
self.rows.set(rows.unwrap_or(DEFAULT_ROWS));
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue