diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index cd32e6c95de..b5f20784c8e 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -1366,53 +1366,40 @@ impl MicrotaskRunnable for ImageElementMicrotask {
}
pub trait LayoutHTMLImageElementHelpers {
- #[allow(unsafe_code)]
- unsafe fn image(self) -> Option>;
- #[allow(unsafe_code)]
- unsafe fn image_url(self) -> Option;
- #[allow(unsafe_code)]
- unsafe fn image_density(self) -> Option;
- #[allow(unsafe_code)]
- unsafe fn image_data(self) -> (Option>, Option);
+ fn image(self) -> Option>;
+ fn image_url(self) -> Option;
+ fn image_density(self) -> Option;
+ fn image_data(self) -> (Option>, Option);
fn get_width(self) -> LengthOrPercentageOrAuto;
fn get_height(self) -> LengthOrPercentageOrAuto;
}
+impl<'dom> LayoutDom<'dom, HTMLImageElement> {
+ #[allow(unsafe_code)]
+ fn current_request(self) -> &'dom ImageRequest {
+ unsafe { self.unsafe_get().current_request.borrow_for_layout() }
+ }
+}
+
impl LayoutHTMLImageElementHelpers for LayoutDom<'_, HTMLImageElement> {
- #[allow(unsafe_code)]
- unsafe fn image(self) -> Option> {
- (*self.unsafe_get())
- .current_request
- .borrow_for_layout()
- .image
- .clone()
+ fn image(self) -> Option> {
+ self.current_request().image.clone()
}
- #[allow(unsafe_code)]
- unsafe fn image_url(self) -> Option {
- (*self.unsafe_get())
- .current_request
- .borrow_for_layout()
- .parsed_url
- .clone()
+ fn image_url(self) -> Option {
+ self.current_request().parsed_url.clone()
}
- #[allow(unsafe_code)]
- unsafe fn image_data(self) -> (Option>, Option) {
- let current_request = (*self.unsafe_get()).current_request.borrow_for_layout();
+ fn image_data(self) -> (Option>, Option) {
+ let current_request = self.current_request();
(
current_request.image.clone(),
current_request.metadata.clone(),
)
}
- #[allow(unsafe_code)]
- unsafe fn image_density(self) -> Option {
- (*self.unsafe_get())
- .current_request
- .borrow_for_layout()
- .current_pixel_density
- .clone()
+ fn image_density(self) -> Option {
+ self.current_request().current_pixel_density.clone()
}
fn get_width(self) -> LengthOrPercentageOrAuto {
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 7348431d4f3..b7215cfd92b 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -1493,25 +1493,21 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
#[allow(unsafe_code)]
fn image_url(self) -> Option {
- unsafe {
- self.downcast::()
- .expect("not an image!")
- .image_url()
- }
+ self.downcast::()
+ .expect("not an image!")
+ .image_url()
}
#[allow(unsafe_code)]
fn image_data(self) -> Option<(Option>, Option)> {
- unsafe { self.downcast::().map(|e| e.image_data()) }
+ self.downcast::().map(|e| e.image_data())
}
#[allow(unsafe_code)]
fn image_density(self) -> Option {
- unsafe {
- self.downcast::()
- .expect("not an image!")
- .image_density()
- }
+ self.downcast::()
+ .expect("not an image!")
+ .image_density()
}
fn canvas_data(self) -> Option {