diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 6d823da56f84..161f0e0a9d8c 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -264,7 +264,7 @@ pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: * let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); data.flush_stylesheets(); - let atom = unsafe { Atom::from_static(pseudo_tag) }; + let atom = Atom::from(pseudo_tag); let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ true); type Helpers = ArcHelpers; @@ -293,7 +293,7 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser } }; - let atom = unsafe { Atom::from_static(pseudo_tag) }; + let atom = Atom::from(pseudo_tag); let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ false); // The stylist consumes stylesheets lazily. diff --git a/ports/geckolib/string_cache/lib.rs b/ports/geckolib/string_cache/lib.rs index 63b7ae72854c..1301fe091c54 100644 --- a/ports/geckolib/string_cache/lib.rs +++ b/ports/geckolib/string_cache/lib.rs @@ -128,6 +128,20 @@ impl WeakAtom { String::from_utf16(self.as_slice()).unwrap() } + #[inline] + pub fn is_static(&self) -> bool { + unsafe { + (*self.as_ptr()).mIsStatic() != 0 + } + } + + #[inline] + pub fn len(&self) -> u32 { + unsafe { + (*self.as_ptr()).mLength() + } + } + #[inline] pub fn as_ptr(&self) -> *mut nsIAtom { let const_ptr: *const nsIAtom = &self.0; @@ -158,7 +172,7 @@ impl Atom { } #[inline] - pub unsafe fn from_static(ptr: *mut nsIAtom) -> Self { + unsafe fn from_static(ptr: *mut nsIAtom) -> Self { Atom(ptr as *mut WeakAtom) } } @@ -199,8 +213,10 @@ impl Clone for Atom { impl Drop for Atom { #[inline] fn drop(&mut self) { - unsafe { - Gecko_ReleaseAtom(self.as_ptr()); + if !self.is_static() { + unsafe { + Gecko_ReleaseAtom(self.as_ptr()); + } } } } @@ -281,8 +297,11 @@ impl From for Atom { impl From<*mut nsIAtom> for Atom { #[inline] fn from(ptr: *mut nsIAtom) -> Atom { + debug_assert!(!ptr.is_null()); unsafe { - Gecko_AddRefAtom(ptr); + if (*ptr).mIsStatic() == 0 { + Gecko_AddRefAtom(ptr); + } Atom(WeakAtom::new(ptr)) } }