Skip to content

Commit

Permalink
Auto merge of #14653 - upsuper:bug1321176, r=Manishearth
Browse files Browse the repository at this point in the history
stylo: Fix assertion for unresolvable url

<!-- Please describe your changes on the following line: -->
This is the Servo part of [bug 1321176](https://bugzilla.mozilla.org/show_bug.cgi?id=1321176), which has been reviewed by @emilio, @Manishearth, and @heycam.

r? @Manishearth

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14653)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Dec 20, 2016
2 parents bcf154d + 09ce132 commit ae2b74e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion components/script/dom/element.rs
Expand Up @@ -397,7 +397,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
PropertyDeclaration::BackgroundImage(DeclaredValue::Value(
background_image::SpecifiedValue(vec![
background_image::single_value::SpecifiedValue(Some(
specified::Image::for_cascade(Some(url.into()), specified::url::UrlExtraData { })
specified::Image::for_cascade(url.into(), specified::url::UrlExtraData { })
))
])))));
}
Expand Down
4 changes: 3 additions & 1 deletion components/style/gecko/conversions.rs
Expand Up @@ -133,7 +133,9 @@ impl nsStyleImage {
self.set_gradient(gradient)
},
Image::Url(ref url) if with_url => {
let (ptr, len) = url.as_slice_components();
let (ptr, len) = match url.as_slice_components() {
Ok(value) | Err(value) => value
};
let extra_data = url.extra_data();
unsafe {
Gecko_SetUrlImageValue(self,
Expand Down
13 changes: 10 additions & 3 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -1152,7 +1152,10 @@ fn static_assert() {
Either::Second(_none) => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()),
Either::First(ref url) => {
let extra_data = url.extra_data();
let (ptr, len) = url.as_slice_components();
let (ptr, len) = match url.as_slice_components() {
Ok(value) => value,
Err(_) => (ptr::null(), 0),
};
unsafe {
Gecko_SetMozBinding(&mut self.gecko,
ptr,
Expand Down Expand Up @@ -1737,7 +1740,9 @@ fn static_assert() {
}
}
Either::First(ref url) => {
let (ptr, len) = url.as_slice_components();
let (ptr, len) = match url.as_slice_components() {
Ok(value) | Err(value) => value
};
let extra_data = url.extra_data();
unsafe {
Gecko_SetListStyleImage(&mut self.gecko,
Expand Down Expand Up @@ -2433,7 +2438,9 @@ clip-path
for i in 0..v.images.len() {
let image = &v.images[i];
let extra_data = image.url.extra_data();
let (ptr, len) = image.url.as_slice_components();
let (ptr, len) = match image.url.as_slice_components() {
Ok(value) | Err(value) => value,
};
unsafe {
Gecko_SetCursorImage(&mut self.gecko.mCursorImages[i],
ptr, len as u32,
Expand Down
2 changes: 1 addition & 1 deletion components/style/values/specified/image.rs
Expand Up @@ -45,7 +45,7 @@ impl Image {

/// Creates an already specified image value from an already resolved URL
/// for insertion in the cascade.
pub fn for_cascade(url: Option<ServoUrl>, extra_data: UrlExtraData) -> Self {
pub fn for_cascade(url: ServoUrl, extra_data: UrlExtraData) -> Self {
Image::Url(SpecifiedUrl::for_cascade(url, extra_data))
}
}
Expand Down
16 changes: 10 additions & 6 deletions components/style/values/specified/url.rs
Expand Up @@ -13,7 +13,6 @@ use parser::ParserContextExtraData;
use servo_url::ServoUrl;
use std::borrow::Cow;
use std::fmt::{self, Write};
use std::ptr;
use std::sync::Arc;
use style_traits::ToCss;
use values::NoViewportPercentage;
Expand Down Expand Up @@ -121,19 +120,24 @@ impl SpecifiedUrl {
}

/// Little helper for Gecko's ffi.
pub fn as_slice_components(&self) -> (*const u8, usize) {
#[cfg(feature = "gecko")]
pub fn as_slice_components(&self) -> Result<(*const u8, usize), (*const u8, usize)> {
match self.resolved {
Some(ref url) => (url.as_str().as_ptr(), url.as_str().len()),
None => (ptr::null(), 0),
Some(ref url) => Ok((url.as_str().as_ptr(), url.as_str().len())),
None => {
let url = self.original.as_ref()
.expect("We should always have either the original or the resolved value");
Err((url.as_str().as_ptr(), url.as_str().len()))
}
}
}

/// Creates an already specified url value from an already resolved URL
/// for insertion in the cascade.
pub fn for_cascade(url: Option<ServoUrl>, extra_data: UrlExtraData) -> Self {
pub fn for_cascade(url: ServoUrl, extra_data: UrlExtraData) -> Self {
SpecifiedUrl {
original: None,
resolved: url,
resolved: Some(url),
extra_data: extra_data,
}
}
Expand Down

0 comments on commit ae2b74e

Please sign in to comment.