Move DOMRefCell to style.

This commit is contained in:
Simon Sapin 2016-08-30 17:23:21 +02:00
parent ec723057b2
commit c87180a2fb
5 changed files with 16 additions and 17 deletions

View file

@ -128,8 +128,9 @@
//! return `Err()` from the method with the appropriate [error value] //! return `Err()` from the method with the appropriate [error value]
//! (error/enum.Error.html). //! (error/enum.Error.html).
pub use style::domrefcell as cell;
pub mod callback; pub mod callback;
pub mod cell;
pub mod conversions; pub mod conversions;
pub mod error; pub mod error;
pub mod global; pub mod global;

View file

@ -88,6 +88,7 @@ use std::sync::mpsc::{Receiver, Sender};
use std::time::SystemTime; use std::time::SystemTime;
use string_cache::{Atom, Namespace, QualName}; use string_cache::{Atom, Namespace, QualName};
use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto}; use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
use style::domrefcell::DOMRefCell;
use style::element_state::*; use style::element_state::*;
use style::properties::PropertyDeclarationBlock; use style::properties::PropertyDeclarationBlock;
use style::selector_impl::{PseudoElement, ElementSnapshot}; use style::selector_impl::{PseudoElement, ElementSnapshot};
@ -172,6 +173,13 @@ impl<T: JSTraceable> JSTraceable for UnsafeCell<T> {
} }
} }
impl<T: JSTraceable> JSTraceable for DOMRefCell<T> {
fn trace(&self, trc: *mut JSTracer) {
unsafe {
(*self).borrow_for_gc_trace().trace(trc)
}
}
}
impl JSTraceable for Heap<*mut JSObject> { impl JSTraceable for Heap<*mut JSObject> {
fn trace(&self, trc: *mut JSTracer) { fn trace(&self, trc: *mut JSTracer) {

View file

@ -17,7 +17,6 @@
#![feature(slice_patterns)] #![feature(slice_patterns)]
#![feature(stmt_expr_attributes)] #![feature(stmt_expr_attributes)]
#![feature(question_mark)] #![feature(question_mark)]
#![feature(try_borrow)]
#![feature(try_from)] #![feature(try_from)]
#![deny(unsafe_code)] #![deny(unsafe_code)]

View file

@ -4,17 +4,15 @@
//! A shareable mutable container for the DOM. //! A shareable mutable container for the DOM.
use dom::bindings::trace::JSTraceable; use refcell::{BorrowError, BorrowMutError, Ref, RefCell, RefMut};
use js::jsapi::JSTracer; use thread_state;
use style::refcell::{BorrowError, BorrowMutError, Ref, RefCell, RefMut};
use style::thread_state;
use style::thread_state::SCRIPT;
/// A mutable field in the DOM. /// A mutable field in the DOM.
/// ///
/// This extends the API of `core::cell::RefCell` to allow unsafe access in /// This extends the API of `core::cell::RefCell` to allow unsafe access in
/// certain situations, with dynamic checking in debug builds. /// certain situations, with dynamic checking in debug builds.
#[derive(Clone, HeapSizeOf)] #[derive(Clone)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct DOMRefCell<T> { pub struct DOMRefCell<T> {
value: RefCell<T>, value: RefCell<T>,
} }
@ -48,7 +46,7 @@ impl<T> DOMRefCell<T> {
/// ///
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub unsafe fn borrow_for_script_deallocation(&self) -> &mut T { 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() &mut *self.value.as_ptr()
} }
@ -60,14 +58,6 @@ impl<T> DOMRefCell<T> {
} }
} }
impl<T: JSTraceable> JSTraceable for DOMRefCell<T> {
fn trace(&self, trc: *mut JSTracer) {
unsafe {
(*self).borrow_for_gc_trace().trace(trc)
}
}
}
// Functionality duplicated with `core::cell::RefCell` // Functionality duplicated with `core::cell::RefCell`
// =================================================== // ===================================================
impl<T> DOMRefCell<T> { impl<T> DOMRefCell<T> {

View file

@ -81,6 +81,7 @@ pub mod context;
pub mod custom_properties; pub mod custom_properties;
pub mod data; pub mod data;
pub mod dom; pub mod dom;
pub mod domrefcell;
pub mod element_state; pub mod element_state;
pub mod error_reporting; pub mod error_reporting;
pub mod font_face; pub mod font_face;