mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
fix redundant closures in component/script/dom (#31917)
* fixed unnecessary conversions * resolved conflicts * resolved conflicts * fix redundant closures in component/script/dom * resolved conflicts * fixed formatting
This commit is contained in:
parent
f183170786
commit
1bc63801e7
26 changed files with 35 additions and 44 deletions
|
@ -181,7 +181,7 @@ impl Serializable for Blob {
|
|||
|
||||
let deserialized_blob = Blob::new(owner, blob_impl);
|
||||
|
||||
let blobs = blobs.get_or_insert_with(|| HashMap::new());
|
||||
let blobs = blobs.get_or_insert_with(HashMap::new);
|
||||
blobs.insert(storage_key, deserialized_blob);
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -146,7 +146,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
|
|||
// Step 5.2.3
|
||||
if self.Device().is_represented_device_null() {
|
||||
if let Err(e) = self.Device().garbage_collect_the_connection() {
|
||||
return promise.reject_error(Error::from(e));
|
||||
return promise.reject_error(e);
|
||||
}
|
||||
return promise.reject_error(Error::Network);
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ fn stringify_handle_value(message: HandleValue) -> DOMString {
|
|||
let mut ids = IdVector::new(cx);
|
||||
if !GetPropertyKeys(
|
||||
cx,
|
||||
obj.handle().into(),
|
||||
obj.handle(),
|
||||
jsapi::JSITER_OWNONLY | jsapi::JSITER_SYMBOLS,
|
||||
ids.handle_mut(),
|
||||
) {
|
||||
|
|
|
@ -357,9 +357,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
pipeline_id,
|
||||
} = worker_load_origin;
|
||||
|
||||
let referrer = referrer_url
|
||||
.map(|url| Referrer::ReferrerUrl(url))
|
||||
.unwrap_or(referrer);
|
||||
let referrer = referrer_url.map(Referrer::ReferrerUrl).unwrap_or(referrer);
|
||||
|
||||
let request = RequestBuilder::new(worker_url.clone(), referrer)
|
||||
.destination(Destination::Worker)
|
||||
|
|
|
@ -710,10 +710,12 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
|||
use cssparser::FromParsedColor;
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::BackgroundColor(
|
||||
specified::Color::from_rgba(color.red, color.green, color.blue, color.alpha)
|
||||
.into(),
|
||||
),
|
||||
PropertyDeclaration::BackgroundColor(specified::Color::from_rgba(
|
||||
color.red,
|
||||
color.green,
|
||||
color.blue,
|
||||
color.alpha,
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -749,8 +751,7 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
|||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::Color(longhands::color::SpecifiedValue(
|
||||
specified::Color::from_rgba(color.red, color.green, color.blue, color.alpha)
|
||||
.into(),
|
||||
specified::Color::from_rgba(color.red, color.green, color.blue, color.alpha),
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -962,7 +962,7 @@ impl GlobalScope {
|
|||
self.list_auto_close_worker
|
||||
.borrow_mut()
|
||||
.drain(0..)
|
||||
.for_each(|worker| drop(worker));
|
||||
.for_each(drop);
|
||||
}
|
||||
|
||||
/// Update our state to un-managed,
|
||||
|
|
|
@ -866,7 +866,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
mipmap_filter: convert_filter_mode(descriptor.mipmapFilter),
|
||||
lod_min_clamp: *descriptor.lodMinClamp,
|
||||
lod_max_clamp: *descriptor.lodMaxClamp,
|
||||
compare: descriptor.compare.map(|c| convert_compare_function(c)),
|
||||
compare: descriptor.compare.map(convert_compare_function),
|
||||
anisotropy_clamp: 1,
|
||||
border_color: None,
|
||||
};
|
||||
|
|
|
@ -165,7 +165,7 @@ impl HeadersMethods for Headers {
|
|||
let valid_name = validate_name(name)?;
|
||||
Ok(
|
||||
get_value_from_header_list(&valid_name, &self.header_list.borrow())
|
||||
.map(|v| ByteString::new(v)),
|
||||
.map(ByteString::new),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -737,7 +737,7 @@ impl HTMLFormElement {
|
|||
atom!("submit"),
|
||||
true,
|
||||
true,
|
||||
submitter_button.map(|s| DomRoot::from_ref(s)),
|
||||
submitter_button.map(DomRoot::from_ref),
|
||||
);
|
||||
let event = event.upcast::<Event>();
|
||||
event.fire(self.upcast::<EventTarget>());
|
||||
|
|
|
@ -1642,7 +1642,7 @@ fn radio_group_iter<'a>(
|
|||
|
||||
// If group is None, in_same_group always fails, but we need to always return elem.
|
||||
root.traverse_preorder(ShadowIncluding::No)
|
||||
.filter_map(|r| DomRoot::downcast::<HTMLInputElement>(r))
|
||||
.filter_map(DomRoot::downcast::<HTMLInputElement>)
|
||||
.filter(move |r| &**r == elem || in_same_group(r, owner.as_deref(), group, None))
|
||||
}
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
|
|||
fn NamedItem(&self, name: DOMString) -> Option<DomRoot<HTMLOptionElement>> {
|
||||
self.Options()
|
||||
.NamedGetter(name)
|
||||
.map_or(None, |e| DomRoot::downcast::<HTMLOptionElement>(e))
|
||||
.map_or(None, DomRoot::downcast::<HTMLOptionElement>)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-select-remove
|
||||
|
|
|
@ -425,7 +425,7 @@ impl PaintWorkletGlobalScope {
|
|||
|
||||
receiver
|
||||
.recv_timeout(Duration::from_millis(timeout))
|
||||
.map_err(|e| PaintWorkletError::from(e))
|
||||
.map_err(PaintWorkletError::from)
|
||||
}
|
||||
}
|
||||
Box::new(WorkletPainter {
|
||||
|
|
|
@ -69,12 +69,12 @@ impl PerformanceEntry {
|
|||
impl PerformanceEntryMethods for PerformanceEntry {
|
||||
// https://w3c.github.io/performance-timeline/#dom-performanceentry-name
|
||||
fn Name(&self) -> DOMString {
|
||||
DOMString::from(self.name.clone())
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
// https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype
|
||||
fn EntryType(&self) -> DOMString {
|
||||
DOMString::from(self.entry_type.clone())
|
||||
self.entry_type.clone()
|
||||
}
|
||||
|
||||
// https://w3c.github.io/performance-timeline/#dom-performanceentry-starttime
|
||||
|
|
|
@ -173,7 +173,7 @@ impl PerformanceResourceTimingMethods for PerformanceResourceTiming {
|
|||
// when a proxy is configured
|
||||
fn NextHopProtocol(&self) -> DOMString {
|
||||
match self.next_hop {
|
||||
Some(ref protocol) => DOMString::from(protocol.clone()),
|
||||
Some(ref protocol) => protocol.clone(),
|
||||
None => DOMString::from(""),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,7 +276,7 @@ impl ResponseMethods for Response {
|
|||
USVString(String::from(
|
||||
(*self.url.borrow())
|
||||
.as_ref()
|
||||
.map(|u| serialize_without_fragment(u))
|
||||
.map(serialize_without_fragment)
|
||||
.unwrap_or(""),
|
||||
))
|
||||
}
|
||||
|
|
|
@ -349,7 +349,7 @@ impl ServiceWorkerGlobalScope {
|
|||
let scope = global.upcast::<WorkerGlobalScope>();
|
||||
|
||||
let referrer = referrer_url
|
||||
.map(|url| Referrer::ReferrerUrl(url))
|
||||
.map(Referrer::ReferrerUrl)
|
||||
.unwrap_or_else(|| global.upcast::<GlobalScope>().get_referrer());
|
||||
|
||||
let request = RequestBuilder::new(script_url, referrer)
|
||||
|
|
|
@ -458,7 +458,7 @@ impl Tokenizer {
|
|||
system_id,
|
||||
} => {
|
||||
let doctype = DocumentType::new(
|
||||
DOMString::from(String::from(name)),
|
||||
DOMString::from(name),
|
||||
Some(DOMString::from(public_id)),
|
||||
Some(DOMString::from(system_id)),
|
||||
document,
|
||||
|
|
|
@ -61,7 +61,7 @@ impl Tokenizer {
|
|||
let tb = TreeBuilder::new_for_fragment(
|
||||
sink,
|
||||
Dom::from_ref(fc.context_elem),
|
||||
fc.form_elem.map(|n| Dom::from_ref(n)),
|
||||
fc.form_elem.map(Dom::from_ref),
|
||||
options,
|
||||
);
|
||||
|
||||
|
|
|
@ -192,11 +192,8 @@ impl StorageEventMethods for StorageEvent {
|
|||
url: USVString,
|
||||
storageArea: Option<&Storage>,
|
||||
) {
|
||||
self.event.init_event(
|
||||
Atom::from(type_),
|
||||
bool::from(bubbles),
|
||||
bool::from(cancelable),
|
||||
);
|
||||
self.event
|
||||
.init_event(Atom::from(type_), bubbles, cancelable);
|
||||
*self.key.borrow_mut() = key;
|
||||
*self.old_value.borrow_mut() = oldValue;
|
||||
*self.new_value.borrow_mut() = newValue;
|
||||
|
|
|
@ -44,7 +44,7 @@ impl TestRunnerMethods for TestRunner {
|
|||
self.get_bluetooth_thread()
|
||||
.send(BluetoothRequest::Test(String::from(dataSetName), sender))
|
||||
.unwrap();
|
||||
match receiver.recv().unwrap().into() {
|
||||
match receiver.recv().unwrap() {
|
||||
Ok(()) => Ok(()),
|
||||
Err(error) => Err(Error::from(error)),
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ impl<'a, E: TextControlElement> TextControlSelection<'a, E> {
|
|||
self.set_range(
|
||||
Some(start),
|
||||
Some(end),
|
||||
direction.map(|d| SelectionDirection::from(d)),
|
||||
direction.map(SelectionDirection::from),
|
||||
None,
|
||||
);
|
||||
Ok(())
|
||||
|
|
|
@ -49,7 +49,7 @@ impl TextTrack {
|
|||
id: id.into(),
|
||||
mode: Cell::new(mode),
|
||||
cue_list: Default::default(),
|
||||
track_list: DomRefCell::new(track_list.map(|t| Dom::from_ref(t))),
|
||||
track_list: DomRefCell::new(track_list.map(Dom::from_ref)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ impl VTTCueMethods for VTTCue {
|
|||
|
||||
// https://w3c.github.io/webvtt/#dom-vttcue-region
|
||||
fn SetRegion(&self, value: Option<&VTTRegion>) {
|
||||
*self.region.borrow_mut() = value.map(|r| Dom::from_ref(r))
|
||||
*self.region.borrow_mut() = value.map(Dom::from_ref)
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webvtt/#dom-vttcue-vertical
|
||||
|
|
|
@ -983,14 +983,14 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
fn GetResponseText(&self) -> Fallible<USVString> {
|
||||
match self.response_type.get() {
|
||||
XMLHttpRequestResponseType::_empty | XMLHttpRequestResponseType::Text => {
|
||||
Ok(USVString(String::from(match self.ready_state.get() {
|
||||
Ok(USVString(match self.ready_state.get() {
|
||||
// Step 3
|
||||
XMLHttpRequestState::Loading | XMLHttpRequestState::Done => {
|
||||
self.text_response()
|
||||
},
|
||||
// Step 2
|
||||
_ => "".to_owned(),
|
||||
})))
|
||||
}))
|
||||
},
|
||||
// Step 1
|
||||
_ => Err(Error::InvalidState),
|
||||
|
|
|
@ -44,12 +44,7 @@ impl XRRenderState {
|
|||
depth_far: Cell::new(depth_far),
|
||||
inline_vertical_fov: Cell::new(inline_vertical_fov),
|
||||
base_layer: MutNullableDom::new(layer),
|
||||
layers: DomRefCell::new(
|
||||
layers
|
||||
.into_iter()
|
||||
.map(|layer| Dom::from_ref(layer))
|
||||
.collect(),
|
||||
),
|
||||
layers: DomRefCell::new(layers.into_iter().map(Dom::from_ref).collect()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -441,7 +441,7 @@ impl XRSession {
|
|||
let callback = self.current_raf_callback_list.borrow()[i]
|
||||
.1
|
||||
.as_ref()
|
||||
.map(|callback| Rc::clone(callback));
|
||||
.map(Rc::clone);
|
||||
if let Some(callback) = callback {
|
||||
let _ = callback.Call__(time, &frame, ExceptionHandling::Report);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue