Cleanup NodeIterator, Range, ServoHTMLParser, TextEncoder, URLHelper, URL, VirtualMethods

This commit is contained in:
Manish Goregaokar 2015-08-15 05:32:51 +05:30
parent a53b86f107
commit 19241c95f7
13 changed files with 24 additions and 53 deletions

View file

@ -70,4 +70,4 @@ fn register_clippy(reg: &mut Registry) {
#[cfg(not(feature = "clippy"))] #[cfg(not(feature = "clippy"))]
fn register_clippy(reg: &mut Registry) { fn register_clippy(reg: &mut Registry) {
reg.register_lint_pass(box lints::str_to_string::StrToStringPass as LintPassObject); reg.register_lint_pass(box lints::str_to_string::StrToStringPass as LintPassObject);
} }

View file

@ -275,7 +275,7 @@ impl LayoutDataRef {
/// prevent CSS selector matching from mutably accessing nodes it's not supposed to and racing /// prevent CSS selector matching from mutably accessing nodes it's not supposed to and racing
/// on it. This has already resulted in one bug! /// on it. This has already resulted in one bug!
#[inline] #[inline]
pub fn borrow_mut(self) -> RefMut<Option<LayoutData>> { pub fn borrow_mut(&self) -> RefMut<Option<LayoutData>> {
debug_assert!(task_state::get().is_layout()); debug_assert!(task_state::get().is_layout());
self.data_cell.borrow_mut() self.data_cell.borrow_mut()
} }
@ -2088,12 +2088,7 @@ impl<'a> NodeMethods for &'a Node {
// https://dom.spec.whatwg.org/#dom-node-nodevalue // https://dom.spec.whatwg.org/#dom-node-nodevalue
fn GetNodeValue(self) -> Option<DOMString> { fn GetNodeValue(self) -> Option<DOMString> {
if let NodeTypeId::CharacterData(..) = self.type_id { CharacterDataCast::to_ref(self).map(|c| c.Data())
let chardata: &CharacterData = CharacterDataCast::to_ref(self).unwrap();
Some(chardata.Data())
} else {
None
}
} }
// https://dom.spec.whatwg.org/#dom-node-nodevalue // https://dom.spec.whatwg.org/#dom-node-nodevalue

View file

@ -138,7 +138,7 @@ impl<'a> NodeIteratorMethods for &'a NodeIterator {
} }
} }
return Ok(None); Ok(None)
} }
// https://dom.spec.whatwg.org/#dom-nodeiterator-previousnode // https://dom.spec.whatwg.org/#dom-nodeiterator-previousnode
@ -183,7 +183,7 @@ impl<'a> NodeIteratorMethods for &'a NodeIterator {
} }
} }
return Ok(None); Ok(None)
} }
// https://dom.spec.whatwg.org/#dom-nodeiterator-detach // https://dom.spec.whatwg.org/#dom-nodeiterator-detach

View file

@ -122,7 +122,7 @@ impl Range {
return Err(HierarchyRequest); return Err(HierarchyRequest);
} }
return Ok((first_contained_child, last_contained_child, contained_children)); Ok((first_contained_child, last_contained_child, contained_children))
} }
} }
@ -338,17 +338,11 @@ impl<'a> RangeMethods for &'a Range {
let end = &inner.end; let end = &inner.end;
let end_node = end.node(); let end_node = end.node();
let end_offset = end.offset; let end_offset = end.offset;
match (bp_position(parent.r(), offset + 1, start_node.r(), start_offset).unwrap(), // Step 5.
bp_position(parent.r(), offset, end_node.r(), end_offset).unwrap()) { Ordering::Greater == bp_position(parent.r(), offset + 1,
(Ordering::Greater, Ordering::Less) => { start_node.r(), start_offset).unwrap() &&
// Step 5. Ordering::Less == bp_position(parent.r(), offset,
true end_node.r(), end_offset).unwrap()
},
_ => {
// Step 6.
false
}
}
} }
// https://dom.spec.whatwg.org/#dom-range-clonecontents // https://dom.spec.whatwg.org/#dom-range-clonecontents

View file

@ -268,7 +268,7 @@ impl ServoHTMLParser {
} }
#[inline] #[inline]
pub fn tokenizer<'a>(&'a self) -> &'a DOMRefCell<Tokenizer> { pub fn tokenizer(&self) -> &DOMRefCell<Tokenizer> {
&self.tokenizer &self.tokenizer
} }
} }

View file

@ -65,7 +65,7 @@ impl TextEncoder {
} }
_ => { _ => {
debug!("Encoding Not UTF"); debug!("Encoding Not UTF");
return Err(Range("The encoding must be utf-8, utf-16le, or utf-16be.".to_owned())) Err(Range("The encoding must be utf-8, utf-16le, or utf-16be.".to_owned()))
} }
} }
} }
@ -87,7 +87,7 @@ impl<'a> TextEncoderMethods for &'a TextEncoder {
let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object, ptr::null()); let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object, ptr::null());
ptr::copy_nonoverlapping(encoded.as_ptr(), js_object_data, length as usize); ptr::copy_nonoverlapping(encoded.as_ptr(), js_object_data, length as usize);
return js_object; js_object
} }
} }
} }

View file

@ -104,7 +104,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
node = n; node = n;
// "2. If node is not null and filtering node returns FILTER_ACCEPT, // "2. If node is not null and filtering node returns FILTER_ACCEPT,
// then set the currentNode attribute to node, return node." // then set the currentNode attribute to node, return node."
if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) { if NodeFilterConstants::FILTER_ACCEPT == try!(self.accept_node(node.r())) {
self.current_node.set(JS::from_rooted(&node)); self.current_node.set(JS::from_rooted(&node));
return Ok(Some(node)) return Ok(Some(node))
} }
@ -192,7 +192,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
} }
// "5. Filter node and if the return value is FILTER_ACCEPT, then // "5. Filter node and if the return value is FILTER_ACCEPT, then
// set the currentNode attribute to node and return node." // set the currentNode attribute to node and return node."
if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) { if NodeFilterConstants::FILTER_ACCEPT == try!(self.accept_node(node.r())) {
self.current_node.set(JS::from_rooted(&node)); self.current_node.set(JS::from_rooted(&node));
return Ok(Some(node)) return Ok(Some(node))
} }
@ -211,7 +211,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
loop { loop {
// "1. While result is not FILTER_REJECT and node has a child, run these subsubsteps:" // "1. While result is not FILTER_REJECT and node has a child, run these subsubsteps:"
loop { loop {
if let NodeFilterConstants::FILTER_REJECT = result { if NodeFilterConstants::FILTER_REJECT == result {
break; break;
} }
match node.r().GetFirstChild() { match node.r().GetFirstChild() {
@ -223,7 +223,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
result = try!(self.accept_node(node.r())); result = try!(self.accept_node(node.r()));
// "3. If result is FILTER_ACCEPT, then // "3. If result is FILTER_ACCEPT, then
// set the currentNode attribute to node and return node." // set the currentNode attribute to node and return node."
if let NodeFilterConstants::FILTER_ACCEPT = result { if NodeFilterConstants::FILTER_ACCEPT == result {
self.current_node.set(JS::from_rooted(&node)); self.current_node.set(JS::from_rooted(&node));
return Ok(Some(node)) return Ok(Some(node))
} }
@ -241,7 +241,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
result = try!(self.accept_node(node.r())); result = try!(self.accept_node(node.r()));
// "4. If result is FILTER_ACCEPT, then // "4. If result is FILTER_ACCEPT, then
// set the currentNode attribute to node and return node." // set the currentNode attribute to node and return node."
if let NodeFilterConstants::FILTER_ACCEPT = result { if NodeFilterConstants::FILTER_ACCEPT == result {
self.current_node.set(JS::from_rooted(&node)); self.current_node.set(JS::from_rooted(&node));
return Ok(Some(node)) return Ok(Some(node))
} }
@ -378,7 +378,7 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker {
let result = try!(self.accept_node(node.r())); let result = try!(self.accept_node(node.r()));
// "3. If result is FILTER_ACCEPT, then set the currentNode // "3. If result is FILTER_ACCEPT, then set the currentNode
// attribute to node and return node." // attribute to node and return node."
if let NodeFilterConstants::FILTER_ACCEPT = result { if NodeFilterConstants::FILTER_ACCEPT == result {
self.current_node.set(JS::from_rooted(&node)); self.current_node.set(JS::from_rooted(&node));
return Ok(Some(node)) return Ok(Some(node))
} }
@ -403,7 +403,7 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker {
// "5. Filter node and if the return value is FILTER_ACCEPT, then return null." // "5. Filter node and if the return value is FILTER_ACCEPT, then return null."
Some(n) => { Some(n) => {
node = n; node = n;
if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) { if NodeFilterConstants::FILTER_ACCEPT == try!(self.accept_node(node.r())) {
return Ok(None) return Ok(None)
} }
} }

View file

@ -142,7 +142,7 @@ impl<'a> URLMethods for &'a URL {
} }
} }
fn parser_with_base<'a>(base: Option<&'a Url>) -> UrlParser<'a> { fn parser_with_base(base: Option<&Url>) -> UrlParser {
let mut parser = UrlParser::new(); let mut parser = UrlParser::new();
if let Some(base) = base { if let Some(base) = base {
parser.base_url(base); parser.base_url(base);

View file

@ -84,7 +84,7 @@ impl UrlHelper {
if urlA.port() != urlB.port() { if urlA.port() != urlB.port() {
return false return false
} }
return true true
} }
// https://url.spec.whatwg.org/#dom-urlutils-search // https://url.spec.whatwg.org/#dom-urlutils-search

View file

@ -48,7 +48,7 @@ use string_cache::Atom;
pub trait VirtualMethods { pub trait VirtualMethods {
/// Returns self as the superclass of the implementation for this trait, /// Returns self as the superclass of the implementation for this trait,
/// if any. /// if any.
fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods>; fn super_type(&self) -> Option<&VirtualMethods>;
/// Called when changing or adding attributes, after the attribute's value /// Called when changing or adding attributes, after the attribute's value
/// has been updated. /// has been updated.

View file

@ -166,11 +166,6 @@ dependencies = [
"winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "clippy"
version = "0.0.11"
source = "git+https://github.com/Manishearth/rust-clippy?branch=servo#4d5e15ee6e1061ed7da0a91df3510728cabc0a21"
[[package]] [[package]]
name = "clock_ticks" name = "clock_ticks"
version = "0.0.6" version = "0.0.6"
@ -1109,7 +1104,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "plugins" name = "plugins"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"clippy 0.0.11 (git+https://github.com/Manishearth/rust-clippy?branch=servo)",
"tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)", "tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)",
] ]

6
ports/cef/Cargo.lock generated
View file

@ -165,11 +165,6 @@ dependencies = [
"winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "clippy"
version = "0.0.11"
source = "git+https://github.com/Manishearth/rust-clippy?branch=servo#4d5e15ee6e1061ed7da0a91df3510728cabc0a21"
[[package]] [[package]]
name = "clock_ticks" name = "clock_ticks"
version = "0.0.6" version = "0.0.6"
@ -1087,7 +1082,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "plugins" name = "plugins"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"clippy 0.0.11 (git+https://github.com/Manishearth/rust-clippy?branch=servo)",
"tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)", "tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)",
] ]

6
ports/gonk/Cargo.lock generated
View file

@ -151,11 +151,6 @@ dependencies = [
"winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "clippy"
version = "0.0.11"
source = "git+https://github.com/Manishearth/rust-clippy?branch=servo#4d5e15ee6e1061ed7da0a91df3510728cabc0a21"
[[package]] [[package]]
name = "clock_ticks" name = "clock_ticks"
version = "0.0.6" version = "0.0.6"
@ -993,7 +988,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "plugins" name = "plugins"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"clippy 0.0.11 (git+https://github.com/Manishearth/rust-clippy?branch=servo)",
"tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)", "tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)",
] ]