mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Removed unsafe from 'query_selector_iter'
This commit is contained in:
parent
1a376aa75d
commit
89e8a26539
3 changed files with 34 additions and 55 deletions
|
@ -232,13 +232,9 @@ impl<'a> Activatable for &'a HTMLButtonElement {
|
||||||
if owner.is_none() || elem.click_in_progress() {
|
if owner.is_none() || elem.click_in_progress() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// This is safe because we are stopping after finding the first element
|
|
||||||
// and only then performing actions which may modify the DOM tree
|
|
||||||
unsafe {
|
|
||||||
node.query_selector_iter("button[type=submit]".to_owned()).unwrap()
|
node.query_selector_iter("button[type=submit]".to_owned()).unwrap()
|
||||||
.filter_map(HTMLButtonElementCast::to_root)
|
.filter_map(HTMLButtonElementCast::to_root)
|
||||||
.find(|r| r.r().form_owner() == owner)
|
.find(|r| r.r().form_owner() == owner)
|
||||||
.map(|s| s.r().synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey));
|
.map(|s| s.r().synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -359,12 +359,9 @@ fn broadcast_radio_checked(broadcaster: &HTMLInputElement, group: Option<&Atom>)
|
||||||
// This function is a workaround for lifetime constraint difficulties.
|
// This function is a workaround for lifetime constraint difficulties.
|
||||||
fn do_broadcast(doc_node: &Node, broadcaster: &HTMLInputElement,
|
fn do_broadcast(doc_node: &Node, broadcaster: &HTMLInputElement,
|
||||||
owner: Option<&HTMLFormElement>, group: Option<&Atom>) {
|
owner: Option<&HTMLFormElement>, group: Option<&Atom>) {
|
||||||
// There is no DOM tree manipulation here, so this is safe
|
let iter = doc_node.query_selector_iter("input[type=radio]".to_owned())
|
||||||
let iter = unsafe {
|
.unwrap().filter_map(HTMLInputElementCast::to_root)
|
||||||
doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
|
.filter(|r| in_same_group(r.r(), owner, group) && broadcaster != r.r());
|
||||||
.filter_map(HTMLInputElementCast::to_root)
|
|
||||||
.filter(|r| in_same_group(r.r(), owner, group) && broadcaster != r.r())
|
|
||||||
};
|
|
||||||
for ref r in iter {
|
for ref r in iter {
|
||||||
if r.r().Checked() {
|
if r.r().Checked() {
|
||||||
r.r().SetChecked(false);
|
r.r().SetChecked(false);
|
||||||
|
@ -714,15 +711,12 @@ impl Activatable for HTMLInputElement {
|
||||||
let doc_node = NodeCast::from_ref(doc.r());
|
let doc_node = NodeCast::from_ref(doc.r());
|
||||||
let group = self.get_radio_group_name();;
|
let group = self.get_radio_group_name();;
|
||||||
|
|
||||||
// Safe since we only manipulate the DOM tree after finding an element
|
let checked_member = doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
|
||||||
let checked_member = unsafe {
|
|
||||||
doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
|
|
||||||
.filter_map(HTMLInputElementCast::to_root)
|
.filter_map(HTMLInputElementCast::to_root)
|
||||||
.find(|r| {
|
.find(|r| {
|
||||||
in_same_group(r.r(), owner.r(), group.as_ref()) &&
|
in_same_group(r.r(), owner.r(), group.as_ref()) &&
|
||||||
r.r().Checked()
|
r.r().Checked()
|
||||||
})
|
});
|
||||||
};
|
|
||||||
cache.checked_radio = checked_member.r().map(JS::from_ref);
|
cache.checked_radio = checked_member.r().map(JS::from_ref);
|
||||||
cache.checked_changed = self.checked_changed.get();
|
cache.checked_changed = self.checked_changed.get();
|
||||||
self.SetChecked(true);
|
self.SetChecked(true);
|
||||||
|
@ -849,14 +843,10 @@ impl Activatable for HTMLInputElement {
|
||||||
if elem.click_in_progress() {
|
if elem.click_in_progress() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// This is safe because we are stopping after finding the first element
|
|
||||||
// and only then performing actions which may modify the DOM tree
|
|
||||||
let submit_button;
|
let submit_button;
|
||||||
unsafe {
|
|
||||||
submit_button = node.query_selector_iter("input[type=submit]".to_owned()).unwrap()
|
submit_button = node.query_selector_iter("input[type=submit]".to_owned()).unwrap()
|
||||||
.filter_map(HTMLInputElementCast::to_root)
|
.filter_map(HTMLInputElementCast::to_root)
|
||||||
.find(|r| r.r().form_owner() == owner);
|
.find(|r| r.r().form_owner() == owner);
|
||||||
}
|
|
||||||
match submit_button {
|
match submit_button {
|
||||||
Some(ref button) => {
|
Some(ref button) => {
|
||||||
if button.r().is_instance_activatable() {
|
if button.r().is_instance_activatable() {
|
||||||
|
@ -864,9 +854,6 @@ impl Activatable for HTMLInputElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
unsafe {
|
|
||||||
// Safe because we don't perform any DOM modification
|
|
||||||
// until we're done with the iterator.
|
|
||||||
let inputs = node.query_selector_iter("input".to_owned()).unwrap()
|
let inputs = node.query_selector_iter("input".to_owned()).unwrap()
|
||||||
.filter_map(HTMLInputElementCast::to_root)
|
.filter_map(HTMLInputElementCast::to_root)
|
||||||
.filter(|input| {
|
.filter(|input| {
|
||||||
|
@ -884,8 +871,6 @@ impl Activatable for HTMLInputElement {
|
||||||
// lazily test for > 1 submission-blocking inputs
|
// lazily test for > 1 submission-blocking inputs
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
form.r().submit(SubmittedFrom::NotFromFormSubmitMethod,
|
form.r().submit(SubmittedFrom::NotFromFormSubmitMethod,
|
||||||
FormSubmitter::FormElement(form.r()));
|
FormSubmitter::FormElement(form.r()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,8 +345,7 @@ pub struct QuerySelectorIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> QuerySelectorIterator {
|
impl<'a> QuerySelectorIterator {
|
||||||
#[allow(unsafe_code)]
|
fn new(iter: TreeIterator, selectors: Vec<Selector>)
|
||||||
unsafe fn new(iter: TreeIterator, selectors: Vec<Selector>)
|
|
||||||
-> QuerySelectorIterator {
|
-> QuerySelectorIterator {
|
||||||
QuerySelectorIterator {
|
QuerySelectorIterator {
|
||||||
selectors: selectors,
|
selectors: selectors,
|
||||||
|
@ -737,8 +736,7 @@ impl Node {
|
||||||
/// Get an iterator over all nodes which match a set of selectors
|
/// Get an iterator over all nodes which match a set of selectors
|
||||||
/// Be careful not to do anything which may manipulate the DOM tree
|
/// Be careful not to do anything which may manipulate the DOM tree
|
||||||
/// whilst iterating, otherwise the iterator may be invalidated.
|
/// whilst iterating, otherwise the iterator may be invalidated.
|
||||||
#[allow(unsafe_code)]
|
pub fn query_selector_iter(&self, selectors: DOMString)
|
||||||
pub unsafe fn query_selector_iter(&self, selectors: DOMString)
|
|
||||||
-> Fallible<QuerySelectorIterator> {
|
-> Fallible<QuerySelectorIterator> {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
match parse_author_origin_selector_list_from_str(&selectors) {
|
match parse_author_origin_selector_list_from_str(&selectors) {
|
||||||
|
@ -755,7 +753,7 @@ impl Node {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn query_selector_all(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
|
pub fn query_selector_all(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let iter = try!(unsafe { self.query_selector_iter(selectors) });
|
let iter = try!(self.query_selector_iter(selectors));
|
||||||
Ok(NodeList::new_simple_list(window.r(), iter))
|
Ok(NodeList::new_simple_list(window.r(), iter))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue