From c87180a2fbddb20f072f74586b990f256f3e6f8b Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 30 Aug 2016 17:23:21 +0200 Subject: [PATCH] Move DOMRefCell to style. --- components/script/dom/bindings/mod.rs | 3 ++- components/script/dom/bindings/trace.rs | 8 ++++++++ components/script/lib.rs | 1 - .../bindings/cell.rs => style/domrefcell.rs} | 20 +++++-------------- components/style/lib.rs | 1 + 5 files changed, 16 insertions(+), 17 deletions(-) rename components/{script/dom/bindings/cell.rs => style/domrefcell.rs} (89%) diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs index 439016ee15b..02d5c9c8bef 100644 --- a/components/script/dom/bindings/mod.rs +++ b/components/script/dom/bindings/mod.rs @@ -128,8 +128,9 @@ //! return `Err()` from the method with the appropriate [error value] //! (error/enum.Error.html). +pub use style::domrefcell as cell; + pub mod callback; -pub mod cell; pub mod conversions; pub mod error; pub mod global; diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index d6969f38d6c..507e19e4bcb 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -88,6 +88,7 @@ use std::sync::mpsc::{Receiver, Sender}; use std::time::SystemTime; use string_cache::{Atom, Namespace, QualName}; use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto}; +use style::domrefcell::DOMRefCell; use style::element_state::*; use style::properties::PropertyDeclarationBlock; use style::selector_impl::{PseudoElement, ElementSnapshot}; @@ -172,6 +173,13 @@ impl JSTraceable for UnsafeCell { } } +impl JSTraceable for DOMRefCell { + fn trace(&self, trc: *mut JSTracer) { + unsafe { + (*self).borrow_for_gc_trace().trace(trc) + } + } +} impl JSTraceable for Heap<*mut JSObject> { fn trace(&self, trc: *mut JSTracer) { diff --git a/components/script/lib.rs b/components/script/lib.rs index 2cef235aae7..910706f4a1a 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -17,7 +17,6 @@ #![feature(slice_patterns)] #![feature(stmt_expr_attributes)] #![feature(question_mark)] -#![feature(try_borrow)] #![feature(try_from)] #![deny(unsafe_code)] diff --git a/components/script/dom/bindings/cell.rs b/components/style/domrefcell.rs similarity index 89% rename from components/script/dom/bindings/cell.rs rename to components/style/domrefcell.rs index 709e20297cd..a61a2a0d7fe 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/style/domrefcell.rs @@ -4,17 +4,15 @@ //! A shareable mutable container for the DOM. -use dom::bindings::trace::JSTraceable; -use js::jsapi::JSTracer; -use style::refcell::{BorrowError, BorrowMutError, Ref, RefCell, RefMut}; -use style::thread_state; -use style::thread_state::SCRIPT; +use refcell::{BorrowError, BorrowMutError, Ref, RefCell, RefMut}; +use thread_state; /// A mutable field in the DOM. /// /// This extends the API of `core::cell::RefCell` to allow unsafe access in /// certain situations, with dynamic checking in debug builds. -#[derive(Clone, HeapSizeOf)] +#[derive(Clone)] +#[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct DOMRefCell { value: RefCell, } @@ -48,7 +46,7 @@ impl DOMRefCell { /// #[allow(unsafe_code)] pub unsafe fn borrow_for_script_deallocation(&self) -> &mut T { - debug_assert!(thread_state::get().contains(SCRIPT)); + debug_assert!(thread_state::get().contains(thread_state::SCRIPT)); &mut *self.value.as_ptr() } @@ -60,14 +58,6 @@ impl DOMRefCell { } } -impl JSTraceable for DOMRefCell { - fn trace(&self, trc: *mut JSTracer) { - unsafe { - (*self).borrow_for_gc_trace().trace(trc) - } - } -} - // Functionality duplicated with `core::cell::RefCell` // =================================================== impl DOMRefCell { diff --git a/components/style/lib.rs b/components/style/lib.rs index fe1957d7c4e..9c1387b79c5 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -81,6 +81,7 @@ pub mod context; pub mod custom_properties; pub mod data; pub mod dom; +pub mod domrefcell; pub mod element_state; pub mod error_reporting; pub mod font_face;