diff --git a/servo/components/style/rule_tree/mod.rs b/servo/components/style/rule_tree/mod.rs index 2e87a30c2120..1e9602428c03 100644 --- a/servo/components/style/rule_tree/mod.rs +++ b/servo/components/style/rule_tree/mod.rs @@ -440,8 +440,7 @@ impl StrongRuleNode { // script. debug_assert!(!thread_state::get().is_worker() && (thread_state::get().is_layout() || - (thread_state::get().is_script() && - me.refcount.load(Ordering::SeqCst) == 0))); + thread_state::get().is_script())); let current = me.next_free.load(Ordering::SeqCst); if current == FREE_LIST_SENTINEL { diff --git a/servo/components/style/stylist.rs b/servo/components/style/stylist.rs index de106e7a3de5..83bce4bec58e 100644 --- a/servo/components/style/stylist.rs +++ b/servo/components/style/stylist.rs @@ -624,6 +624,18 @@ impl Stylist { } } +impl Drop for Stylist { + fn drop(&mut self) { + // This is the last chance to GC the rule tree. If we have dropped all + // strong rule node references before the Stylist is dropped, then this + // will cause the rule tree to be destroyed correctly. If we haven't + // dropped all strong rule node references before now, then we will + // leak them, since there will be no way to call gc() on the rule tree + // after this point. + unsafe { self.rule_tree.gc(); } + } +} + /// Map that contains the CSS rules for a specific PseudoElement /// (or lack of PseudoElement). diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 37a69ed07c82..c0b4d59d373e 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -46,6 +46,7 @@ use style::selector_parser::PseudoElementCascadeType; use style::sequential; use style::string_cache::Atom; use style::stylesheets::{Origin, Stylesheet}; +use style::thread_state; use style::timer::Timer; use style_traits::ToCss; @@ -66,6 +67,9 @@ pub extern "C" fn Servo_Initialize() -> () { // Allocate our default computed values. unsafe { ComputedValues::initialize(); } + + // Pretend that we're a Servo Layout thread, to make some assertions happy. + thread_state::initialize(thread_state::LAYOUT); } #[no_mangle]