mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
clippy: fix result_unit_err
warnings (#31791)
* clippy: fix `result_unit_err` warnings * feat: fix result warnings in script * doc: document `generate_key` return type Co-authored-by: Martin Robinson <mrobinson@igalia.com> * feat: add back result to RangeRequestBounds::get_final Co-authored-by: Martin Robinson <mrobinson@igalia.com> --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
ea62a5e24f
commit
da696b7e57
14 changed files with 175 additions and 191 deletions
|
@ -1104,9 +1104,8 @@ impl<'a> CanvasData<'a> {
|
|||
updates.push(ImageUpdate::Update(image_key, descriptor, data));
|
||||
},
|
||||
None => {
|
||||
let key = match self.webrender_api.generate_key() {
|
||||
Ok(key) => key,
|
||||
Err(()) => return,
|
||||
let Some(key) = self.webrender_api.generate_key() else {
|
||||
return;
|
||||
};
|
||||
updates.push(ImageUpdate::Add(key, descriptor, data));
|
||||
self.image_key = Some(key);
|
||||
|
|
|
@ -30,7 +30,8 @@ pub enum ImageUpdate {
|
|||
}
|
||||
|
||||
pub trait WebrenderApi {
|
||||
fn generate_key(&self) -> Result<ImageKey, ()>;
|
||||
/// Attempt to generate an [`ImageKey`], returning `None` in case of failure.
|
||||
fn generate_key(&self) -> Option<ImageKey>;
|
||||
fn update_images(&self, updates: Vec<ImageUpdate>);
|
||||
fn clone(&self) -> Box<dyn WebrenderApi>;
|
||||
}
|
||||
|
|
|
@ -3180,7 +3180,7 @@ impl WebXRLayerGrandManagerAPI<WebXRSurfman> for WebXRBridgeGrandManager {
|
|||
&self,
|
||||
factory: WebXRLayerManagerFactory<WebXRSurfman>,
|
||||
) -> Result<WebXRLayerManager, WebXRError> {
|
||||
let (sender, receiver) = webgl_channel().map_err(|_| WebXRError::CommunicationError)?;
|
||||
let (sender, receiver) = webgl_channel().ok_or(WebXRError::CommunicationError)?;
|
||||
let _ = self.factory_sender.send(factory);
|
||||
let _ = self
|
||||
.sender
|
||||
|
@ -3221,7 +3221,7 @@ impl<GL: WebXRTypes> WebXRLayerManagerAPI<GL> for WebXRBridgeManager {
|
|||
context_id: WebXRContextId,
|
||||
init: WebXRLayerInit,
|
||||
) -> Result<WebXRLayerId, WebXRError> {
|
||||
let (sender, receiver) = webgl_channel().map_err(|_| WebXRError::CommunicationError)?;
|
||||
let (sender, receiver) = webgl_channel().ok_or(WebXRError::CommunicationError)?;
|
||||
let _ = self
|
||||
.sender
|
||||
.send(WebGLMsg::WebXRCommand(WebXRCommand::CreateLayer(
|
||||
|
@ -3264,7 +3264,7 @@ impl<GL: WebXRTypes> WebXRLayerManagerAPI<GL> for WebXRBridgeManager {
|
|||
_: &mut dyn WebXRContexts<GL>,
|
||||
layers: &[(WebXRContextId, WebXRLayerId)],
|
||||
) -> Result<Vec<WebXRSubImages>, WebXRError> {
|
||||
let (sender, receiver) = webgl_channel().map_err(|_| WebXRError::CommunicationError)?;
|
||||
let (sender, receiver) = webgl_channel().ok_or(WebXRError::CommunicationError)?;
|
||||
let _ = self
|
||||
.sender
|
||||
.send(WebGLMsg::WebXRCommand(WebXRCommand::BeginFrame(
|
||||
|
@ -3283,7 +3283,7 @@ impl<GL: WebXRTypes> WebXRLayerManagerAPI<GL> for WebXRBridgeManager {
|
|||
_: &mut dyn WebXRContexts<GL>,
|
||||
layers: &[(WebXRContextId, WebXRLayerId)],
|
||||
) -> Result<(), WebXRError> {
|
||||
let (sender, receiver) = webgl_channel().map_err(|_| WebXRError::CommunicationError)?;
|
||||
let (sender, receiver) = webgl_channel().ok_or(WebXRError::CommunicationError)?;
|
||||
let _ = self
|
||||
.sender
|
||||
.send(WebGLMsg::WebXRCommand(WebXRCommand::EndFrame(
|
||||
|
|
|
@ -83,7 +83,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn glplayer_channel<T>() -> Result<(GLPlayerSender<T>, GLPlayerReceiver<T>), ()>
|
||||
pub fn glplayer_channel<T>() -> Option<(GLPlayerSender<T>, GLPlayerReceiver<T>)>
|
||||
where
|
||||
T: for<'de> Deserialize<'de> + Serialize,
|
||||
{
|
||||
|
@ -91,10 +91,11 @@ where
|
|||
if true {
|
||||
ipc::glplayer_channel()
|
||||
.map(|(tx, rx)| (GLPlayerSender::Ipc(tx), GLPlayerReceiver::Ipc(rx)))
|
||||
.map_err(|_| ())
|
||||
.ok()
|
||||
} else {
|
||||
mpsc::glplayer_channel()
|
||||
.map(|(tx, rx)| (GLPlayerSender::Mpsc(tx), GLPlayerReceiver::Mpsc(rx)))
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,12 @@ pub struct CookieStorage {
|
|||
max_per_host: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RemoveCookieError {
|
||||
Overlapping,
|
||||
NonHTTP,
|
||||
}
|
||||
|
||||
impl CookieStorage {
|
||||
pub fn new(max_cookies: usize) -> CookieStorage {
|
||||
CookieStorage {
|
||||
|
@ -40,7 +46,7 @@ impl CookieStorage {
|
|||
cookie: &Cookie,
|
||||
url: &ServoUrl,
|
||||
source: CookieSource,
|
||||
) -> Result<Option<Cookie>, ()> {
|
||||
) -> Result<Option<Cookie>, RemoveCookieError> {
|
||||
let domain = reg_host(cookie.cookie.domain().as_ref().unwrap_or(&""));
|
||||
let cookies = self.cookies_map.entry(domain).or_default();
|
||||
|
||||
|
@ -61,7 +67,7 @@ impl CookieStorage {
|
|||
});
|
||||
|
||||
if any_overlapping {
|
||||
return Err(());
|
||||
return Err(RemoveCookieError::Overlapping);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +86,7 @@ impl CookieStorage {
|
|||
if c.cookie.http_only().unwrap_or(false) && source == CookieSource::NonHTTP {
|
||||
// Undo the removal.
|
||||
cookies.push(c);
|
||||
Err(())
|
||||
Err(RemoveCookieError::NonHTTP)
|
||||
} else {
|
||||
Ok(Some(c))
|
||||
}
|
||||
|
|
|
@ -569,7 +569,7 @@ pub enum RangeRequestBounds {
|
|||
}
|
||||
|
||||
impl RangeRequestBounds {
|
||||
pub fn get_final(&self, len: Option<u64>) -> Result<RelativePos, ()> {
|
||||
pub fn get_final(&self, len: Option<u64>) -> Result<RelativePos, &'static str> {
|
||||
match self {
|
||||
RangeRequestBounds::Final(pos) => {
|
||||
if let Some(len) = len {
|
||||
|
@ -577,7 +577,7 @@ impl RangeRequestBounds {
|
|||
return Ok(pos.clone());
|
||||
}
|
||||
}
|
||||
Err(())
|
||||
Err("Tried to process RangeRequestBounds::Final without len")
|
||||
},
|
||||
RangeRequestBounds::Pending(offset) => Ok(RelativePos::from_opts(
|
||||
if let Some(len) = len {
|
||||
|
@ -750,12 +750,10 @@ async fn scheme_fetch(
|
|||
|
||||
let range_header = request.headers.typed_get::<Range>();
|
||||
let is_range_request = range_header.is_some();
|
||||
let range = match get_range_request_bounds(range_header).get_final(file_size) {
|
||||
Ok(range) => range,
|
||||
Err(_) => {
|
||||
let Ok(range) = get_range_request_bounds(range_header).get_final(file_size)
|
||||
else {
|
||||
range_not_satisfiable_error(&mut response);
|
||||
return response;
|
||||
},
|
||||
};
|
||||
let mut reader = BufReader::with_capacity(FILE_CHUNK_SIZE, file);
|
||||
if reader.seek(SeekFrom::Start(range.start as u64)).is_err() {
|
||||
|
|
|
@ -293,12 +293,9 @@ impl FileManager {
|
|||
let file_impl = self.store.get_impl(id, file_token, origin_in)?;
|
||||
match file_impl {
|
||||
FileImpl::Memory(buf) => {
|
||||
let range = match range.get_final(Some(buf.size)) {
|
||||
Ok(range) => range,
|
||||
Err(_) => {
|
||||
return Err(BlobURLStoreError::InvalidRange);
|
||||
},
|
||||
};
|
||||
let range = range
|
||||
.get_final(Some(buf.size))
|
||||
.map_err(|_| BlobURLStoreError::InvalidRange)?;
|
||||
|
||||
let range = range.to_abs_range(buf.size as usize);
|
||||
let len = range.len() as u64;
|
||||
|
@ -328,12 +325,9 @@ impl FileManager {
|
|||
let file = File::open(&metadata.path)
|
||||
.map_err(|e| BlobURLStoreError::External(e.to_string()))?;
|
||||
|
||||
let range = match range.get_final(Some(metadata.size)) {
|
||||
Ok(range) => range,
|
||||
Err(_) => {
|
||||
return Err(BlobURLStoreError::InvalidRange);
|
||||
},
|
||||
};
|
||||
let range = range
|
||||
.get_final(Some(metadata.size))
|
||||
.map_err(|_| BlobURLStoreError::InvalidRange)?;
|
||||
|
||||
let mut reader = BufReader::with_capacity(FILE_CHUNK_SIZE, file);
|
||||
if reader.seek(SeekFrom::Start(range.start as u64)).is_err() {
|
||||
|
|
|
@ -318,91 +318,91 @@ impl DOMString {
|
|||
/// YYYY must be four or more digits, MM and DD both must be two digits
|
||||
/// <https://html.spec.whatwg.org/multipage/#valid-date-string>
|
||||
pub fn is_valid_date_string(&self) -> bool {
|
||||
self.parse_date_string().is_ok()
|
||||
self.parse_date_string().is_some()
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#parse-a-date-string>
|
||||
pub fn parse_date_string(&self) -> Result<(i32, u32, u32), ()> {
|
||||
pub fn parse_date_string(&self) -> Option<(i32, u32, u32)> {
|
||||
let value = &self.0;
|
||||
// Step 1, 2, 3
|
||||
let (year_int, month_int, day_int) = parse_date_component(value)?;
|
||||
|
||||
// Step 4
|
||||
if value.split('-').nth(3).is_some() {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 5, 6
|
||||
Ok((year_int, month_int, day_int))
|
||||
Some((year_int, month_int, day_int))
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#parse-a-time-string>
|
||||
pub fn parse_time_string(&self) -> Result<(u32, u32, f64), ()> {
|
||||
pub fn parse_time_string(&self) -> Option<(u32, u32, f64)> {
|
||||
let value = &self.0;
|
||||
// Step 1, 2, 3
|
||||
let (hour_int, minute_int, second_float) = parse_time_component(value)?;
|
||||
|
||||
// Step 4
|
||||
if value.split(':').nth(3).is_some() {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 5, 6
|
||||
Ok((hour_int, minute_int, second_float))
|
||||
Some((hour_int, minute_int, second_float))
|
||||
}
|
||||
|
||||
/// A valid month string should be "YYYY-MM"
|
||||
/// YYYY must be four or more digits, MM both must be two digits
|
||||
/// <https://html.spec.whatwg.org/multipage/#valid-month-string>
|
||||
pub fn is_valid_month_string(&self) -> bool {
|
||||
self.parse_month_string().is_ok()
|
||||
self.parse_month_string().is_some()
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#parse-a-month-string>
|
||||
pub fn parse_month_string(&self) -> Result<(i32, u32), ()> {
|
||||
pub fn parse_month_string(&self) -> Option<(i32, u32)> {
|
||||
let value = &self;
|
||||
// Step 1, 2, 3
|
||||
let (year_int, month_int) = parse_month_component(value)?;
|
||||
|
||||
// Step 4
|
||||
if value.split("-").nth(2).is_some() {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
// Step 5
|
||||
Ok((year_int, month_int))
|
||||
Some((year_int, month_int))
|
||||
}
|
||||
|
||||
/// A valid week string should be like {YYYY}-W{WW}, such as "2017-W52"
|
||||
/// YYYY must be four or more digits, WW both must be two digits
|
||||
/// <https://html.spec.whatwg.org/multipage/#valid-week-string>
|
||||
pub fn is_valid_week_string(&self) -> bool {
|
||||
self.parse_week_string().is_ok()
|
||||
self.parse_week_string().is_some()
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#parse-a-week-string>
|
||||
pub fn parse_week_string(&self) -> Result<(i32, u32), ()> {
|
||||
pub fn parse_week_string(&self) -> Option<(i32, u32)> {
|
||||
let value = &self.0;
|
||||
// Step 1, 2, 3
|
||||
let mut iterator = value.split('-');
|
||||
let year = iterator.next().ok_or(())?;
|
||||
let year = iterator.next()?;
|
||||
|
||||
// Step 4
|
||||
let year_int = year.parse::<i32>().map_err(|_| ())?;
|
||||
let year_int = year.parse::<i32>().ok()?;
|
||||
if year.len() < 4 || year_int == 0 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 5, 6
|
||||
let week = iterator.next().ok_or(())?;
|
||||
let week = iterator.next()?;
|
||||
let (week_first, week_last) = week.split_at(1);
|
||||
if week_first != "W" {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 7
|
||||
let week_int = week_last.parse::<u32>().map_err(|_| ())?;
|
||||
let week_int = week_last.parse::<u32>().ok()?;
|
||||
if week_last.len() != 2 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 8
|
||||
|
@ -410,16 +410,16 @@ impl DOMString {
|
|||
|
||||
// Step 9
|
||||
if week_int < 1 || week_int > max_week {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 10
|
||||
if iterator.next().is_some() {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 11
|
||||
Ok((year_int, week_int))
|
||||
Some((year_int, week_int))
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#valid-floating-point-number>
|
||||
|
@ -428,37 +428,32 @@ impl DOMString {
|
|||
static ref RE: Regex =
|
||||
Regex::new(r"^-?(?:\d+\.\d+|\d+|\.\d+)(?:(e|E)(\+|\-)?\d+)?$").unwrap();
|
||||
}
|
||||
RE.is_match(&self.0) && self.parse_floating_point_number().is_ok()
|
||||
RE.is_match(&self.0) && self.parse_floating_point_number().is_some()
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-floating-point-number-values>
|
||||
pub fn parse_floating_point_number(&self) -> Result<f64, ()> {
|
||||
pub fn parse_floating_point_number(&self) -> Option<f64> {
|
||||
// Steps 15-16 are telling us things about IEEE rounding modes
|
||||
// for floating-point significands; this code assumes the Rust
|
||||
// compiler already matches them in any cases where
|
||||
// that actually matters. They are not
|
||||
// related to f64::round(), which is for rounding to integers.
|
||||
let input = &self.0;
|
||||
match input.trim().parse::<f64>() {
|
||||
Ok(val)
|
||||
if let Ok(val) = input.trim().parse::<f64>() {
|
||||
if !(
|
||||
// A valid number is the same as what rust considers to be valid,
|
||||
// except for +1., NaN, and Infinity.
|
||||
val.is_infinite() ||
|
||||
val.is_nan() ||
|
||||
input.ends_with(".") ||
|
||||
input.starts_with("+")
|
||||
) =>
|
||||
{
|
||||
Ok(val)
|
||||
},
|
||||
_ => Err(()),
|
||||
val.is_infinite() || val.is_nan() || input.ends_with(".") || input.starts_with("+")
|
||||
) {
|
||||
return Some(val);
|
||||
}
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#best-representation-of-the-number-as-a-floating-point-number>
|
||||
pub fn set_best_representation_of_the_floating_point_number(&mut self) {
|
||||
if let Ok(val) = self.parse_floating_point_number() {
|
||||
if let Some(val) = self.parse_floating_point_number() {
|
||||
self.0 = val.to_string();
|
||||
}
|
||||
}
|
||||
|
@ -466,7 +461,7 @@ impl DOMString {
|
|||
/// A valid normalized local date and time string should be "{date}T{time}"
|
||||
/// where date and time are both valid, and the time string must be as short as possible
|
||||
/// <https://html.spec.whatwg.org/multipage/#valid-normalised-local-date-and-time-string>
|
||||
pub fn convert_valid_normalized_local_date_and_time_string(&mut self) -> Result<(), ()> {
|
||||
pub fn convert_valid_normalized_local_date_and_time_string(&mut self) -> Option<()> {
|
||||
let ((year, month, day), (hour, minute, second)) =
|
||||
self.parse_local_date_and_time_string()?;
|
||||
if second == 0.0 {
|
||||
|
@ -488,13 +483,11 @@ impl DOMString {
|
|||
year, month, day, hour, minute, second
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
Some(())
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#parse-a-local-date-and-time-string>
|
||||
pub fn parse_local_date_and_time_string(
|
||||
&self,
|
||||
) -> Result<((i32, u32, u32), (u32, u32, f64)), ()> {
|
||||
pub fn parse_local_date_and_time_string(&self) -> Option<((i32, u32, u32), (u32, u32, f64))> {
|
||||
let value = &self;
|
||||
// Step 1, 2, 4
|
||||
let mut iterator = if value.contains('T') {
|
||||
|
@ -504,20 +497,20 @@ impl DOMString {
|
|||
};
|
||||
|
||||
// Step 3
|
||||
let date = iterator.next().ok_or(())?;
|
||||
let date = iterator.next()?;
|
||||
let date_tuple = parse_date_component(date)?;
|
||||
|
||||
// Step 5
|
||||
let time = iterator.next().ok_or(())?;
|
||||
let time = iterator.next()?;
|
||||
let time_tuple = parse_time_component(time)?;
|
||||
|
||||
// Step 6
|
||||
if iterator.next().is_some() {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 7, 8, 9
|
||||
Ok((date_tuple, time_tuple))
|
||||
Some((date_tuple, time_tuple))
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#valid-e-mail-address>
|
||||
|
@ -670,114 +663,114 @@ impl Extend<char> for DOMString {
|
|||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#parse-a-month-component>
|
||||
fn parse_month_component(value: &str) -> Result<(i32, u32), ()> {
|
||||
fn parse_month_component(value: &str) -> Option<(i32, u32)> {
|
||||
// Step 3
|
||||
let mut iterator = value.split('-');
|
||||
let year = iterator.next().ok_or(())?;
|
||||
let month = iterator.next().ok_or(())?;
|
||||
let year = iterator.next()?;
|
||||
let month = iterator.next()?;
|
||||
|
||||
// Step 1, 2
|
||||
let year_int = year.parse::<i32>().map_err(|_| ())?;
|
||||
let year_int = year.parse::<i32>().ok()?;
|
||||
if year.len() < 4 || year_int == 0 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 4, 5
|
||||
let month_int = month.parse::<u32>().map_err(|_| ())?;
|
||||
let month_int = month.parse::<u32>().ok()?;
|
||||
if month.len() != 2 || month_int > 12 || month_int < 1 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 6
|
||||
Ok((year_int, month_int))
|
||||
Some((year_int, month_int))
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#parse-a-date-component>
|
||||
fn parse_date_component(value: &str) -> Result<(i32, u32, u32), ()> {
|
||||
fn parse_date_component(value: &str) -> Option<(i32, u32, u32)> {
|
||||
// Step 1
|
||||
let (year_int, month_int) = parse_month_component(value)?;
|
||||
|
||||
// Step 3, 4
|
||||
let day = value.split('-').nth(2).ok_or(())?;
|
||||
let day_int = day.parse::<u32>().map_err(|_| ())?;
|
||||
let day = value.split('-').nth(2)?;
|
||||
let day_int = day.parse::<u32>().ok()?;
|
||||
if day.len() != 2 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 2, 5
|
||||
let max_day = max_day_in_month(year_int, month_int)?;
|
||||
if day_int == 0 || day_int > max_day {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 6
|
||||
Ok((year_int, month_int, day_int))
|
||||
Some((year_int, month_int, day_int))
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#parse-a-time-component>
|
||||
fn parse_time_component(value: &str) -> Result<(u32, u32, f64), ()> {
|
||||
fn parse_time_component(value: &str) -> Option<(u32, u32, f64)> {
|
||||
// Step 1
|
||||
let mut iterator = value.split(':');
|
||||
let hour = iterator.next().ok_or(())?;
|
||||
let hour = iterator.next()?;
|
||||
if hour.len() != 2 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
let hour_int = hour.parse::<u32>().map_err(|_| ())?;
|
||||
let hour_int = hour.parse::<u32>().ok()?;
|
||||
|
||||
// Step 2
|
||||
if hour_int > 23 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 3, 4
|
||||
let minute = iterator.next().ok_or(())?;
|
||||
let minute = iterator.next()?;
|
||||
if minute.len() != 2 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
let minute_int = minute.parse::<u32>().map_err(|_| ())?;
|
||||
let minute_int = minute.parse::<u32>().ok()?;
|
||||
|
||||
// Step 5
|
||||
if minute_int > 59 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 6, 7
|
||||
let second_float = match iterator.next() {
|
||||
Some(second) => {
|
||||
let mut second_iterator = second.split('.');
|
||||
if second_iterator.next().ok_or(())?.len() != 2 {
|
||||
return Err(());
|
||||
if second_iterator.next()?.len() != 2 {
|
||||
return None;
|
||||
}
|
||||
match second_iterator.next() {
|
||||
Some(second_last) => {
|
||||
if second_last.len() > 3 {
|
||||
return Err(());
|
||||
return None;
|
||||
}
|
||||
},
|
||||
None => {},
|
||||
}
|
||||
|
||||
second.parse::<f64>().map_err(|_| ())?
|
||||
second.parse::<f64>().ok()?
|
||||
},
|
||||
None => 0.0,
|
||||
};
|
||||
|
||||
// Step 8
|
||||
Ok((hour_int, minute_int, second_float))
|
||||
Some((hour_int, minute_int, second_float))
|
||||
}
|
||||
|
||||
fn max_day_in_month(year_num: i32, month_num: u32) -> Result<u32, ()> {
|
||||
fn max_day_in_month(year_num: i32, month_num: u32) -> Option<u32> {
|
||||
match month_num {
|
||||
1 | 3 | 5 | 7 | 8 | 10 | 12 => Ok(31),
|
||||
4 | 6 | 9 | 11 => Ok(30),
|
||||
1 | 3 | 5 | 7 | 8 | 10 | 12 => Some(31),
|
||||
4 | 6 | 9 | 11 => Some(30),
|
||||
2 => {
|
||||
if is_leap_year(year_num) {
|
||||
Ok(29)
|
||||
Some(29)
|
||||
} else {
|
||||
Ok(28)
|
||||
Some(28)
|
||||
}
|
||||
},
|
||||
_ => Err(()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -500,7 +500,8 @@ impl HTMLInputElement {
|
|||
.upcast::<Element>()
|
||||
.get_attribute(&ns!(), &local_name!("step"))
|
||||
{
|
||||
if let Ok(step) = DOMString::from(attr.summarize().value).parse_floating_point_number()
|
||||
if let Some(step) =
|
||||
DOMString::from(attr.summarize().value).parse_floating_point_number()
|
||||
{
|
||||
if step > 0.0 {
|
||||
return Some(step * self.step_scale_factor());
|
||||
|
@ -517,7 +518,8 @@ impl HTMLInputElement {
|
|||
.upcast::<Element>()
|
||||
.get_attribute(&ns!(), &local_name!("min"))
|
||||
{
|
||||
if let Ok(min) = self.convert_string_to_number(&DOMString::from(attr.summarize().value))
|
||||
if let Some(min) =
|
||||
self.convert_string_to_number(&DOMString::from(attr.summarize().value))
|
||||
{
|
||||
return Some(min);
|
||||
}
|
||||
|
@ -531,7 +533,8 @@ impl HTMLInputElement {
|
|||
.upcast::<Element>()
|
||||
.get_attribute(&ns!(), &local_name!("max"))
|
||||
{
|
||||
if let Ok(max) = self.convert_string_to_number(&DOMString::from(attr.summarize().value))
|
||||
if let Some(max) =
|
||||
self.convert_string_to_number(&DOMString::from(attr.summarize().value))
|
||||
{
|
||||
return Some(max);
|
||||
}
|
||||
|
@ -631,7 +634,7 @@ impl HTMLInputElement {
|
|||
.get_attribute(&ns!(), &local_name!("min"))
|
||||
{
|
||||
let minstr = &DOMString::from(attr.summarize().value);
|
||||
if let Ok(min) = self.convert_string_to_number(minstr) {
|
||||
if let Some(min) = self.convert_string_to_number(minstr) {
|
||||
return min;
|
||||
}
|
||||
}
|
||||
|
@ -639,7 +642,7 @@ impl HTMLInputElement {
|
|||
.upcast::<Element>()
|
||||
.get_attribute(&ns!(), &local_name!("value"))
|
||||
{
|
||||
if let Ok(value) =
|
||||
if let Some(value) =
|
||||
self.convert_string_to_number(&DOMString::from(attr.summarize().value))
|
||||
{
|
||||
return value;
|
||||
|
@ -876,7 +879,7 @@ impl HTMLInputElement {
|
|||
// https://html.spec.whatwg.org/multipage/#time-state-(type%3Dtime)%3Asuffering-from-bad-input
|
||||
InputType::Time => !value.is_valid_time_string(),
|
||||
// https://html.spec.whatwg.org/multipage/#local-date-and-time-state-(type%3Ddatetime-local)%3Asuffering-from-bad-input
|
||||
InputType::DatetimeLocal => value.parse_local_date_and_time_string().is_err(),
|
||||
InputType::DatetimeLocal => value.parse_local_date_and_time_string().is_none(),
|
||||
// https://html.spec.whatwg.org/multipage/#number-state-(type%3Dnumber)%3Asuffering-from-bad-input
|
||||
// https://html.spec.whatwg.org/multipage/#range-state-(type%3Drange)%3Asuffering-from-bad-input
|
||||
InputType::Number | InputType::Range => !value.is_valid_floating_point_number_string(),
|
||||
|
@ -924,9 +927,8 @@ impl HTMLInputElement {
|
|||
return ValidationFlags::empty();
|
||||
}
|
||||
|
||||
let value_as_number = match self.convert_string_to_number(value) {
|
||||
Ok(num) => num,
|
||||
Err(()) => return ValidationFlags::empty(),
|
||||
let Some(value_as_number) = self.convert_string_to_number(value) else {
|
||||
return ValidationFlags::empty();
|
||||
};
|
||||
|
||||
let mut failed_flags = ValidationFlags::empty();
|
||||
|
@ -1328,7 +1330,6 @@ impl HTMLInputElementMethods for HTMLInputElement {
|
|||
};
|
||||
NonNull::new_unchecked(NewDateObject(*cx, time))
|
||||
})
|
||||
.ok()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-input-valueasdate
|
||||
|
@ -1965,7 +1966,7 @@ impl HTMLInputElement {
|
|||
InputType::DatetimeLocal => {
|
||||
if value
|
||||
.convert_valid_normalized_local_date_and_time_string()
|
||||
.is_err()
|
||||
.is_none()
|
||||
{
|
||||
value.clear();
|
||||
}
|
||||
|
@ -2132,54 +2133,48 @@ impl HTMLInputElement {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#concept-input-value-string-number
|
||||
fn convert_string_to_number(&self, value: &DOMString) -> Result<f64, ()> {
|
||||
fn convert_string_to_number(&self, value: &DOMString) -> Option<f64> {
|
||||
match self.input_type() {
|
||||
InputType::Date => value
|
||||
.parse_date_string()
|
||||
.ok()
|
||||
.and_then(|(year, month, day)| NaiveDate::from_ymd_opt(year, month, day))
|
||||
.and_then(|date| date.and_hms_opt(0, 0, 0))
|
||||
.map(|time| Ok(time.and_utc().timestamp_millis() as f64))
|
||||
.unwrap_or(Err(())),
|
||||
.map(|time| time.and_utc().timestamp_millis() as f64),
|
||||
InputType::Month => match value.parse_month_string() {
|
||||
// This one returns number of months, not milliseconds
|
||||
// (specification requires this, presumably because number of
|
||||
// milliseconds is not consistent across months)
|
||||
// the - 1.0 is because january is 1, not 0
|
||||
Ok((year, month)) => Ok(((year - 1970) * 12) as f64 + (month as f64 - 1.0)),
|
||||
_ => Err(()),
|
||||
Some((year, month)) => Some(((year - 1970) * 12) as f64 + (month as f64 - 1.0)),
|
||||
_ => None,
|
||||
},
|
||||
InputType::Week => value
|
||||
.parse_week_string()
|
||||
.ok()
|
||||
.and_then(|(year, weeknum)| NaiveDate::from_isoywd_opt(year, weeknum, Weekday::Mon))
|
||||
.and_then(|date| date.and_hms_opt(0, 0, 0))
|
||||
.map(|time| Ok(time.and_utc().timestamp_millis() as f64))
|
||||
.unwrap_or(Err(())),
|
||||
.map(|time| time.and_utc().timestamp_millis() as f64),
|
||||
InputType::Time => match value.parse_time_string() {
|
||||
Ok((hours, minutes, seconds)) => {
|
||||
Ok((seconds as f64 + 60.0 * minutes as f64 + 3600.0 * hours as f64) * 1000.0)
|
||||
Some((hours, minutes, seconds)) => {
|
||||
Some((seconds as f64 + 60.0 * minutes as f64 + 3600.0 * hours as f64) * 1000.0)
|
||||
},
|
||||
_ => Err(()),
|
||||
_ => None,
|
||||
},
|
||||
InputType::DatetimeLocal => {
|
||||
// Is this supposed to know the locale's daylight-savings-time rules?
|
||||
value
|
||||
.parse_local_date_and_time_string()
|
||||
.ok()
|
||||
.and_then(|((year, month, day), (hours, minutes, seconds))| {
|
||||
value.parse_local_date_and_time_string().and_then(
|
||||
|((year, month, day), (hours, minutes, seconds))| {
|
||||
let hms_millis =
|
||||
(seconds + 60.0 * minutes as f64 + 3600.0 * hours as f64) * 1000.0;
|
||||
NaiveDate::from_ymd_opt(year, month, day)
|
||||
.and_then(|date| date.and_hms_opt(0, 0, 0))
|
||||
.map(|time| Ok(time.and_utc().timestamp_millis() as f64 + hms_millis))
|
||||
})
|
||||
.unwrap_or(Err(()))
|
||||
.map(|time| time.and_utc().timestamp_millis() as f64 + hms_millis)
|
||||
},
|
||||
)
|
||||
},
|
||||
InputType::Number | InputType::Range => value.parse_floating_point_number(),
|
||||
// min/max/valueAsNumber/stepDown/stepUp do not apply to
|
||||
// the remaining types
|
||||
_ => Err(()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2222,40 +2217,30 @@ impl HTMLInputElement {
|
|||
// https://html.spec.whatwg.org/multipage/#concept-input-value-string-date
|
||||
// This does the safe Rust part of conversion; the unsafe JS Date part
|
||||
// is in GetValueAsDate
|
||||
fn convert_string_to_naive_datetime(&self, value: DOMString) -> Result<NaiveDateTime, ()> {
|
||||
fn convert_string_to_naive_datetime(&self, value: DOMString) -> Option<NaiveDateTime> {
|
||||
match self.input_type() {
|
||||
InputType::Date => value
|
||||
.parse_date_string()
|
||||
.ok()
|
||||
.and_then(|(y, m, d)| NaiveDate::from_ymd_opt(y, m, d))
|
||||
.and_then(|date| date.and_hms_opt(0, 0, 0))
|
||||
.ok_or(()),
|
||||
InputType::Time => value
|
||||
.parse_time_string()
|
||||
.ok()
|
||||
.and_then(|(h, m, s)| {
|
||||
.and_then(|date| date.and_hms_opt(0, 0, 0)),
|
||||
InputType::Time => value.parse_time_string().and_then(|(h, m, s)| {
|
||||
let whole_seconds = s.floor();
|
||||
let nanos = ((s - whole_seconds) * 1e9).floor() as u32;
|
||||
NaiveDate::from_ymd_opt(1970, 1, 1)
|
||||
.and_then(|date| date.and_hms_nano_opt(h, m, whole_seconds as u32, nanos))
|
||||
})
|
||||
.ok_or(()),
|
||||
}),
|
||||
InputType::Week => value
|
||||
.parse_week_string()
|
||||
.ok()
|
||||
.and_then(|(iso_year, week)| {
|
||||
NaiveDate::from_isoywd_opt(iso_year, week, Weekday::Mon)
|
||||
})
|
||||
.and_then(|date| date.and_hms_opt(0, 0, 0))
|
||||
.ok_or(()),
|
||||
.and_then(|date| date.and_hms_opt(0, 0, 0)),
|
||||
InputType::Month => value
|
||||
.parse_month_string()
|
||||
.ok()
|
||||
.and_then(|(y, m)| NaiveDate::from_ymd_opt(y, m, 1))
|
||||
.and_then(|date| date.and_hms_opt(0, 0, 0))
|
||||
.ok_or(()),
|
||||
.and_then(|date| date.and_hms_opt(0, 0, 0)),
|
||||
// does not apply to other types
|
||||
_ => Err(()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -218,9 +218,8 @@ impl VideoFrameRenderer for MediaFrameRenderer {
|
|||
Some((ref mut image_key, ref mut width, ref mut height)) => {
|
||||
self.old_frame = Some(*image_key);
|
||||
|
||||
let new_image_key = match self.api.generate_image_key() {
|
||||
Ok(key) => key,
|
||||
Err(()) => return,
|
||||
let Some(new_image_key) = self.api.generate_image_key() else {
|
||||
return;
|
||||
};
|
||||
|
||||
/* update current_frame */
|
||||
|
@ -251,9 +250,8 @@ impl VideoFrameRenderer for MediaFrameRenderer {
|
|||
updates.push(ImageUpdate::AddImage(new_image_key, descriptor, image_data));
|
||||
},
|
||||
None => {
|
||||
let image_key = match self.api.generate_image_key() {
|
||||
Ok(key) => key,
|
||||
Err(()) => return,
|
||||
let Some(image_key) = self.api.generate_image_key() else {
|
||||
return;
|
||||
};
|
||||
self.current_frame = Some((image_key, frame.get_width(), frame.get_height()));
|
||||
|
||||
|
|
|
@ -1036,14 +1036,14 @@ impl gfx_traits::WebrenderApi for FontCacheWR {
|
|||
struct CanvasWebrenderApi(CompositorProxy);
|
||||
|
||||
impl canvas_paint_thread::WebrenderApi for CanvasWebrenderApi {
|
||||
fn generate_key(&self) -> Result<ImageKey, ()> {
|
||||
fn generate_key(&self) -> Option<ImageKey> {
|
||||
let (sender, receiver) = unbounded();
|
||||
let _ = self
|
||||
.0
|
||||
.send(CompositorMsg::Forwarded(ForwardedToCompositorMsg::Canvas(
|
||||
CanvasToCompositorMsg::GenerateKey(sender),
|
||||
)));
|
||||
receiver.recv().map_err(|_| ())
|
||||
receiver.recv().ok()
|
||||
}
|
||||
fn update_images(&self, updates: Vec<canvas_paint_thread::ImageUpdate>) {
|
||||
let _ = self
|
||||
|
|
|
@ -49,13 +49,19 @@ impl<T: Serialize> WebGLSender<T> {
|
|||
#[inline]
|
||||
pub fn send(&self, msg: T) -> WebGLSendResult {
|
||||
match *self {
|
||||
WebGLSender::Ipc(ref sender) => sender.send(msg).map_err(|_| ()),
|
||||
WebGLSender::Mpsc(ref sender) => sender.send(msg).map_err(|_| ()),
|
||||
WebGLSender::Ipc(ref sender) => sender.send(msg).map_err(|_| WebGLSendError),
|
||||
WebGLSender::Mpsc(ref sender) => sender.send(msg).map_err(|_| WebGLSendError),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type WebGLSendResult = Result<(), ()>;
|
||||
#[derive(Debug)]
|
||||
pub struct WebGLSendError;
|
||||
pub type WebGLSendResult = Result<(), WebGLSendError>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WebGLReceiveError;
|
||||
pub type WebGLReceiveResult<T> = Result<T, WebGLReceiveError>;
|
||||
|
||||
pub enum WebGLReceiver<T>
|
||||
where
|
||||
|
@ -69,17 +75,17 @@ impl<T> WebGLReceiver<T>
|
|||
where
|
||||
T: for<'de> Deserialize<'de> + Serialize,
|
||||
{
|
||||
pub fn recv(&self) -> Result<T, ()> {
|
||||
pub fn recv(&self) -> WebGLReceiveResult<T> {
|
||||
match *self {
|
||||
WebGLReceiver::Ipc(ref receiver) => receiver.recv().map_err(|_| ()),
|
||||
WebGLReceiver::Mpsc(ref receiver) => receiver.recv().map_err(|_| ()),
|
||||
WebGLReceiver::Ipc(ref receiver) => receiver.recv().map_err(|_| WebGLReceiveError),
|
||||
WebGLReceiver::Mpsc(ref receiver) => receiver.recv().map_err(|_| WebGLReceiveError),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_recv(&self) -> Result<T, ()> {
|
||||
pub fn try_recv(&self) -> WebGLReceiveResult<T> {
|
||||
match *self {
|
||||
WebGLReceiver::Ipc(ref receiver) => receiver.try_recv().map_err(|_| ()),
|
||||
WebGLReceiver::Mpsc(ref receiver) => receiver.try_recv().map_err(|_| ()),
|
||||
WebGLReceiver::Ipc(ref receiver) => receiver.try_recv().map_err(|_| WebGLReceiveError),
|
||||
WebGLReceiver::Mpsc(ref receiver) => receiver.try_recv().map_err(|_| WebGLReceiveError),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,16 +102,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn webgl_channel<T>() -> Result<(WebGLSender<T>, WebGLReceiver<T>), ()>
|
||||
pub fn webgl_channel<T>() -> Option<(WebGLSender<T>, WebGLReceiver<T>)>
|
||||
where
|
||||
T: for<'de> Deserialize<'de> + Serialize,
|
||||
{
|
||||
if *IS_MULTIPROCESS {
|
||||
ipc::webgl_channel()
|
||||
.map(|(tx, rx)| (WebGLSender::Ipc(tx), WebGLReceiver::Ipc(rx)))
|
||||
.map_err(|_| ())
|
||||
.ok()
|
||||
} else {
|
||||
mpsc::webgl_channel().map(|(tx, rx)| (WebGLSender::Mpsc(tx), WebGLReceiver::Mpsc(rx)))
|
||||
mpsc::webgl_channel()
|
||||
.map(|(tx, rx)| (WebGLSender::Mpsc(tx), WebGLReceiver::Mpsc(rx)))
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1227,12 +1227,12 @@ impl WebrenderIpcSender {
|
|||
}
|
||||
|
||||
/// Create a new image key. Blocks until the key is available.
|
||||
pub fn generate_image_key(&self) -> Result<ImageKey, ()> {
|
||||
pub fn generate_image_key(&self) -> Option<ImageKey> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.0
|
||||
.send(ScriptToCompositorMsg::GenerateImageKey(sender))
|
||||
.map_err(|_| ())?;
|
||||
receiver.recv().map_err(|_| ())
|
||||
.ok()?;
|
||||
receiver.recv().ok()
|
||||
}
|
||||
|
||||
/// Perform a resource update operation.
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![allow(clippy::result_unit_err)]
|
||||
#![crate_name = "servo_url"]
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue