diff options
author | Anthony Ramine <nox@nox.paris> | 2020-03-29 19:46:10 +0200 |
---|---|---|
committer | Anthony Ramine <nox@nox.paris> | 2020-03-30 13:07:27 +0200 |
commit | 05c71dff8884d31316d2b08ee453b00a9ef8a902 (patch) | |
tree | a44e7fe0e87284ebdf32dbca6967a63f6600ca72 /components/script/dom | |
parent | 4a17950331eb5096b53aa11cd007f2079e0fa635 (diff) | |
download | servo-05c71dff8884d31316d2b08ee453b00a9ef8a902.tar.gz servo-05c71dff8884d31316d2b08ee453b00a9ef8a902.zip |
Fix AttrHelpersForLayout
We should never be returning 'static stuff from attrs, that's a big lie.
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/attr.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 7dcc76e6caf..1113706de92 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -233,28 +233,27 @@ impl Attr { } #[allow(unsafe_code)] -pub trait AttrHelpersForLayout { - unsafe fn value_forever(&self) -> &'static AttrValue; - unsafe fn value_ref_forever(&self) -> &'static str; - unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>; - unsafe fn local_name_atom_forever(&self) -> LocalName; +pub trait AttrHelpersForLayout<'dom> { + unsafe fn value_forever(self) -> &'dom AttrValue; + unsafe fn value_ref_forever(self) -> &'dom str; + unsafe fn value_tokens_forever(self) -> Option<&'dom [Atom]>; + unsafe fn local_name_atom_forever(self) -> LocalName; } #[allow(unsafe_code)] -impl AttrHelpersForLayout for LayoutDom<'_, Attr> { +impl<'dom> AttrHelpersForLayout<'dom> for LayoutDom<'dom, Attr> { #[inline] - unsafe fn value_forever(&self) -> &'static AttrValue { - // This transmute is used to cheat the lifetime restriction. - mem::transmute::<&AttrValue, &AttrValue>((*self.unsafe_get()).value.borrow_for_layout()) + unsafe fn value_forever(self) -> &'dom AttrValue { + (*self.unsafe_get()).value.borrow_for_layout() } #[inline] - unsafe fn value_ref_forever(&self) -> &'static str { + unsafe fn value_ref_forever(self) -> &'dom str { &**self.value_forever() } #[inline] - unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]> { + unsafe fn value_tokens_forever(self) -> Option<&'dom [Atom]> { // This transmute is used to cheat the lifetime restriction. match *self.value_forever() { AttrValue::TokenList(_, ref tokens) => Some(tokens), @@ -263,7 +262,7 @@ impl AttrHelpersForLayout for LayoutDom<'_, Attr> { } #[inline] - unsafe fn local_name_atom_forever(&self) -> LocalName { + unsafe fn local_name_atom_forever(self) -> LocalName { (*self.unsafe_get()).identifier.local_name.clone() } } |