aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorPrabhjyot Singh Sodhi <prabhjyotsingh95@gmail.com>2015-09-02 14:44:39 +0530
committerPrabhjyot Singh Sodhi <prabhjyotsingh95@gmail.com>2015-09-02 22:20:33 +0530
commit105ea0d6906f72797cff930d2712e9230f051cc2 (patch)
tree6bad3aca168a39c89ef283d354fe6916d837ec21 /components/script
parenteaf90c0b1c14717fb580bb0bdb8f6c4db363ace6 (diff)
downloadservo-105ea0d6906f72797cff930d2712e9230f051cc2.tar.gz
servo-105ea0d6906f72797cff930d2712e9230f051cc2.zip
renaming tokens(), atom() and uint() and rewriting to return or panic
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/attr.rs18
-rw-r--r--components/script/dom/document.rs10
-rw-r--r--components/script/dom/domtokenlist.rs9
-rw-r--r--components/script/dom/element.rs19
-rw-r--r--components/script/dom/htmliframeelement.rs2
-rw-r--r--components/script/dom/htmlinputelement.rs2
-rw-r--r--components/script/dom/htmltablecellelement.rs2
-rw-r--r--components/script/dom/htmltextareaelement.rs4
8 files changed, 31 insertions, 35 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index 134d7156475..4c5f2c09d80 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -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");
}
}
}
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 7441a14bcae..fb85cdb980b 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -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,
}
}
diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs
index c8940a33f7b..5c8af75f298 100644
--- a/components/script/dom/domtokenlist.rs
+++ b/components/script/dom/domtokenlist.rs
@@ -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)
})
}
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index f128e25626e..83574e7b6fa 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -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);
}
}
}
diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs
index 121612ecdf8..d4cd6cae3ac 100644
--- a/components/script/dom/htmliframeelement.rs
+++ b/components/script/dom/htmliframeelement.rs
@@ -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,
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 1f29188714e..33a4a45d295 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -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));
}
diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs
index 0d3af25aebf..c67d02c8693 100644
--- a/components/script/dom/htmltablecellelement.rs
+++ b/components/script/dom/htmltablecellelement.rs
@@ -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) => {
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index 793ed11e476..f1682d2270b 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -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));
},