Rename MutJS<T> to MutDom<T>

This commit is contained in:
Anthony Ramine 2017-09-26 00:16:22 +02:00
parent 7be32fb237
commit d29335040d
12 changed files with 45 additions and 45 deletions

View file

@ -237,20 +237,20 @@ impl LayoutJS<Node> {
/// on `Dom<T>`. /// on `Dom<T>`.
#[must_root] #[must_root]
#[derive(JSTraceable)] #[derive(JSTraceable)]
pub struct MutJS<T: DomObject> { pub struct MutDom<T: DomObject> {
val: UnsafeCell<Dom<T>>, val: UnsafeCell<Dom<T>>,
} }
impl<T: DomObject> MutJS<T> { impl<T: DomObject> MutDom<T> {
/// Create a new `MutJS`. /// Create a new `MutDom`.
pub fn new(initial: &T) -> MutJS<T> { pub fn new(initial: &T) -> MutDom<T> {
debug_assert!(thread_state::get().is_script()); debug_assert!(thread_state::get().is_script());
MutJS { MutDom {
val: UnsafeCell::new(Dom::from_ref(initial)), val: UnsafeCell::new(Dom::from_ref(initial)),
} }
} }
/// Set this `MutJS` to the given value. /// Set this `MutDom` to the given value.
pub fn set(&self, val: &T) { pub fn set(&self, val: &T) {
debug_assert!(thread_state::get().is_script()); debug_assert!(thread_state::get().is_script());
unsafe { unsafe {
@ -258,7 +258,7 @@ impl<T: DomObject> MutJS<T> {
} }
} }
/// Get the value in this `MutJS`. /// Get the value in this `MutDom`.
pub fn get(&self) -> Root<T> { pub fn get(&self) -> Root<T> {
debug_assert!(thread_state::get().is_script()); debug_assert!(thread_state::get().is_script());
unsafe { unsafe {
@ -267,14 +267,14 @@ impl<T: DomObject> MutJS<T> {
} }
} }
impl<T: DomObject> HeapSizeOf for MutJS<T> { impl<T: DomObject> HeapSizeOf for MutDom<T> {
fn heap_size_of_children(&self) -> usize { fn heap_size_of_children(&self) -> usize {
// See comment on HeapSizeOf for Dom<T>. // See comment on HeapSizeOf for Dom<T>.
0 0
} }
} }
impl<T: DomObject> PartialEq for MutJS<T> { impl<T: DomObject> PartialEq for MutDom<T> {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
unsafe { unsafe {
*self.val.get() == *other.val.get() *self.val.get() == *other.val.get()
@ -282,7 +282,7 @@ impl<T: DomObject> PartialEq for MutJS<T> {
} }
} }
impl<T: DomObject + PartialEq> PartialEq<T> for MutJS<T> { impl<T: DomObject + PartialEq> PartialEq<T> for MutDom<T> {
fn eq(&self, other: &T) -> bool { fn eq(&self, other: &T) -> bool {
unsafe { unsafe {
**self.val.get() == *other **self.val.get() == *other

View file

@ -33,7 +33,7 @@
//! the [`Root`](bindings/root/struct.Root.html) smart pointer; //! the [`Root`](bindings/root/struct.Root.html) smart pointer;
//! * tracing pointers in member fields: the [`Dom`](bindings/root/struct.Dom.html), //! * tracing pointers in member fields: the [`Dom`](bindings/root/struct.Dom.html),
//! [`MutNullableJS`](bindings/root/struct.MutNullableJS.html) and //! [`MutNullableJS`](bindings/root/struct.MutNullableJS.html) and
//! [`MutJS`](bindings/root/struct.MutJS.html) smart pointers and //! [`MutDom`](bindings/root/struct.MutDom.html) smart pointers and
//! [the tracing implementation](bindings/trace/index.html); //! [the tracing implementation](bindings/trace/index.html);
//! * rooting pointers from across thread boundaries or in channels: the //! * rooting pointers from across thread boundaries or in channels: the
//! [`Trusted`](bindings/refcounted/struct.Trusted.html) smart pointer; //! [`Trusted`](bindings/refcounted/struct.Trusted.html) smart pointer;

View file

@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::NodeIteratorBinding;
use dom::bindings::codegen::Bindings::NodeIteratorBinding::NodeIteratorMethods; use dom::bindings::codegen::Bindings::NodeIteratorBinding::NodeIteratorMethods;
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, MutJS, Root}; use dom::bindings::root::{Dom, MutDom, Root};
use dom::document::Document; use dom::document::Document;
use dom::node::Node; use dom::node::Node;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -22,7 +22,7 @@ pub struct NodeIterator {
reflector_: Reflector, reflector_: Reflector,
root_node: Dom<Node>, root_node: Dom<Node>,
#[ignore_heap_size_of = "Defined in rust-mozjs"] #[ignore_heap_size_of = "Defined in rust-mozjs"]
reference_node: MutJS<Node>, reference_node: MutDom<Node>,
pointer_before_reference_node: Cell<bool>, pointer_before_reference_node: Cell<bool>,
what_to_show: u32, what_to_show: u32,
#[ignore_heap_size_of = "Can't measure due to #6870"] #[ignore_heap_size_of = "Can't measure due to #6870"]
@ -36,7 +36,7 @@ impl NodeIterator {
NodeIterator { NodeIterator {
reflector_: Reflector::new(), reflector_: Reflector::new(),
root_node: Dom::from_ref(root_node), root_node: Dom::from_ref(root_node),
reference_node: MutJS::new(root_node), reference_node: MutDom::new(root_node),
pointer_before_reference_node: Cell::new(true), pointer_before_reference_node: Cell::new(true),
what_to_show: what_to_show, what_to_show: what_to_show,
filter: filter filter: filter

View file

@ -14,7 +14,7 @@ use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::inheritance::{CharacterDataTypeId, NodeTypeId}; use dom::bindings::inheritance::{CharacterDataTypeId, NodeTypeId};
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, MutJS, Root, RootedReference}; use dom::bindings::root::{Dom, MutDom, Root, RootedReference};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
use dom::bindings::trace::JSTraceable; use dom::bindings::trace::JSTraceable;
use dom::bindings::weakref::{WeakRef, WeakRefVec}; use dom::bindings::weakref::{WeakRef, WeakRefVec};
@ -933,7 +933,7 @@ impl RangeMethods for Range {
#[derive(DenyPublicFields, HeapSizeOf, JSTraceable)] #[derive(DenyPublicFields, HeapSizeOf, JSTraceable)]
#[must_root] #[must_root]
pub struct BoundaryPoint { pub struct BoundaryPoint {
node: MutJS<Node>, node: MutDom<Node>,
offset: Cell<u32>, offset: Cell<u32>,
} }
@ -942,7 +942,7 @@ impl BoundaryPoint {
debug_assert!(!node.is_doctype()); debug_assert!(!node.is_doctype());
debug_assert!(offset <= node.len()); debug_assert!(offset <= node.len());
BoundaryPoint { BoundaryPoint {
node: MutJS::new(node), node: MutDom::new(node),
offset: Cell::new(offset), offset: Cell::new(offset),
} }
} }

View file

@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::TouchBinding;
use dom::bindings::codegen::Bindings::TouchBinding::TouchMethods; use dom::bindings::codegen::Bindings::TouchBinding::TouchMethods;
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::{MutJS, Root}; use dom::bindings::root::{MutDom, Root};
use dom::eventtarget::EventTarget; use dom::eventtarget::EventTarget;
use dom::window::Window; use dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -15,7 +15,7 @@ use dom_struct::dom_struct;
pub struct Touch { pub struct Touch {
reflector_: Reflector, reflector_: Reflector,
identifier: i32, identifier: i32,
target: MutJS<EventTarget>, target: MutDom<EventTarget>,
screen_x: f64, screen_x: f64,
screen_y: f64, screen_y: f64,
client_x: f64, client_x: f64,
@ -32,7 +32,7 @@ impl Touch {
Touch { Touch {
reflector_: Reflector::new(), reflector_: Reflector::new(),
identifier: identifier, identifier: identifier,
target: MutJS::new(target), target: MutDom::new(target),
screen_x: *screen_x, screen_x: *screen_x,
screen_y: *screen_y, screen_y: *screen_y,
client_x: *client_x, client_x: *client_x,

View file

@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::TouchEventBinding::TouchEventMethods;
use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::reflect_dom_object; use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::root::{MutJS, Root}; use dom::bindings::root::{MutDom, Root};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
use dom::event::{EventBubbles, EventCancelable}; use dom::event::{EventBubbles, EventCancelable};
use dom::touchlist::TouchList; use dom::touchlist::TouchList;
@ -19,9 +19,9 @@ use std::cell::Cell;
#[dom_struct] #[dom_struct]
pub struct TouchEvent { pub struct TouchEvent {
uievent: UIEvent, uievent: UIEvent,
touches: MutJS<TouchList>, touches: MutDom<TouchList>,
target_touches: MutJS<TouchList>, target_touches: MutDom<TouchList>,
changed_touches: MutJS<TouchList>, changed_touches: MutDom<TouchList>,
alt_key: Cell<bool>, alt_key: Cell<bool>,
meta_key: Cell<bool>, meta_key: Cell<bool>,
ctrl_key: Cell<bool>, ctrl_key: Cell<bool>,
@ -34,9 +34,9 @@ impl TouchEvent {
target_touches: &TouchList) -> TouchEvent { target_touches: &TouchList) -> TouchEvent {
TouchEvent { TouchEvent {
uievent: UIEvent::new_inherited(), uievent: UIEvent::new_inherited(),
touches: MutJS::new(touches), touches: MutDom::new(touches),
target_touches: MutJS::new(target_touches), target_touches: MutDom::new(target_touches),
changed_touches: MutJS::new(changed_touches), changed_touches: MutDom::new(changed_touches),
ctrl_key: Cell::new(false), ctrl_key: Cell::new(false),
shift_key: Cell::new(false), shift_key: Cell::new(false),
alt_key: Cell::new(false), alt_key: Cell::new(false),

View file

@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::TreeWalkerBinding;
use dom::bindings::codegen::Bindings::TreeWalkerBinding::TreeWalkerMethods; use dom::bindings::codegen::Bindings::TreeWalkerBinding::TreeWalkerMethods;
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, MutJS, Root}; use dom::bindings::root::{Dom, MutDom, Root};
use dom::document::Document; use dom::document::Document;
use dom::node::Node; use dom::node::Node;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -21,7 +21,7 @@ use std::rc::Rc;
pub struct TreeWalker { pub struct TreeWalker {
reflector_: Reflector, reflector_: Reflector,
root_node: Dom<Node>, root_node: Dom<Node>,
current_node: MutJS<Node>, current_node: MutDom<Node>,
what_to_show: u32, what_to_show: u32,
#[ignore_heap_size_of = "function pointers and Rc<T> are hard"] #[ignore_heap_size_of = "function pointers and Rc<T> are hard"]
filter: Filter filter: Filter
@ -34,7 +34,7 @@ impl TreeWalker {
TreeWalker { TreeWalker {
reflector_: Reflector::new(), reflector_: Reflector::new(),
root_node: Dom::from_ref(root_node), root_node: Dom::from_ref(root_node),
current_node: MutJS::new(root_node), current_node: MutDom::new(root_node),
what_to_show: what_to_show, what_to_show: what_to_show,
filter: filter filter: filter
} }

View file

@ -18,7 +18,7 @@ use dom::bindings::inheritance::Castable;
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
use dom::bindings::refcounted::Trusted; use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::reflector::{DomObject, reflect_dom_object};
use dom::bindings::root::{MutJS, MutNullableJS, Root}; use dom::bindings::root::{MutDom, MutNullableJS, Root};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
use dom::event::Event; use dom::event::Event;
use dom::eventtarget::EventTarget; use dom::eventtarget::EventTarget;
@ -51,9 +51,9 @@ pub struct VRDisplay {
depth_near: Cell<f64>, depth_near: Cell<f64>,
depth_far: Cell<f64>, depth_far: Cell<f64>,
presenting: Cell<bool>, presenting: Cell<bool>,
left_eye_params: MutJS<VREyeParameters>, left_eye_params: MutDom<VREyeParameters>,
right_eye_params: MutJS<VREyeParameters>, right_eye_params: MutDom<VREyeParameters>,
capabilities: MutJS<VRDisplayCapabilities>, capabilities: MutDom<VRDisplayCapabilities>,
stage_params: MutNullableJS<VRStageParameters>, stage_params: MutNullableJS<VRStageParameters>,
#[ignore_heap_size_of = "Defined in rust-webvr"] #[ignore_heap_size_of = "Defined in rust-webvr"]
frame_data: DOMRefCell<WebVRFrameData>, frame_data: DOMRefCell<WebVRFrameData>,
@ -100,9 +100,9 @@ impl VRDisplay {
depth_near: Cell::new(0.01), depth_near: Cell::new(0.01),
depth_far: Cell::new(10000.0), depth_far: Cell::new(10000.0),
presenting: Cell::new(false), presenting: Cell::new(false),
left_eye_params: MutJS::new(&*VREyeParameters::new(display.left_eye_parameters.clone(), &global)), left_eye_params: MutDom::new(&*VREyeParameters::new(display.left_eye_parameters.clone(), &global)),
right_eye_params: MutJS::new(&*VREyeParameters::new(display.right_eye_parameters.clone(), &global)), right_eye_params: MutDom::new(&*VREyeParameters::new(display.right_eye_parameters.clone(), &global)),
capabilities: MutJS::new(&*VRDisplayCapabilities::new(display.capabilities.clone(), &global)), capabilities: MutDom::new(&*VRDisplayCapabilities::new(display.capabilities.clone(), &global)),
stage_params: MutNullableJS::new(stage.as_ref().map(|v| v.deref())), stage_params: MutNullableJS::new(stage.as_ref().map(|v| v.deref())),
frame_data: DOMRefCell::new(Default::default()), frame_data: DOMRefCell::new(Default::default()),
layer: DOMRefCell::new(Default::default()), layer: DOMRefCell::new(Default::default()),

View file

@ -575,10 +575,10 @@ def check_rust(file_name, lines):
(r": &String", "use &str instead of &String", no_filter), (r": &String", "use &str instead of &String", no_filter),
# There should be any use of banned types: # There should be any use of banned types:
# Cell<JSVal>, Cell<Dom<T>>, DOMRefCell<Dom<T>>, DOMRefCell<HEAP<T>> # Cell<JSVal>, Cell<Dom<T>>, DOMRefCell<Dom<T>>, DOMRefCell<HEAP<T>>
(r"(\s|:)+Cell<JSVal>", "Banned type Cell<JSVal> detected. Use MutJS<JSVal> instead", no_filter), (r"(\s|:)+Cell<JSVal>", "Banned type Cell<JSVal> detected. Use MutDom<JSVal> instead", no_filter),
(r"(\s|:)+Cell<Dom<.+>>", "Banned type Cell<Dom<T>> detected. Use MutJS<T> instead", no_filter), (r"(\s|:)+Cell<Dom<.+>>", "Banned type Cell<Dom<T>> detected. Use MutDom<T> instead", no_filter),
(r"DOMRefCell<Dom<.+>>", "Banned type DOMRefCell<Dom<T>> detected. Use MutJS<T> instead", no_filter), (r"DOMRefCell<Dom<.+>>", "Banned type DOMRefCell<Dom<T>> detected. Use MutDom<T> instead", no_filter),
(r"DOMRefCell<Heap<.+>>", "Banned type DOMRefCell<Heap<T>> detected. Use MutJS<T> instead", no_filter), (r"DOMRefCell<Heap<.+>>", "Banned type DOMRefCell<Heap<T>> detected. Use MutDom<T> instead", no_filter),
# No benefit to using &Root<T> # No benefit to using &Root<T>
(r": &Root<", "use &T instead of &Root<T>", no_filter), (r": &Root<", "use &T instead of &Root<T>", no_filter),
(r"^&&", "operators should go at the end of the first line", no_filter), (r"^&&", "operators should go at the end of the first line", no_filter),

View file

@ -13,7 +13,7 @@ use script::test::Node;
struct Foo { struct Foo {
bar: DOMRefCell<Dom<Node>> bar: DOMRefCell<Dom<Node>>
//~^ ERROR Banned type DOMRefCell<Dom<T>> detected. Use MutJS<T> instead //~^ ERROR Banned type DOMRefCell<Dom<T>> detected. Use MutDom<T> instead
} }
fn main() {} fn main() {}

View file

@ -13,7 +13,7 @@ use std::cell::UnsafeCell;
struct Foo { struct Foo {
bar: Cell<JSVal>, bar: Cell<JSVal>,
//~^ ERROR Banned type Cell<JSVal> detected. Use MutJS<JSVal> instead //~^ ERROR Banned type Cell<JSVal> detected. Use MutDom<JSVal> instead
foo: UnsafeCell<JSVal> foo: UnsafeCell<JSVal>
//~^ NOT AN ERROR //~^ NOT AN ERROR
} }

View file

@ -147,11 +147,11 @@ class CheckTidiness(unittest.TestCase):
self.assertNoMoreErrors(feature_errors) self.assertNoMoreErrors(feature_errors)
ban_errors = tidy.collect_errors_for_files(iterFile('ban.rs'), [], [tidy.check_rust], print_text=False) ban_errors = tidy.collect_errors_for_files(iterFile('ban.rs'), [], [tidy.check_rust], print_text=False)
self.assertEqual('Banned type Cell<JSVal> detected. Use MutJS<JSVal> instead', ban_errors.next()[2]) self.assertEqual('Banned type Cell<JSVal> detected. Use MutDom<JSVal> instead', ban_errors.next()[2])
self.assertNoMoreErrors(ban_errors) self.assertNoMoreErrors(ban_errors)
ban_errors = tidy.collect_errors_for_files(iterFile('ban-domrefcell.rs'), [], [tidy.check_rust], print_text=False) ban_errors = tidy.collect_errors_for_files(iterFile('ban-domrefcell.rs'), [], [tidy.check_rust], print_text=False)
self.assertEqual('Banned type DOMRefCell<Dom<T>> detected. Use MutJS<T> instead', ban_errors.next()[2]) self.assertEqual('Banned type DOMRefCell<Dom<T>> detected. Use MutDom<T> instead', ban_errors.next()[2])
self.assertNoMoreErrors(ban_errors) self.assertNoMoreErrors(ban_errors)
def test_spec_link(self): def test_spec_link(self):