Skip to content

Commit

Permalink
Move DOMRefCell to style.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Aug 31, 2016
1 parent ec72305 commit c87180a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
3 changes: 2 additions & 1 deletion components/script/dom/bindings/mod.rs
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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> {
fn trace(&self, trc: *mut JSTracer) {
Expand Down
1 change: 0 additions & 1 deletion components/script/lib.rs
Expand Up @@ -17,7 +17,6 @@
#![feature(slice_patterns)]
#![feature(stmt_expr_attributes)]
#![feature(question_mark)]
#![feature(try_borrow)]
#![feature(try_from)]

#![deny(unsafe_code)]
Expand Down
Expand Up @@ -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<T> {
value: RefCell<T>,
}
Expand Down Expand Up @@ -48,7 +46,7 @@ impl<T> DOMRefCell<T> {
///
#[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()
}

Expand All @@ -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`
// ===================================================
impl<T> DOMRefCell<T> {
Expand Down
1 change: 1 addition & 0 deletions components/style/lib.rs
Expand Up @@ -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;
Expand Down

0 comments on commit c87180a

Please sign in to comment.