Fix some clippy warnings in components/script/webdriver_handlers.rs (#31784)

* Fixed some clippy warnings in components/script/webdriver_handlers.rs

* Updated fixes for clippy warnings in components/script/webdriver_handlers.rs

* Updated the formatting of components/script/webdriver_handlers.rs

* Updated components/script/webdriver_handler.rs to fix some clippy warnings.
This commit is contained in:
Tumuhairwe 2024-03-22 14:08:07 +03:00 committed by GitHub
parent 77f5175efc
commit 3e9b808938
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -85,11 +85,11 @@ fn find_node_by_unique_id(
} }
} }
fn matching_links<'a>( fn matching_links(
links: &'a NodeList, links: &NodeList,
link_text: String, link_text: String,
partial: bool, partial: bool,
) -> impl Iterator<Item = String> + 'a { ) -> impl Iterator<Item = String> + '_ {
links links
.iter() .iter()
.filter(move |node| { .filter(move |node| {
@ -251,7 +251,7 @@ pub unsafe fn jsval_to_webdriver(
cx, cx,
object.handle(), object.handle(),
name.as_ptr(), name.as_ptr(),
&mut HandleValueArray::new(), &HandleValueArray::new(),
value.handle_mut(), value.handle_mut(),
) { ) {
jsval_to_webdriver(cx, global_scope, value.handle()) jsval_to_webdriver(cx, global_scope, value.handle())
@ -262,11 +262,10 @@ pub unsafe fn jsval_to_webdriver(
} else { } else {
let mut result = HashMap::new(); let mut result = HashMap::new();
let common_properties = vec!["x", "y", "width", "height", "key"]; let common_properties = ["x", "y", "width", "height", "key"];
for property in common_properties.iter() { for property in common_properties.iter() {
rooted!(in(cx) let mut item = UndefinedValue()); rooted!(in(cx) let mut item = UndefinedValue());
if let Ok(_) = get_property_jsval(cx, object.handle(), property, item.handle_mut()) if get_property_jsval(cx, object.handle(), property, item.handle_mut()).is_ok() {
{
if !item.is_undefined() { if !item.is_undefined() {
if let Ok(value) = jsval_to_webdriver(cx, global_scope, item.handle()) { if let Ok(value) = jsval_to_webdriver(cx, global_scope, item.handle()) {
result.insert(property.to_string(), value); result.insert(property.to_string(), value);
@ -381,33 +380,30 @@ fn get_element_in_view_center_point(element: &Element) -> Option<Point2D<i64>> {
.GetBody() .GetBody()
.map(DomRoot::upcast::<Element>) .map(DomRoot::upcast::<Element>)
.and_then(|body| { .and_then(|body| {
element // Step 1: Let rectangle be the first element of the DOMRect sequence
.GetClientRects() // returned by calling getClientRects() on element.
.iter() element.GetClientRects().first().map(|rectangle| {
// Step 1 let x = rectangle.X().round() as i64;
.next() let y = rectangle.Y().round() as i64;
.map(|rectangle| { let width = rectangle.Width().round() as i64;
let x = rectangle.X().round() as i64; let height = rectangle.Height().round() as i64;
let y = rectangle.Y().round() as i64;
let width = rectangle.Width().round() as i64;
let height = rectangle.Height().round() as i64;
let client_width = body.ClientWidth() as i64; let client_width = body.ClientWidth() as i64;
let client_height = body.ClientHeight() as i64; let client_height = body.ClientHeight() as i64;
// Steps 2 - 5 // Steps 2 - 5
let left = cmp::max(0, cmp::min(x, x + width)); let left = cmp::max(0, cmp::min(x, x + width));
let right = cmp::min(client_width, cmp::max(x, x + width)); let right = cmp::min(client_width, cmp::max(x, x + width));
let top = cmp::max(0, cmp::min(y, y + height)); let top = cmp::max(0, cmp::min(y, y + height));
let bottom = cmp::min(client_height, cmp::max(y, y + height)); let bottom = cmp::min(client_height, cmp::max(y, y + height));
// Steps 6 - 7 // Steps 6 - 7
let x = (left + right) / 2; let x = (left + right) / 2;
let y = (top + bottom) / 2; let y = (top + bottom) / 2;
// Step 8 // Step 8
Point2D::new(x, y) Point2D::new(x, y)
}) })
}) })
} }
@ -478,11 +474,11 @@ pub fn handle_find_element_tag_name(
documents documents
.find_document(pipeline) .find_document(pipeline)
.ok_or(ErrorStatus::UnknownError) .ok_or(ErrorStatus::UnknownError)
.and_then(|document| { .map(|document| {
Ok(document document
.GetElementsByTagName(DOMString::from(selector)) .GetElementsByTagName(DOMString::from(selector))
.elements_iter() .elements_iter()
.next()) .next()
}) })
.map(|node| node.map(|x| x.upcast::<Node>().unique_id())), .map(|node| node.map(|x| x.upcast::<Node>().unique_id())),
) )
@ -545,7 +541,7 @@ pub fn handle_find_elements_tag_name(
documents documents
.find_document(pipeline) .find_document(pipeline)
.ok_or(ErrorStatus::UnknownError) .ok_or(ErrorStatus::UnknownError)
.and_then(|document| Ok(document.GetElementsByTagName(DOMString::from(selector)))) .map(|document| document.GetElementsByTagName(DOMString::from(selector)))
.map(|nodes| { .map(|nodes| {
nodes nodes
.elements_iter() .elements_iter()
@ -955,7 +951,7 @@ pub fn handle_get_text(
reply reply
.send( .send(
find_node_by_unique_id(documents, pipeline, node_id) find_node_by_unique_id(documents, pipeline, node_id)
.and_then(|node| Ok(node.GetTextContent().map_or("".to_owned(), String::from))), .map(|node| node.GetTextContent().map_or("".to_owned(), String::from)),
) )
.unwrap(); .unwrap();
} }
@ -969,7 +965,7 @@ pub fn handle_get_name(
reply reply
.send( .send(
find_node_by_unique_id(documents, pipeline, node_id) find_node_by_unique_id(documents, pipeline, node_id)
.and_then(|node| Ok(String::from(node.downcast::<Element>().unwrap().TagName()))), .map(|node| String::from(node.downcast::<Element>().unwrap().TagName())),
) )
.unwrap(); .unwrap();
} }
@ -983,12 +979,11 @@ pub fn handle_get_attribute(
) { ) {
reply reply
.send( .send(
find_node_by_unique_id(documents, pipeline, node_id).and_then(|node| { find_node_by_unique_id(documents, pipeline, node_id).map(|node| {
Ok(node node.downcast::<Element>()
.downcast::<Element>()
.unwrap() .unwrap()
.GetAttribute(DOMString::from(name)) .GetAttribute(DOMString::from(name))
.map(String::from)) .map(String::from)
}), }),
) )
.unwrap(); .unwrap();
@ -1004,7 +999,7 @@ pub fn handle_get_property(
) { ) {
reply reply
.send( .send(
find_node_by_unique_id(documents, pipeline, node_id).and_then(|node| { find_node_by_unique_id(documents, pipeline, node_id).map(|node| {
let document = documents.find_document(pipeline).unwrap(); let document = documents.find_document(pipeline).unwrap();
let _ac = enter_realm(&*document); let _ac = enter_realm(&*document);
let cx = document.window().get_cx(); let cx = document.window().get_cx();
@ -1021,12 +1016,12 @@ pub fn handle_get_property(
Ok(_) => match unsafe { Ok(_) => match unsafe {
jsval_to_webdriver(*cx, &node.reflector().global(), property.handle()) jsval_to_webdriver(*cx, &node.reflector().global(), property.handle())
} { } {
Ok(property) => Ok(property), Ok(property) => property,
Err(_) => Ok(WebDriverJSValue::Undefined), Err(_) => WebDriverJSValue::Undefined,
}, },
Err(error) => { Err(error) => {
throw_dom_exception(cx, &node.reflector().global(), error); throw_dom_exception(cx, &node.reflector().global(), error);
Ok(WebDriverJSValue::Undefined) WebDriverJSValue::Undefined
}, },
} }
}), }),
@ -1043,14 +1038,14 @@ pub fn handle_get_css(
) { ) {
reply reply
.send( .send(
find_node_by_unique_id(documents, pipeline, node_id).and_then(|node| { find_node_by_unique_id(documents, pipeline, node_id).map(|node| {
let window = window_from_node(&*node); let window = window_from_node(&*node);
let element = node.downcast::<Element>().unwrap(); let element = node.downcast::<Element>().unwrap();
Ok(String::from( String::from(
window window
.GetComputedStyle(element, None) .GetComputedStyle(element, None)
.GetPropertyValue(DOMString::from(name)), .GetPropertyValue(DOMString::from(name)),
)) )
}), }),
) )
.unwrap(); .unwrap();