mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Make creating CssUrl infallible.
There were a check in CssUrl::parse_from_string for extra data, which was removed as part of servo/servo#16241, so it never fails now. CssUrl::from_url_value_data doesn't seem to need Result from the very beginning. It is unclear why it was made that way. Bug: 1461858 Reviewed-by: emilio MozReview-Commit-ID: LXzKlZ6wPYW
This commit is contained in:
parent
0b5720547e
commit
dc2aadd43a
6 changed files with 28 additions and 42 deletions
|
@ -429,7 +429,6 @@ impl nsStyleImage {
|
||||||
unsafe fn get_image_url(self: &nsStyleImage) -> ComputedImageUrl {
|
unsafe fn get_image_url(self: &nsStyleImage) -> ComputedImageUrl {
|
||||||
let url_value = bindings::Gecko_GetURLValue(self);
|
let url_value = bindings::Gecko_GetURLValue(self);
|
||||||
ComputedImageUrl::from_url_value_data(url_value.as_ref().unwrap())
|
ComputedImageUrl::from_url_value_data(url_value.as_ref().unwrap())
|
||||||
.expect("Could not convert to ComputedUrl")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn get_gradient(self: &nsStyleImage) -> Box<Gradient> {
|
unsafe fn get_gradient(self: &nsStyleImage) -> Box<Gradient> {
|
||||||
|
@ -679,7 +678,7 @@ pub mod basic_shape {
|
||||||
StyleShapeSourceType::URL => unsafe {
|
StyleShapeSourceType::URL => unsafe {
|
||||||
let shape_image = &*other.mShapeImage.mPtr;
|
let shape_image = &*other.mShapeImage.mPtr;
|
||||||
let other_url = &(**shape_image.__bindgen_anon_1.mURLValue.as_ref());
|
let other_url = &(**shape_image.__bindgen_anon_1.mURLValue.as_ref());
|
||||||
let url = ComputedUrl::from_url_value_data(&other_url._base).unwrap();
|
let url = ComputedUrl::from_url_value_data(&other_url._base);
|
||||||
ShapeSource::ImageOrUrl(url)
|
ShapeSource::ImageOrUrl(url)
|
||||||
},
|
},
|
||||||
StyleShapeSourceType::Image => {
|
StyleShapeSourceType::Image => {
|
||||||
|
|
|
@ -38,16 +38,11 @@ pub struct CssUrl {
|
||||||
impl CssUrl {
|
impl CssUrl {
|
||||||
/// Try to parse a URL from a string value that is a valid CSS token for a
|
/// Try to parse a URL from a string value that is a valid CSS token for a
|
||||||
/// URL.
|
/// URL.
|
||||||
///
|
pub fn parse_from_string(url: String, context: &ParserContext) -> Self {
|
||||||
/// Returns `Err` in the case that extra_data is incomplete.
|
CssUrl {
|
||||||
pub fn parse_from_string<'a>(
|
|
||||||
url: String,
|
|
||||||
context: &ParserContext,
|
|
||||||
) -> Result<Self, ParseError<'a>> {
|
|
||||||
Ok(CssUrl {
|
|
||||||
serialization: Arc::new(url),
|
serialization: Arc::new(url),
|
||||||
extra_data: context.url_data.clone(),
|
extra_data: context.url_data.clone(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the URL is definitely invalid. We don't eagerly resolve
|
/// Returns true if the URL is definitely invalid. We don't eagerly resolve
|
||||||
|
@ -58,13 +53,13 @@ impl CssUrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from URLValueData to SpecifiedUrl.
|
/// Convert from URLValueData to SpecifiedUrl.
|
||||||
unsafe fn from_url_value_data(url: &URLValueData) -> Result<Self, ()> {
|
unsafe fn from_url_value_data(url: &URLValueData) -> Self {
|
||||||
let arc_type =
|
let arc_type =
|
||||||
&url.mString as *const _ as *const RawOffsetArc<String>;
|
&url.mString as *const _ as *const RawOffsetArc<String>;
|
||||||
Ok(CssUrl {
|
CssUrl {
|
||||||
serialization: Arc::from_raw_offset((*arc_type).clone()),
|
serialization: Arc::from_raw_offset((*arc_type).clone()),
|
||||||
extra_data: url.mExtraData.to_safe(),
|
extra_data: url.mExtraData.to_safe(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this URL looks like a fragment.
|
/// Returns true if this URL looks like a fragment.
|
||||||
|
@ -104,7 +99,7 @@ impl Parse for CssUrl {
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
let url = input.expect_url()?;
|
let url = input.expect_url()?;
|
||||||
Self::parse_from_string(url.as_ref().to_owned(), context)
|
Ok(Self::parse_from_string(url.as_ref().to_owned(), context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,11 +183,8 @@ pub struct SpecifiedImageUrl {
|
||||||
|
|
||||||
impl SpecifiedImageUrl {
|
impl SpecifiedImageUrl {
|
||||||
/// Parse a URL from a string value. See SpecifiedUrl::parse_from_string.
|
/// Parse a URL from a string value. See SpecifiedUrl::parse_from_string.
|
||||||
pub fn parse_from_string<'a>(
|
pub fn parse_from_string(url: String, context: &ParserContext) -> Self {
|
||||||
url: String,
|
Self::from_css_url(CssUrl::parse_from_string(url, context))
|
||||||
context: &ParserContext,
|
|
||||||
) -> Result<Self, ParseError<'a>> {
|
|
||||||
CssUrl::parse_from_string(url, context).map(Self::from_css_url)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_css_url(url: CssUrl) -> Self {
|
fn from_css_url(url: CssUrl) -> Self {
|
||||||
|
@ -296,10 +288,10 @@ impl ToCss for ComputedUrl {
|
||||||
|
|
||||||
impl ComputedUrl {
|
impl ComputedUrl {
|
||||||
/// Convert from URLValueData to ComputedUrl.
|
/// Convert from URLValueData to ComputedUrl.
|
||||||
pub unsafe fn from_url_value_data(url: &URLValueData) -> Result<Self, ()> {
|
pub unsafe fn from_url_value_data(url: &URLValueData) -> Self {
|
||||||
Ok(ComputedUrl(
|
ComputedUrl(
|
||||||
SpecifiedUrl::from_css_url(CssUrl::from_url_value_data(url)?)
|
SpecifiedUrl::from_css_url(CssUrl::from_url_value_data(url))
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,10 +310,10 @@ impl ToCss for ComputedImageUrl {
|
||||||
|
|
||||||
impl ComputedImageUrl {
|
impl ComputedImageUrl {
|
||||||
/// Convert from URLValueData to SpecifiedUrl.
|
/// Convert from URLValueData to SpecifiedUrl.
|
||||||
pub unsafe fn from_url_value_data(url: &URLValueData) -> Result<Self, ()> {
|
pub unsafe fn from_url_value_data(url: &URLValueData) -> Self {
|
||||||
Ok(ComputedImageUrl(
|
ComputedImageUrl(
|
||||||
SpecifiedImageUrl::from_css_url(CssUrl::from_url_value_data(url)?)
|
SpecifiedImageUrl::from_css_url(CssUrl::from_url_value_data(url))
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from nsStyleImageReques to ComputedImageUrl.
|
/// Convert from nsStyleImageReques to ComputedImageUrl.
|
||||||
|
@ -332,6 +324,6 @@ impl ComputedImageUrl {
|
||||||
|
|
||||||
let image_value = image_request.mImageValue.mRawPtr.as_ref().unwrap();
|
let image_value = image_request.mImageValue.mRawPtr.as_ref().unwrap();
|
||||||
let url_value_data = &image_value._base;
|
let url_value_data = &image_value._base;
|
||||||
Self::from_url_value_data(url_value_data)
|
Ok(Self::from_url_value_data(url_value_data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -762,7 +762,7 @@ def set_gecko_property(ffi_name, expr):
|
||||||
SVGPaintKind::PaintServer(
|
SVGPaintKind::PaintServer(
|
||||||
ComputedUrl::from_url_value_data(
|
ComputedUrl::from_url_value_data(
|
||||||
&(**paint.mPaint.mPaintServer.as_ref())._base
|
&(**paint.mPaint.mPaintServer.as_ref())._base
|
||||||
).unwrap()
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -971,7 +971,6 @@ def set_gecko_property(ffi_name, expr):
|
||||||
let gecko_url_value = &*self.gecko.${gecko_ffi_name}.mRawPtr;
|
let gecko_url_value = &*self.gecko.${gecko_ffi_name}.mRawPtr;
|
||||||
UrlOrNone::Url(
|
UrlOrNone::Url(
|
||||||
ComputedUrl::from_url_value_data(&gecko_url_value._base)
|
ComputedUrl::from_url_value_data(&gecko_url_value._base)
|
||||||
.expect("${gecko_ffi_name} could not convert to ComputedUrl")
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4555,7 +4554,7 @@ fn static_assert() {
|
||||||
NS_STYLE_FILTER_URL => {
|
NS_STYLE_FILTER_URL => {
|
||||||
filters.push(unsafe {
|
filters.push(unsafe {
|
||||||
Filter::Url(
|
Filter::Url(
|
||||||
ComputedUrl::from_url_value_data(&(**filter.__bindgen_anon_1.mURL.as_ref())._base).unwrap()
|
ComputedUrl::from_url_value_data(&(**filter.__bindgen_anon_1.mURL.as_ref())._base)
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,18 +40,14 @@ pub struct CssUrl {
|
||||||
|
|
||||||
impl CssUrl {
|
impl CssUrl {
|
||||||
/// Try to parse a URL from a string value that is a valid CSS token for a
|
/// Try to parse a URL from a string value that is a valid CSS token for a
|
||||||
/// URL. Never fails - the API is only fallible to be compatible with the
|
/// URL.
|
||||||
/// gecko version.
|
pub fn parse_from_string(url: String, context: &ParserContext) -> Self {
|
||||||
pub fn parse_from_string<'a>(
|
|
||||||
url: String,
|
|
||||||
context: &ParserContext,
|
|
||||||
) -> Result<Self, ParseError<'a>> {
|
|
||||||
let serialization = Arc::new(url);
|
let serialization = Arc::new(url);
|
||||||
let resolved = context.url_data.join(&serialization).ok();
|
let resolved = context.url_data.join(&serialization).ok();
|
||||||
Ok(CssUrl {
|
CssUrl {
|
||||||
original: Some(serialization),
|
original: Some(serialization),
|
||||||
resolved: resolved,
|
resolved: resolved,
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the URL is definitely invalid. For Servo URLs, we can
|
/// Returns true if the URL is definitely invalid. For Servo URLs, we can
|
||||||
|
@ -110,7 +106,7 @@ impl Parse for CssUrl {
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
let url = input.expect_url()?;
|
let url = input.expect_url()?;
|
||||||
Self::parse_from_string(url.as_ref().to_owned(), context)
|
Ok(Self::parse_from_string(url.as_ref().to_owned(), context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a,
|
||||||
}
|
}
|
||||||
|
|
||||||
let url_string = input.expect_url_or_string()?.as_ref().to_owned();
|
let url_string = input.expect_url_or_string()?.as_ref().to_owned();
|
||||||
let url = CssUrl::parse_from_string(url_string, &self.context)?;
|
let url = CssUrl::parse_from_string(url_string, &self.context);
|
||||||
|
|
||||||
let media = parse_media_query_list(&self.context, input,
|
let media = parse_media_query_list(&self.context, input,
|
||||||
self.error_context.error_reporter);
|
self.error_context.error_reporter);
|
||||||
|
|
|
@ -990,7 +990,7 @@ impl Parse for MozImageRect {
|
||||||
input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
|
input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
|
||||||
input.parse_nested_block(|i| {
|
input.parse_nested_block(|i| {
|
||||||
let string = i.expect_url_or_string()?;
|
let string = i.expect_url_or_string()?;
|
||||||
let url = SpecifiedImageUrl::parse_from_string(string.as_ref().to_owned(), context)?;
|
let url = SpecifiedImageUrl::parse_from_string(string.as_ref().to_owned(), context);
|
||||||
i.expect_comma()?;
|
i.expect_comma()?;
|
||||||
let top = NumberOrPercentage::parse_non_negative(context, i)?;
|
let top = NumberOrPercentage::parse_non_negative(context, i)?;
|
||||||
i.expect_comma()?;
|
i.expect_comma()?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue